Skip to content

Honor nonuniform knots when rendering splines - #462

Draft
dxli wants to merge 21 commits into
LibreCAD:masterfrom
dxli:codex/spline-knot-geometry
Draft

dxli wants to merge 21 commits into
LibreCAD:masterfrom
dxli:codex/spline-knot-geometry

Conversation

@dxli

@dxli dxli commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

This draft now depends on #460; its diff includes the parent until that PR merges.

Spline display currently ignores the knot vector: with quadratic controls (0,0), (1,2), (3,2), (4,0) and knots 0,0,0,0.25,1,1,1, the segment seam renders at x=2 instead of x=1.5. Use source knots for valid ordinary splines, including non-clamped and periodic profiles, and render degree-one splines as exact linear segments. Handle the degenerate line/conic intersection equations for those segments. Builder-created splines now initialize their bounds, shared area merging retains Z extents, and removing a weighted control also removes its corresponding weight. Invalid removals throw before changing state; callers still update knots.

For positive-weight rational splines and ordinary splines above degree 3, up to degree 64 with usable source knots, convert to homogeneous Bézier pieces and adaptively subdivide to line segments. The subdivision compares the projected control hull to each chord against 1e-4 of the input control-point extent, with finite-value, depth and 8192-segment limits. Unsupported, invalid or unrepresentable high-degree profiles produce no display segments and report an import warning; lower-degree fallback is unchanged. Shared internal segment joins are included once in line intersections; the existing import warning remains because geometry operations are approximate and not all profiles are supported.

Validation on macOS ARM64, headless:

  • 31 focused Bézier/spline geometry tests pass, including nonuniform knots, weighted quadratic and cubic independent points, quarter-circle accuracy, line/conic intersections, exact joins, invalid-weight fallback, and generated periodic and non-clamped quadratic curves checked against independent ezdxf points. Rebuilding the curve no longer duplicates ordinary segments. The original knot and rational quarter-circle controls fail before their fixes.
  • Builder-created control-point and fit-point splines select in their actual XY area; both shared area-merge overloads preserve 3D extents. Thirty-eight focused geometry tests pass.
  • Weighted control removal, bounds checks, invalid-index refusal, and ASCII/Binary save/reopen pass. A targeted AddressSanitizer harness instrumented the builder removal implementation; the rest of lckernel was not instrumented. Invalid weights preserve an existing destination, and a corrected same-document save succeeds with both codecs.
  • A generated elevated rational HATCH passes ASCII/Binary save/reopen, movement and region line-intersection checks with bundled and current shared libdxfrw. The latter uses separate scratch system-codec build glue. Selected HATCH/MPOLYGON and standalone spline regression controls pass on both codec paths.
  • A generated periodic quadratic HATCH passes source-knot geometry, region intersection and ASCII/Binary save/reopen with both codec paths; ezdxf independently inspects both formats.
  • Generated degree-four ordinary and degree-five weighted 3D curves match independent sampled points, survive ASCII/Binary round trips with both codecs, and report an approximation note. Invalid or over-limit high-degree input has no fabricated display segments.
  • Explicit unit weights on a non-rational quadratic preserve exact geometry and survive ASCII/Binary save/reopen with both codec paths without a spurious approximation note.
  • A generated non-clamped 3D ordinary and weighted spline pair survives ASCII/Binary save/reopen with both codec paths and retains the independently evaluated endpoints.
  • The Python binding plan-sync check passes. The parent spline model change requires dependent consumers to rebuild.

Native GUI behavior, additional high-degree, periodic and non-clamped profiles and broader 3D/intersection semantics remain to be qualified. The approximation is bounded only for the admitted profile, not an exact NURBS representation.

Windows CI follow-up: close the source and destination test streams before rewriting or retrying. Both affected spline tests pass locally and in the Windows BuildWindows job; BuildWindowsPersistence also passed. Wider native platform qualification remains open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant