Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-cad

Source of release 0.9.4

0.9.4 / src / measure / api.lucb

## Luce's measuring calls (luced-3d's Check node).

## Measuring a model, as static functions.
pub struct CadMeasure:
    let reserved: u8 = 0

    ## `model`'s edges `references` names (empty: every edge between two
    ## faces) checked for continuity `level` (0 to 3) at `stations` per edge
    ## (continuity.lucb): a pass within a gap of `distance`, an angle of
    ## `angle` degrees, and curvature and rate differences of `curvature`
    ## and `rate` percent. With `combs`, curvature combs of `samples` on each
    ## curved edge; with `quills`, each side's curvature across the edge at
    ## every station; both drawn at `scale` (1: the largest a tenth of the
    ## model). Without `sharp`, edges whose faces meet at more than 10° all
    ## along them (creases) are left out, combs aside.
    pub static func check(model: interop.Reference[CadModel], references: str = "", level: i64 = 2, stations: i64 = 12, distance: f64 = 0.001, angle: f64 = 0.1,
                          curvature: f64 = 0.5, rate: f64 = 1.0, combs: bool = true, samples: i64 = 48, quills: bool = true, scale: f64 = 1.0, sharp: bool = true,
                          faces: str = "") -> interop.Reference[CadCheck]!:
        if not (distance > 0.0) or not (angle > 0.0) or not (curvature > 0.0) or not (rate > 0.0): error(invalid, "a check's thresholds must be positive")
        if not (scale > 0.0) or not math.is_finite(scale): error(invalid, "a comb's scale must be positive")
        let options = CheckOptions(level = level, stations = stations, limits = Limits(distance = distance, angle = angle, curvature = curvature, rate = rate), combs = combs, samples = samples, quills = quills, scale = scale, sharp = sharp)
        let none_eased: Vector3[1] = [Vector3()]
        let none_reach: f64[1] = [0.0]
        return try check_model(model.value(), references, options, faces, none_eased[..<0], none_reach[..<0])

    ## How evenly the faces `faces` of `model` curve (fairness.lucb; names
    ## apart by `;`, empty every face), sampled `samples` by `samples` a
    ## face: the Class-A numbers behind the zebra.
    pub static func fairness(model: interop.Reference[CadModel], faces: str = "", samples: i64 = 41) -> CadFairness!:
        return try fairness_of(model.value(), faces, samples)

    ## `check` of the faces `faces` against their neighbors at `level`
    ## (Alias's Continuity Check of a new surface), its stations within
    ## `reach[i]` of `eased[i]` drawn but not counted: a fill's conflicting
    ## corners, which no surface meets and which Fill reports itself.
    pub static func check_eased(model: interop.Reference[CadModel], level: i64, faces: str, eased: const Vector3[], reach: const f64[], stations: i64 = 12, distance: f64 = 0.0001,
                                angle: f64 = 0.1, curvature: f64 = 0.5, rate: f64 = 1.0) -> interop.Reference[CadCheck]!:
        if eased.length != reach.length: error(invalid, "a check's eased points and reaches must pair up")
        let options = CheckOptions(level = level, stations = stations, limits = Limits(distance = distance, angle = angle, curvature = curvature, rate = rate), combs = true, samples = 32, quills = true, scale = 1.0, sharp = true)
        return try check_model(model.value(), "", options, faces, eased, reach)

    ## `check` with the curvature combs of `set`'s shown curves added (free
    ## curves and curves on faces alike, Alias's Curve Curvature): `samples`
    ## a span, at `scale` (1: the most curved quill a tenth of the curves).
    pub static func with_curve_combs(check: interop.Reference[CadCheck], set: interop.Reference[GeometrySet], samples: i64 = 48, scale: f64 = 1.0) -> !:
        if not (scale > 0.0) or not math.is_finite(scale): error(invalid, "a comb's scale must be positive")
        try comb_curves(check.value(), set, samples, scale)

    ## A check of `set`'s curves alone: their combs (with_curve_combs).
    pub static func curve_check(set: interop.Reference[GeometrySet], samples: i64 = 48, scale: f64 = 1.0) -> interop.Reference[CadCheck]!:
        let result = try interop.Reference[CadCheck].adopt(new CadCheck() in memory.heap, cad_check_type, memory.heap)
        errdefer result.release()
        try CadMeasure.with_curve_combs(result, set, samples, scale)
        return result

    ## `model`'s tessellation (`segments`) colored by how far it lies from
    ## `reference`'s surfaces (deviation.lucb): green within `acceptable`,
    ## saturated at `ramp`.
    pub static func deviation(model: interop.Reference[CadModel], reference: interop.Reference[CadModel], acceptable: f64 = 0.01, ramp: f64 = 0.1, segments: i64 = 16) -> interop.Reference[CadDeviation]!:
        return try deviation_map(model.value(), reference.value(), acceptable, ramp, segments)

    ## How curve `a` at `ta` meets curve `b` at `tb` (curve_joins.lucb):
    ## `a` reaching the joint from below (`sa` 1) or above (-1), `b` leaving
    ## it upward (`sb` -1: its part above `tb` continues) or downward (1),
    ## as Blend Curve's ends take them.
    pub static func curve_join(a: interop.Reference[CadSpline], ta: f64, sa: i64, b: interop.Reference[CadSpline], tb: f64, sb: i64) -> CadCurveJoin!:
        return try curve_join(spline_in(a.value()), ta, sa, spline_in(b.value()), tb, sb)