A tangent contact within tolerance is one complete hit
Two curves that touch, staying within tol.confusion of each other over a stretch and then parting, have one contact. The numeric curve–curve search reports it as one hit at the closest approach, with multiplicity 2 where the curves are tangent there, and the result stays Complete. The closed forms already report a tangent contact as a complete hit with multiplicity 2, so the numeric route and the closed form now agree on the same configuration (issue #163).
A stretch where the curves run along one another, an overlap, is unchanged: it is joined into an overlap, and the result stays Incomplete with an Unseparated region over it, because a stretch of coincidence cannot be split into hits. A search that runs out of its budget of halvings also stays Incomplete with BudgetExhausted, because pieces it did not settle may hide further hits, and a contact found there is not proven to be the only one.
The contact is found after the subdivision, on the stretches the subdivision left unseparated. Those stretches are tested against the closest approach of the sampled distance, refined by golden-section search, so the hit sits where the distance is least. A stretch counts as a contact only when that closest approach lies within tol.confusion, and its regions are dropped from the result once a contact accounts for them.
Multiplicity is 2 where the two curves touch within confusion, and 1 where they cross. The rule is the one the marching search already uses for surfaces (SurfacePair::grazes), with the same tolerances. Across the hit, the second curve lies w sin(theta) + k w^2 / 2 from the first at distance w along it, theta being the angle between the tangents and k the magnitude of the difference of the two curvature vectors perpendicular to the common tangent. Moved by confusion, the curves touch when sin^2(theta) <= 2 k tol.confusion. An exactly parallel pair (sin(theta) <= tol.angular) is a touch whatever the curvatures. Lines have k = 0, so a shallow crossing of two lines stays a crossing at any angle above tol.angular. The curvatures are read only where the tangents are not exactly parallel.
A curve–surface hit found by the numeric search follows the same rule, with the surface in place of the second curve (#428). At the distance w along the curve, the curve lies s w + k w^2 / 2 from the surface, s being the sine of the angle between the curve's tangent and the surface's tangent plane and k = |kappa . n - II(P, P)|: kappa . n is the curve's curvature along the surface's unit normal, and II(P, P) the surface's second fundamental form on P, the part of the curve's unit tangent in the tangent plane. The hit is a touch when s <= tol.angular or s^2 <= 2 k tol.confusion. A line has kappa = 0 and a plane II = 0, so a line crossing a plane at a shallow angle stays a crossing. A hit the search places on the touch (#417) reports 2 directly.
Considered options
- Make the closed forms
Incompleteat a tangent, so that both routes agree on the weaker status: rejected. The closed forms are exact, so a tangent there is a complete answer; downgrading it would make every tangent a non-result, and a caller could no longer use the completeness flag to tell a tangent apart from an unfinished search. The numeric route was the one that disagreed, so it moves. - Keep the merge radius of
sqrt(tol.confusion)for hits: rejected. It dropped distinct crossings closer than that radius and reported the resultComplete(issue #162). Hits now merge only when the curves stay within confusion between them. - Compare the multiplicity's tangent angle with
tol.angularalone: rejected. The located tangent direction is off from the true one by far more thantol.angular(1e-12 at the default tolerance), so a circle tangent to a line came back with multiplicity 1. The grazing rule keepstol.angularfor exactly parallel tangents and tests the curvature otherwise. - Compare a curve–surface hit's angle with
tol.angular_for_extentof the hit's distance to the origin plus one: rejected (#428). The angle that counts as tangent shrank as the shapes moved away from the origin, and the added unit assumed a unit-sized model, so a segment crossing a plane at a slope of 1e-8 was a touch at the origin and a crossing translated by 1e3. Sines and curvatures are the same at every placement and size (ADR 0051). - Threshold the sine at
sqrt(tol.confusion): rejected. It assumes unit curvature, so it depends on the scale of the curves (a circle of radius1e-3has curvature1e3), and it reports a shallow crossing at1e-4rad as a touch although moving either line by confusion never makes them touch. The curvature test is scale-free by construction. - Run the contact stage on the
BudgetExhaustedregions too: rejected. A budget that ran out has not settled its pairs, so a closest approach found there is not proven to be the only contact. Those results stay incomplete, as they were. - Report a contact as
Unseparatedwith its hit: rejected.Unseparatednames a stretch the search could not settle, and a contact is settled: its hit is one point and the curves part on both sides. Keeping it complete lets a caller trust the result without checking the reason. - One hit per side of the tangency: rejected. The two roots of a near-double root sit about
sqrt(tol.confusion)apart, and each side of a circle tangent to a circle yields one. Those are one contact, so they are merged by the stretch test insame_contact, which checks that the curves stay within confusion between the two hits. The test runs between neighbours in first-curve parameter only, the hit kept before and, on a closed first curve, the last and the first across its seam, and keeps the one of the two where the curves come closer: between two hits far apart, its probes can land on other crossings and pass by accident (#425).