2D Geometry Constraint Solver

Rust + WASM — 47+ constraints, 10 entities, 4 solvers, sparse CG, propagation, multi-start, diagnostics, drag mode

Sketch Canvas

Fixed Free (unsolved) Solved Arc Ellipse Hyperbola Parabola

Example Sketches

Solver Configuration

Load a sketch example, then click Solve.

JSON API

Two APIs: solve_sketch(systemJson) (simple) & solve_sketch_v2(requestJson) (full config + DOF + diagnostics)

// Click an example button, then Solve to see JSON I/O here.

Solver Capabilities

Levenberg-Marquardt
Damped least-squares with Armijo backtracking. Dense + sparse variant.
Algorithm
DogLeg (Powell)
Trust-region: interpolates steepest descent and Gauss-Newton steps.
Algorithm
BFGS Quasi-Newton
Inverse Hessian approximation with strong Wolfe line search + zoom.
Algorithm
L-BFGS Solver
Limited-memory BFGS with two-loop recursion. O(mn) memory. Auto-selected for n >= 100 variables.
Algorithm
Sparse CG Solver
CSC Jacobian, SpGEMM for JᵀJ, Conjugate Gradient with Jacobi preconditioner. O(nnz).
Algorithm
Constraint Propagation
20 rules deduce variable values without iteration. Fully-deducible systems solve instantly.
Feature
Multi-Start
Random perturbation restarts. Keeps best solution across all starts.
Feature
Subsystem Decomposition
Union-Find splits independent constraint groups. Solve each separately.
Feature
Parameter Reduction
Eliminates Coincident, Horizontal, Vertical, EqualRadius, Concentric, EqualMinorAxes.
Feature
Fallback Chain
Auto-tries all algorithms if primary fails. Primary → fallback₁ → fallback₂.
Feature
DOF Analysis
Algebraic + QR rank-based. Detects under/over/full constraint, redundant & conflicting constraints.
Diagnostics
Convergence Tracking
Per-iteration max residual and cost history. Per-constraint residual breakdown.
Diagnostics
Geometric Validation
Detects negative radius, zero-length lines, degenerate arcs/ellipses.
Diagnostics
JSON + Binary Serialization
Full round-trip: to_json/from_json, to_bytes/from_bytes, file save/load, DiagnosticsSnapshot.
Feature
Python Bindings
PyO3/maturin wheel: geom_solver package. Full API: entities, constraints, solve, DOF, diagnostics.
Binding
WASM Bindings
wasm-bindgen: solve_sketch() and solve_sketch_v2() JSON APIs. Runs in browser.
Binding
Warm Start / Drag Mode
solve_with_warm_start() reuses previous solution. solve_drag() fixes a variable temporarily.
Feature
Undo / Redo
Full System state snapshots with batch nesting. Auto-checkpoint before mutations. Interactive CAD support.
Feature

Constraint Quick Reference

Point Constraints (10)
{ Distance: { p1, p2, d } }
{ Horizontal: { p1, p2 } }
{ Vertical: { p1, p2 } }
{ Coincident: { p1, p2 } }
{ FixedPoint: { point, x, y } }
{ AngleBetweenPoints: { a, b, c, deg } }
{ Midpoint: { m, p1, p2 } }
{ Symmetry: { p_out, p_in, line } }
{ PointLineDistance: { point, line, d } }
{ PointOnLineAt: { point, line, t } }
Line Constraints (7)
{ PointOnLine: { point, line } }
{ Parallel: { l1, l2 } }
{ Perpendicular: { l1, l2 } }
{ Angle: { l1, l2, deg } }
{ EqualLength: { l1, l2 } }
{ LineLineIntersection: { point, l1, l2 } }
{ EqualLineLength: { l1, l2 } }
Circle Constraints (9)
{ PointOnCircle: { point, circle } }
{ LineCircleTangent: { line, circle } }
{ CircleCircleTangent: { c1, c2 } }
{ CircleCircleTangentInternal: { c1, c2 } }
{ EqualRadius: { c1, c2 } }
{ Concentric: { c1, c2 } }
{ CircleRadius: { circle, r } }
{ C2CDistance: { c1, c2, d } }
{ P2CDistance: { point, circle, d } }
Arc Constraints (11)
{ PointOnArc: { point, arc } }
{ LineArcTangent: { line, arc } }
{ ArcArcTangent: { a1, a2 } }
{ ArcArcTangentInternal: { a1, a2 } }
{ ArcCircleTangent: { arc, circle } }
{ ArcCircleTangentInternal: { arc, circle } }
{ ArcRadius: { arc, r } }
{ ArcSweepAngle: { arc, deg } }
{ ArcLength: { arc, len } }
{ LineArcStartTangent: { line, arc } }
{ LineArcEndTangent: { line, arc } }
Ellipse Constraints (7)
{ PointOnEllipse: { point, ellipse } }
{ EllipseTangentLine: { line, ellipse } }
{ EqualMajorAxes: { e1, e2 } }
{ EqualMinorAxes: { e1, e2 } }
{ EllipseRadmin: { ellipse, r } }
{ EllipseFocusDistance: { ellipse, d } }
{ PointOnArcOfEllipse: { point, arc_of_ellipse } }
Hyperbola Constraints (4)
{ PointOnHyperbola: { point, hyperbola } }
{ HyperbolaTangentLine: { line, hyperbola } }
{ HyperbolaRadmin: { hyperbola, r } }
{ EqualHyperbolaRadmins: { h1, h2 } }
Parabola Constraints (3)
{ PointOnParabola: { point, parabola } }
{ ParabolaTangentLine: { line, parabola } }
{ ParabolaFocalLength: { parabola, f } }
Additional (5)
{ EqualLineLength: { l1, l2 } }
{ ArcLength: { arc, len } }
{ EllipseFocusDistance: { ellipse, d } }
{ PointOnArcOfHyperbola: { point, arc_of_hyperbola } }
{ PointOnArcOfParabola: { point, arc_of_parabola } }