dymokomi/luce-cad
Source of release 0.9.3
0.9.3 / src / modeling / cap_rolled.lucb
## A cap loop's G1 variable fillet at a Tangency weight of 1 rolls a ball,
## as Fusion 2705's does (probes 5 and 9 of 2026-10-12): the blend is the
## envelope of the balls along the loop, each of the law's radius, touching
## the cap and the wall (its center r into the material from the cap, at
## the cap's contact distance from the edge). Each section (in the plane
## of the way into the cap and the wall's ruling, as the scaled sections'
## are) is the envelope's curve there (rolled_ball.lucb's envelope_section:
## rays from the corner, the balls about the section searched along the
## whole loop, across its edges), a degree 5 Bezier from the cap's contact
## to the wall's; the rows are fitted along each edge (cap_rows.lucb). A
## closed loop only: open ends' run-outs scale the section.
## The loop's balls sampled (rolled_ball.lucb's SampledBalls), each at the
## edge holding it: its center r into the material from the cap, at the
## cap's contact distance from the edge.
func cap_balls(b: Cap*) -> !:
let law = b.law else return
for k in 0..<ball_samples:
let (e, t) = law.at_length(b.w, law.total * (f64)k / (f64)ball_samples)
let index = b.side_of.items[(usize)e] if e >= 0 else -1
if index < 0: error(invalid, "a rolled fillet's loop could not be followed")
let side = &b.sides.items[(usize)index]
let p = try b.w.at(b.w.edges.items[(usize)e].carrier, t)
let (u, _) = try into_cap(b, side, t)
let (_, c) = try corner_at(b, side, t)
let r = try reach_at(b, side, t)
try b.balls.centers.push(p.add(u.multiply_scalar(c)).add(side.into_wall.multiply_scalar(r)))
try b.balls.radii.push(r)
b.balls.total = law.total
## The rolled section of side `side` at its carrier's parameter `t`: its six
## control points onto `out`.
func cap_rolled_section(b: const Cap*, side: const CapSide*, t: f64, out: Growing[Vector3]*) -> !:
let law = b.law else error(invalid, "a rolled cap blend needs its law")
let edge = b.w.edges.items[side.edge]
let e = try b.w.at(edge.carrier, t)
let (u, _) = try into_cap(b, side, t)
let s = try ruling_at(b, side, t)
let (lambda, c) = try corner_at(b, side, t)
let r = try reach_at(b, side, t)
let on_wall = s.multiply_scalar(try wall_distance(b, lambda, r))
var balls = Balls((void*)&b.balls, sampled_ball, law.total)
let way = try s.normalized()
try envelope_section(&balls, (try law.fraction(b.w, side.edge, t)) * law.total, e, u, way, u.multiply_scalar(-1.0), way.multiply_scalar(-1.0), e.add(u.multiply_scalar(c)), e.add(on_wall), out)