Skip to content

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Oct 16, 2025

This replaces O(n^4) brute-force spline fitting with O(n) least-squares algorithm using chord-length parameterization. This eliminates the exhaustive search through control point combinations, reducing iterations from ~6M to a single linear pass for typical glyphs.

  • Use chord-length parameterization for stable parameter assignment
  • Solve 2x2 linear system with Cramer's rule
  • Add fallback to linear interpolation for degenerate cases

Summary by cubic

Replaced O(n^4) brute-force spline fitting with an O(n) least-squares approach using chord-length parameterization, cutting typical glyph fitting from ~6M iterations to a single linear pass. Also hardened memory handling and cleanup to make the font editor more stable.

  • Refactors

    • Use chord-length parameterization for point t-values.
    • Solve control points via normal equations (2x2) with Cramer's rule.
    • Add linear interpolation fallback for singular/degenerate cases.
  • Bug Fixes

    • Add allocation checks and safe cleanup across command/point handling.
    • Make add_pt return bool; propagate failures up the call stack.
    • Replace recursive copy/free with iterative versions to avoid stack issues.
    • Introduce cleanup() and free_char() to release SDL/cairo and undo stack resources.
    • Guard undo push failures with warnings instead of crashing.

jserv added 2 commits October 17, 2025 00:35
This replaces O(n^4) brute-force spline fitting with O(n) least-squares
algorithm using chord-length parameterization. This eliminates the
exhaustive search through control point combinations, reducing
iterations from ~6M to a single linear pass for typical glyphs.
- Use chord-length parameterization for stable parameter assignment
- Solve 2x2 linear system with Cramer's rule
- Add fallback to linear interpolation for degenerate cases
The recent refactoring of sfit.c removed the custom sqrt() in favor of
using the standard library's sqrt() and fabs() functions. This requires
linking against the math library.

Link error:
  undefined reference to symbol 'sqrt@@GLIBC_2.2.5'
  DSO missing from command line: libm.so.6
@jserv jserv merged commit 16f75bd into main Oct 16, 2025
8 checks passed
@jserv jserv deleted the improve-font-editor branch October 16, 2025 16:48
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

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.

2 participants