Results describe themselves
An intersection or projection result carries what a caller needs to use it without recomputing: the point on every hit, the closest point on every projection, the method and completeness on every intersection, and the overlaps as parameter ranges. The family results (CurveCurveIntersection, CurveCurveIntersection2D, CurveSurfaceIntersection, SurfaceSurfaceIntersection) are structs with private fields read through accessors returning slices, so their storage can change after profiling (hits inline for exact pairs, overlaps in a plain Vec since coincidence is rare) without breaking a caller. Hits and overlaps are plain Copy structs with public fields.
A hit stores a parameter only when the solver computed it on its way to the point: every parameter on the numeric path, the line's parameter for a line against a quadric, both for two 2D lines, and always the parameter of a trimmed operand, since its range test needs it. The others are None. A caller that needs one recovers it from the operand it already holds, curve.parameter_of(hit.point, tol) or surface.parameters_of(hit.point, tol), available on every curve and surface through the PointExtrema, PointExtrema2D and ParametricSurface traits (an elementary geometry inverts in closed form and ignores tol; a B-spline projects the point within tol, see ADR 0015). Recovering every parameter eagerly cost an atan2 or more per hit that most callers never read: dropping it took routed circle–circle from about 145 to 76 ns per pair, 2D circle–circle from 111 to 35 ns. Hits are sorted by parameter when every hit has one, and otherwise keep the solver's order.
A projection gives the closest point next to its parameters and distance (CurveProjection, CurveProjection2D, SurfaceProjection): every algorithm evaluates it while converging, so it costs 24 bytes and no evaluation. A curve–curve extremum gives its two points the same way (CurveCurveExtremum::first_point and second_point, since #192), and CurveCurveExtrema::closest names the ordering of its minima.
An overlap of two curves, CurveCurveOverlap, is a parameter range on each curve plus same_direction, whether both curves run the same way along it. Each range is increasing in its own curve's parameter, so a coincidence that crosses the seam of either curve is split there into one overlap per piece; with opposite directions, the start of one range meets the end of the other, and same_direction is the only way to tell. A curve lying on a surface gives its parameter ranges on the curve.
Rust results do not hold their operands. Borrowing them would make every result generic over the operand types and tied to their lifetime; cloning them would allocate for B-splines. Results stay plain owned data that a caller can store, collect across mixed pairs and send between threads, and the caller already has the operands. Python results do hold them (first and second on intersections, target and query_point on projections): there an operand reference is one reference count, with no copy and no lifetime, and it lets a display draw a result from the result alone. Python hit parameters mirror Rust: None when not computed.
Amendment: every hit carries all its parameters (#177)
The UX study of 0.43.0 (#173, finding G-04) found that every caller who read hits needed the missing parameters and recovered them with a second call, so the saving went to callers who don't read hits, and every caller who did paid for it in code. The routed result now fills every parameter: where the closed form solves for one operand's parameter only, the router recovers the other with its closed-form parameter_of / parameters_of while building the result, and the fields are plain f64 and (f64, f64) (Python float and tuple[float, float]). The typed conic–conic result fills both too. Hits are always sorted by the first operand's parameter.
The cost is the atan2 (or more) per recovered parameter that this ADR avoided. Measured against the parent commit, the median of criterion runs over batches of 1000 pairs: routed circle–circle 88 → about 205 ns per pair, 2D circle–circle 55 → about 115 ns, line–cylinder 147 → about 230 ns; callgrind 793 → 1635, 366 → 1099 and 1237 → 1755 instructions per pair. The typed intersect_exact is unchanged (except conic–conic, now about 5% heavier). It stays the hot path for a caller who needs only the points. A faster closed-form angle recovery can win the routed cost back without changing this interface.
The first considered option below, rejected for that cost, is now the decision. The None reading of a hit parameter in the Python paragraph above no longer holds.
Considered options
- Recovering every parameter on every hit (non-optional fields): rejected. It is the cost most callers do not need, on the hot path of the cheapest pairs.
- Methods or traits that recover a parameter from an operand passed in (
hit.first_parameter_on(&curve), backed by public parameter-recovery traits): rejected. The operand's ownparameter_of/parameters_ofalready does it in one call; two traits and four methods would be a second way to say the same thing. - A NaN niche instead of
Option: rejected for now. It saves 16 bytes per hit but makes a missing value look like a number; it can be revisited with a profile of result building. - Overlap ranges that cross a seam, with an end beyond the period: rejected. Such a range is not an interval of the curve's parameter, and every caller would have to unwrap it.
- Surface parameters left out of curve–surface hits: rejected. A caller needs the hit's position on both operands; they are stored when the solver has them and recoverable in one call otherwise.
- Operands held by Rust results: rejected, for the lifetimes or allocations above.