Skip to content

Intersections route to the exact solution, else numeric, and say which ran

a.intersect(&b, tol) (the Intersect<B> trait) works for every supported pair of curves and surfaces, in either order: concrete types, the Curve, Curve2D, ElementaryCurve, Surface and ElementarySurface enums, B-splines, Bézier curves and surfaces, and trimmed curves. It solves the pair in closed form when the pair and its configuration have one, and runs the numeric search otherwise: the Bézier-hull search for curve–curve and curve–surface, marching for surface–surface. Every result is one of three family results (curve–curve, curve–surface, surface–surface, plus the 2D curve–curve one) and says which method ran (IntersectionMethod::Exact or Numeric) and whether every hit was found (Completeness, ADR 0007). An exact result is always complete, since a closed form proves that no other hit exists.

The typed per-pair results stay, under IntersectExact<B>::intersect_exact: a stack-only enum per pair, no parameter it does not need, never a numeric search. A caller who meets only elementary shapes in a hot loop keeps the nanosecond path one method away. The routing itself adds no run-time dispatch for concrete types: a pair of concrete types calls its typed solver directly, and a trimmed curve routes through its basis type, so only an enum operand pays for a match. The routed call is about 45–55 ns over the typed exact call alone in 3D, and about 17 ns in 2D, spent moving and building the larger result (docs/benchmarks.md). A Bézier curve or surface has no closed form with anything and is routed like the B-spline it wraps: straight to the numeric search, which reads the B-spline through as_bspline.

ADR 0001 rejected an automatic numeric fallback because the switch was hidden: run time moved from nanoseconds to milliseconds and the curves from exact to fitted without the caller knowing. The switch is now visible on every result, so the objection no longer holds, and the name every caller reaches for first gives the whole answer. "Not analytic" survives only as an outcome of intersect_exact.

intersect_curve_curve(a, b, tol) and intersect_curve_surface(curve, surface, tol) stay public, generic over ParametricCurve and ParametricSurface, and always numeric. They are the entry point for curve and surface types defined outside the crate, and return the same family results as intersect, so there is one result vocabulary. Marching has no such entry point: it is crate-private, and intersect is the only way to march two surfaces.

A trimmed curve is intersected as its basis, then its range applies. A hit is kept when it lies within tol.confusion in space of the range: a hit beyond an end is measured as the parameter excess times the curve's speed there, and is reported at that end. This holds at every end, the seam of a circle or ellipse included, and agrees with the rule for overlaps clipped to a sliver: a clipped piece no longer than tol.confusion in space is a hit where the curves touch, not an overlap and not nothing. A parametric widening by tol.parametric (1e-9) is not a distance decision: the same parameter excess is a different distance on curves of different speeds. A hit 1e-8 past an end in space would be dropped on a circle of radius 1 (parameter excess 1e-8 > 1e-9) and kept on one of radius 1e3 (excess 1e-11), and a hit 1e-9 past an end in parameter would be kept on radius 1e3 although it lies 1e-6 away in space, ten times the confusion tolerance.

Marching, as the numeric surface–surface solver, no longer seeds from a parameter grid limited to [-10, 10] along unbounded directions, which missed every curve farther out. It seeds from the points where iso-curves of an elementary side meet the other surface, through exact curve–surface intersections only: rulings and circles of a cylinder or cone, circles of a sphere or torus (not against a torus, which has no closed form with a circle in general), lines of a plane across the other surface's bounding box. A line is intersected whole, so an unbounded direction is searched whole. A B-spline side adds its own seeds (patch pairs or the grid), and when both surfaces are bounded the bounded grid seeds are added too, because a pair such as sphere × torus loses curves with iso-curve seeds alone. A trace ends where it closes, or where it leaves its trace box (see the amendment of 2026-11-02); the step count is only a safety limit. The step follows the curvature with no fixed cap, is halved when the intersection at its midpoint strays from the chord by more than twice the chord deviation, and is halved when it crosses more than one knot of a B-spline side, unless the crossed knots span at most tol.confusion in space. Every numeric surface–surface result is Sampled: a loop smaller than the iso-curve spacing can be missed, and a grazing curve may not be traced.

Amendment (2026-10-30): one table decides exact or numeric

The routing is now the closed-form pair table of ADR 0023: every operand is read as a basis, and the table says whether the pair has a closed form and which solver answers it. The router no longer asks first whether an operand has an elementary basis. The typed path for concrete types stays as described above: a concrete elementary curve or surface is its own basis, so its pairs still call their typed solver with no match. Surface pairs are matched on their kinds, one match against a solver or a march. Marching's choice of seeding circles ("not against a torus") now reads the table instead of restating it.

Considered options

  • Keeping intersect exact and adding a routed intersect_any: rejected. The exact-only call returns no intersection ("not analytic") for a valid pair such as a conic against a torus or any B-spline, so every caller that needs the curves or hits must test for it and call a second function. Routing costs about 50 ns, small against solvers that take from nanoseconds to milliseconds, and the result's method keeps the switch visible; a caller who cannot afford it keeps intersect_exact.
  • A routed path only, with no typed path: rejected. Every hot-loop call would pay for the family result, and the compiler would no longer rule out impossible outcomes such as a hyperbola from plane–sphere.
  • Routing every pair through the elementary enums: rejected. It costs a match on both operands and a conversion for pairs whose types are known at compile time; the typed routing saves about 13–16 ns per circle pair.
  • Making the generic numeric functions crate-private: rejected. A caller-defined curve or surface would have no way to be intersected; returning the family result keeps them cheap to keep.
  • Keeping marching public: rejected. It would be a second surface–surface entry point with a different result shape and no exact path.
  • Iso-curve seeds alone on bounded pairs: rejected. They lost curves of sphere × torus; the grid seeds add about 0.5 ms on that pair (1.02 ms against 0.52 ms), and correctness comes first.
  • A step cap tied to the distance from the seed: rejected. The step grew past small B-spline features; the midpoint test and the knot-crossing rule bound the step by the geometry instead.

Amendment: traces end on the box of a bounded side

A trace ends where it leaves the box around the smaller bounded elementary or B-spline side, grown by a tenth of its diagonal, and on the model-size cube only when neither side is bounded (#138). A bounded side holds the whole intersection, so the cube around the origin added nothing there but lost every curve of a pair lying beyond it.

Amendment (2026-11-02): unbounded branches are cut and reported

The model-size cube is gone. When neither side is bounded, a trace ends where it leaves the seeded box: the box of the seeds, grown by the larger surface size (a cylinder's or cone's radius, a sweep profile's diagonal), or for two planes by the larger of the seeds' spread and the size of their seeding windows, so that the box does not hang on how many seeds survive along the line where they meet. A branch that runs out of that box is cut, and the pair's result is Incomplete with IncompleteReason::Unbounded and a region where each branch was cut, instead of Sampled. Outside those regions the march is as sampled as before. A seeded box moves with the seeds, so a pair translated far from the origin traces the same branches. The [-10, 10] window of the seed search is kept only where an unbounded side has no bounding box of its own, for example an extrusion against an extrusion.