Shared behaviour lives on the traits
A method that more than one shape answers is a trait method, and the trait is its only home. Evaluation, bounds, closedness and continuity are methods of ParametricCurve, ParametricCurve2D and ParametricSurface; projection, containment and inversion (project_point, project_points, contains, parameter_of) are methods of PointExtrema and PointExtrema2D, and of ParametricSurface for surfaces (parameters_of). A type's inherent impl keeps only what is specific to it: Circle::radius, BSplineCurve::insert_knot, Plane::axis. An inherent method never takes the name of a trait method, even with another signature: it would hide the trait method from method-call syntax on that type (Plane::normal() did until #190). The doc comment and the example of a shared method are written once, on the trait method. Callers bring every shape and operation trait into scope with use geomcore::prelude::*.
Before this decision most types carried an inherent twin of each trait method, a one-line forwarder with its own copy of the documentation, so the same contract was written up to 28 times and the copies had begun to drift: some parameter_of twins projected with a hidden Tolerance::DEFAULT, and the B-spline derivative twins documented a limit the elementary curves did not have. The trait is now the interface and each impl is the implementation behind it, which is what dispatch over the enums and the Python method sets build on: they key on the trait's method list, so that list has to be complete and nothing outside it can count as shared.
The projection queries are provided methods built on extrema: project_point is its first entry, project_points maps project_point, contains compares the projected distance with tol.confusion, and parameter_of returns the projected parameter. A type overrides one only where it has a faster closed form, and every existing closed form is kept: the elementary curves invert by atan2 or a dot product and test containment on their implicit equation, and the B-splines project without collecting every extremum. parameter_of and parameters_of take the tolerance that the B-spline projection uses instead of hiding Tolerance::DEFAULT; the elementary closed forms ignore it. Surfaces keep project_point required, with no surface extrema trait: the elementary surfaces project in closed form and have no extrema list to build on.
derivative accepts any order on every curve. The elementary curves always did; the B-spline and Bézier curves now evaluate orders above 2 through the general basis-derivative recurrence and the quotient rule, on a cold path that leaves the unrolled first and second derivatives untouched, so that an implementation of the trait no longer panics where another one answers. Surfaces still evaluate du + dv <= 2 only, and the trait states that limit and its panic.
Considered options
- Keep the inherent twins for discoverability, so
circle.point_at(u)works without importing a trait: rejected. Every shared contract was written in up to 28 places and the copies drifted, and an inherent method silently shadows the trait one, so a type's override could disagree with what generic code and the enums see. The prelude gives the same method syntax with one import. - Generate the twins with a macro: rejected. It removes the typing but not the second interface: rustdoc still lists every method twice, the shadowing remains, and a reader has to expand the macro to learn which body runs.
- Keep
parameter_of(point)with a hidden default tolerance: rejected. The B-spline variant projects, and a projection's result depends on the tolerance; hiding it makes the same call behave differently on two curves that both pass a tolerance everywhere else.
Consequences
Rust code that calls a shared method on a concrete type must import its trait, normally through use geomcore::prelude::*; the flat re-exports are unchanged. Python is unaffected: the bindings import the prelude, and parameter_of and parameters_of gain an optional tol that defaults to Tolerance.default().