Create std::units module (#6528)

Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
Nick Cameron
2025-04-29 08:41:31 +12:00
committed by GitHub
parent d96a4d3337
commit 3a23ec1bee
114 changed files with 4450 additions and 5591 deletions

View File

@ -4,6 +4,7 @@
// Note that everything in the prelude is treated as exported.
export import * from "std::types"
export import "std::units"
export import * from "std::math"
export import * from "std::sketch"
export import * from "std::solid"
@ -382,72 +383,6 @@ export fn revolve(
tagEnd?: tag,
): Solid {}
/// Convert a number to millimeters from its current units.
export fn toMillimeters(@num: number(mm)): number(mm) {
return num
}
/// Convert a number to centimeters from its current units.
export fn toCentimeters(@num: number(cm)): number(cm) {
return num
}
/// Convert a number to meters from its current units.
export fn toMeters(@num: number(m)): number(m) {
return num
}
/// Convert a number to inches from its current units.
export fn toInches(@num: number(in)): number(in) {
return num
}
/// Convert a number to feet from its current units.
export fn toFeet(@num: number(ft)): number(ft) {
return num
}
/// Converts a number to yards from its current units.
export fn toYards(@num: number(yd)): number(yd) {
return num
}
/// Converts a number to radians from its current units.
///
/// ```
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [0, 0])
/// |> angledLine(
/// angle = 50,
/// length = 70 * cos(toRadians(45)),
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)
/// ```
export fn toRadians(@num: number(rad)): number(rad) {
return num
}
/// Converts a number to degrees from its current units.
///
/// ```
/// exampleSketch = startSketchOn(XZ)
/// |> startProfile(at = [0, 0])
/// |> angledLine(
/// angle = 50,
/// length = 70 * cos(toDegrees((PI/4): number(rad))),
/// )
/// |> yLine(endAbsolute = 0)
/// |> close()
///
/// example = extrude(exampleSketch, length = 5)
/// ```
export fn toDegrees(@num: number(deg)): number(deg) {
return num
}
/// Offset a plane by a distance along its normal.
///
/// For example, if you offset the `XZ` plane by 10, the new plane will be parallel to the `XZ`