Add Path Segment
add_path_segmentUse this when you need to append a curved segment to an existing PathBuilder chain on the named chain_anchor variable. The call is injected at the END of the chain, immediately before any .close(). One segment kind, selected by kind:
'spline' —
.spline(points, opts?): interpolates through everypointswaypoint (Vec2[] mm, >= 2 entries; points[0] must match current pen position). Optionaltension, andstartTangent/endTangent2D direction vectors that constrain the first-derivative direction at the endpoints (magnitude normalised internally). Use for organic 2D outlines (eyewear brow, ergonomic handle, sneaker midsole).'nurbs' —
.nurbsSegment(controlPoints, opts?): explicit B-spline net (Vec2[] mm, >= degree+1 entries; controlPoints[0] must match pen; pen ends at controlPoints[N-1]). Optionaldegree(default 3), rationalweights(strictly positive), explicitknots(length = controlPoints.length + degree + 1).'hermite' —
.hermiteG2(a, b): each endpoint{ point: Vec2, tangent: Vec2, curvature?: Vec2 }in mm (a.point must match pen; pen ends at b.point).curvaturedefaults to [0,0] (G1); pass matching curvatures for G2 blends. Tangent magnitude is the first derivative (~ chord length), NOT unit length. Returns the modified code + diagnostics from re-evaluating. Side-effect-free. Each kind fails closed on its own missing required params.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | No | kind:'hermite' — start endpoint; point must match current pen position within 1e-6 mm. | |
| b | No | kind:'hermite' — end endpoint; pen ends at b.point. | |
| code | Yes | The .kcad.ts source code. | |
| kind | Yes | Which path-segment kind to append. | |
| knots | No | kind:'nurbs' — optional explicit knot vector; length must equal controlPoints.length + degree + 1. | |
| degree | No | kind:'nurbs' — B-spline degree (default 3). | |
| points | No | kind:'spline' — waypoints as Vec2 pairs in mm; at least 2 entries; first must match current pen position. | |
| tension | No | kind:'spline' — optional Catmull-Rom-style stiffness; forwarded to the underlying B-spline approximation. | |
| weights | No | kind:'nurbs' — optional rational weights (one per control point; strictly positive). | |
| endTangent | No | kind:'spline' — optional [x, y] direction vector at points[N-1]. Magnitude is normalised internally; direction matters. | |
| binding_name | No | Reserved for future use; the segment injection mutates the chain anchor in place. | |
| chain_anchor | Yes | JS identifier of an existing PathBuilder binding (e.g. `const brow = path().moveTo(0,0)`). | |
| startTangent | No | kind:'spline' — optional [x, y] direction vector at points[0]. Magnitude is normalised internally; direction matters. | |
| controlPoints | No | kind:'nurbs' — control-net vertices as Vec2 pairs in mm; at least degree+1 entries. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | Whether the edit applied and re-evaluated cleanly. | |
| error | No | Failure message (present when ok is false). | |
| new_code | No | Modified .kcad.ts source (present on success). Caller persists it. | |
| diagnostics | No | Diagnostics from re-evaluating the modified source. | |
| binding_name | No | JS const name bound to the new construct (when one was created). |