Skip to main content

Module spline

Module spline 

Source
Expand description

Insert spline anchors by de Casteljau subdivision without changing the curve.

Sketch splines are chained cubic Béziers with 3n + 1 point IDs and anchors at indices 0, 3, 6, … . Splitting P0 P1 P2 P3 at parameter t gives:

A = lerp(P0,P1,t)  B = lerp(P1,P2,t)  C = lerp(P2,P3,t)
D = lerp(A,B,t)    E = lerp(B,C,t)    S = lerp(D,E,t)

The resulting polygon P0, A, D, S, E, C, P3 preserves the 3n + 1 invariant. P0 and P3 keep their IDs; P1 and P2 are reused for A and C so their constraints survive. Their endpoint tangent directions are unchanged. Only D, S, and E receive new IDs.

The new anchor and its handles are collinear (S = lerp(D,E,t)), satisfying the solver’s implicit G1 join constraint before the next solve.

Structs§

InsertedAnchor
The ids insert_anchor minted: the new on-curve anchor and the two off-curve handles flanking it (before precedes it in the polygon, after follows it). The caller decides what to hang on them — the tool draws each anchor’s handle guides.

Functions§

insert_anchor
Insert an anchor into the spline under the plane click (u, v), or None when the click should mean something else. Shape-preserving: the curve through the grown control polygon is the curve that was there before.
is_spline_type
Whether geom_type names a spline. Mirrors the kernel solver’s is_spline_geometry_type: "bezier" is what the tools author, "spline" is the accepted alias. Defined here rather than imported because the sketch module is deliberately kernel-free.