Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-cad

Source of release 0.9.4

0.9.4 / src / modeling / curved_rolled.lucb

## A loop between curved faces (or a flat face and a sphere: a dome's rim)
## filleted G1 at a Tangency weight of 1 along a changing law rolls a ball,
## as Fusion 2705's does (probes 8 and 11 of 2026-10-12): the blend is the
## envelope of the balls round the loop (each the law's radius, touching
## both faces: curved_blend.lucb's section_on finds its center). The balls'
## centers and radii are sampled evenly round the loop once and read
## between by Catmull-Rom cubics; each section (square to the loop at its
## point) is the envelope's curve there (rolled_ball.lucb's
## envelope_section: rays from the edge's point between the contacts), a
## degree 5 Bezier, its second and fifth points on the faces' tangents at
## the contacts; the rows are fitted along each edge (row_fit.lucb).
## (The balls' samples: rolled_ball.lucb's SampledBalls.)

## Whether the loop rolls its ball, and if so its balls sampled.
func curved_rolls(c: Curved*) -> !:
    let law = c.law else return
    if not c.round or c.continuity != 1 or not c.blend_shape.plain(): return
    var changes = false
    for r in law.radii.view():
        if r != law.radii.items[0]: changes = true
    if not changes: return
    c.rolled = true
    for k in 0..<ball_samples:
        let s = law.total * (f64)k / (f64)ball_samples
        let (e, t) = law.at_length(c.w, s)
        let side = c.side_of.items[(usize)e]
        if e < 0 or side < 0: error(invalid, "a rolled fillet's loop could not be followed")
        let section = try section_on(c, &c.sides.items[(usize)side], t)
        try c.balls.centers.push(section.center)
        try c.balls.radii.push(try law.at_edge(c.w, (usize)e, t))
    c.balls.total = law.total

## The rolled section across side `side` at its carrier's parameter `t`:
## its six control points onto `out`.
func curved_rolled_section(c: Curved*, side: const CurvedSide*, t: f64, out: Growing[Vector3]*) -> !:
    let law = c.law else error(invalid, "a rolled curved blend needs its law")
    let section = try section_on(c, side, t)
    let (e, _, _) = try c.w.derivatives(c.w.edges.items[side.edge].carrier, t)
    let ua = try section.on_a.subtract(e).normalized()
    let ub = try section.on_b.subtract(e).normalized()
    let toward_a = try section.corner.subtract(section.on_a).normalized()
    let toward_b = try section.corner.subtract(section.on_b).normalized()
    var balls = Balls((void*)&c.balls, sampled_ball, law.total)
    try envelope_section(&balls, (try law.fraction(c.w, side.edge, t)) * law.total, e, ua, ub, toward_a, toward_b, section.on_a, section.on_b, out)