* Document the units of PI Signed-off-by: Nick Cameron <nrc@ncameron.org> * Add links between lang and std references Signed-off-by: Nick Cameron <nrc@ncameron.org> * Change signature of conversion functions Signed-off-by: Nick Cameron <nrc@ncameron.org> * Split foreign imports out of modules docs Signed-off-by: Nick Cameron <nrc@ncameron.org> * More docs for Plane Signed-off-by: Nick Cameron <nrc@ncameron.org> * Update docs/kcl-std/consts/std-math-PI.md Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> * Update rust/kcl-lib/std/math.kcl Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> --------- Signed-off-by: Nick Cameron <nrc@ncameron.org> Co-authored-by: Jess Frazelle <jessfraz@users.noreply.github.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
78 lines
2.2 KiB
Plaintext
78 lines
2.2 KiB
Plaintext
/// Functions for converting numbers to different units.
|
|
///
|
|
/// All numbers in KCL include units, e.g., the number `42` is always '42 mm' or '42 degrees', etc.
|
|
/// it is never just '42'. For more information, see [numeric types](/docs/kcl-lang/numeric).
|
|
///
|
|
/// Note that you only need to explicitly convert the units of a number if you need a specific unit
|
|
/// for your own calculations. When calling a function, KCL will convert a number to the required
|
|
/// units automatically (where possible, and give an error or warning if it's not possible).
|
|
|
|
@no_std
|
|
@settings(defaultLengthUnit = mm, kclVersion = 1.0)
|
|
|
|
/// Convert a number to millimeters from its current units.
|
|
export fn toMillimeters(@num: number(Length)): number(mm) {
|
|
return num
|
|
}
|
|
|
|
/// Convert a number to centimeters from its current units.
|
|
export fn toCentimeters(@num: number(Length)): number(cm) {
|
|
return num
|
|
}
|
|
|
|
/// Convert a number to meters from its current units.
|
|
export fn toMeters(@num: number(Length)): number(m) {
|
|
return num
|
|
}
|
|
|
|
/// Convert a number to inches from its current units.
|
|
export fn toInches(@num: number(Length)): number(in) {
|
|
return num
|
|
}
|
|
|
|
/// Convert a number to feet from its current units.
|
|
export fn toFeet(@num: number(Length)): number(ft) {
|
|
return num
|
|
}
|
|
|
|
/// Converts a number to yards from its current units.
|
|
export fn toYards(@num: number(Length)): 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(units::toRadians(45)),
|
|
/// )
|
|
/// |> yLine(endAbsolute = 0)
|
|
/// |> close()
|
|
///
|
|
/// example = extrude(exampleSketch, length = 5)
|
|
/// ```
|
|
export fn toRadians(@num: number(Angle)): 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(units::toDegrees((PI/4): number(rad))),
|
|
/// )
|
|
/// |> yLine(endAbsolute = 0)
|
|
/// |> close()
|
|
///
|
|
/// example = extrude(exampleSketch, length = 5)
|
|
/// ```
|
|
export fn toDegrees(@num: number(Angle)): number(deg) {
|
|
return num
|
|
}
|