Repository navigation
CutTrianglePredicates: tell apart the crossings of multiple edges by SoS - #7682
Conversation
The crossings of the edges of a multiple edge, and the crossings of two cuts at it, are ordered by the SoS expansion of their shifts where the exact terms are zero, also for an edge of zero length or in the plane of the triangle; the lowest term of a cross product is found by the ordered merge of lowestTermOfSumOfProducts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mulAs takes an optional integer maxDeg, above which it computes no products, for the expansions of the shifts that need only the low terms; the default path keeps the compile-time bound M alone and the reserve. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e shifts DeltaCrossing takes interleaved wedges whose shifted cuts cross at Y and checks the order of XP, XQ and Y against a model of the shifts of its own, also with nested wedges, with P and Q in one plane, scaled to near 2^30, with ab in the plane of f or of zero length, and with a flat f. DefinedAlikeAlongSide takes one of its wedge sets per segment in Debug. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mulTo and crossTo give way to mulAs and cross with a degree cap and convertPoly replaces widen, a point keeps the third vertices of its two cuts instead of the whole triangles, and ccwByShifts_ finds the shift definitions only for the expansion; also a true bound in deltaShift_. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t a triple edge A crossing of two cuts at their common edge is on the lines of both cuts with the crossings of the edges of the cuts and the other such crossings, so the side of the third point decides the triangle of any two of them on one line, and the bulge that of three, which were zero at every order and failed after a long expansion. A test of a triple edge, with and without an ordinary crossing on the cut. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two cuts by triangles with a common edge are no longer an addPoint failure but the crossing of that edge moved along them, and a segment parallel to the triangle no longer keeps the shifts from telling its crossings apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A static_assert rejects any compile-time maxDeg of mulAs other than std::integral_constant<D, M>, which it would ignore otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is cut short An expansion of the first-order term that stops before the stages whose degrees do not fit in int64 now fails instead of leaving the triangle to the second-order term, as for two crossings of cuts at a quadruple edge and a crossing of two other cuts, which a new test takes with the deciding vertices first and last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the shifts always addPoint builds the crossing of a common edge only for a crossing of two cuts, shiftNormal_ asserts the perturbed normal that reset asserts instead of returning nullopt, convertPoly takes no other compile-time cap than all degrees, and the second-order term with the shift of another multiple edge reuses shiftDiff. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule for the crossings of cuts at a common edge is documented in ccw, which applies it, rather than in ccwByLines, which needs a line through two of the points; such a crossing does not make the line of its cut bulge; failed lists the crossings at a common edge without the crossings of its edges, and Shift and shiftDirection_ the zero scale and denominator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ween the ends of crossing cuts DeltaCrossing checks that wherever ccw finds the cuts from XP and XQ crossing, their crossing Y is between the ends of both along the sweep, against the model where it applies and alone with P and Q in one plane and for the degenerate edges, which now take the other ends of the cuts and two more wedge sets whose cuts cross. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…one segment Two crossings of the same two cuts, defined alike too, are on both cuts, so the doc names the crossings of one segment instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
QuadrupleEdge takes overlapping P and Q and wedges of S and T whose cuts cross as ccw sees them, as a boolean gives them, and DeltaCrossing takes overlapping P and Q too, the only one-plane case where they cross; crossesAtY, shared now, also checks that the predicates did not fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fedr
left a comment
There was a problem hiding this comment.
Reviewed at e7b856d (diff and CI logs; not built locally).
Must fix: empty-optional dereference in CutTrianglePredicatesDeltaCrossing
In table, pos[5] is Y, a crossing of two cuts, and fractionOf returns nullopt for crossings; only pos[7] is set by hand. The checkCcw lambda calls orientFractions( *pos[i], *pos[j], *pos[k], 0, 1 ) whenever numAlike < 2, which includes every triangle with Y alone. This is the red job (msvc-2019 Debug, iterator-debug): "Cannot access value of empty optional" right after [ RUN ] MRMesh.CutTrianglePredicatesDeltaCrossing. On the other jobs it is silent UB, so the triangles of Y with two other points are compared with garbage. Setting pos[5] to (1, 1), as XP and XQ have, fixes it; whether the predicates agree for those triangles is unknown until then.
Suggestions
- Test time in Debug:
CutTrianglePredicatesDefinedAlikeAlongSidetakes 88.7 s on MSVC iterator-debug and 40.9 s on macOS arm64 Debug (4-9 s in Release). Fewer variant tables percheckin Debug would do. - The delta shift has no independent model:
DeltaCrossingchecks the CC axioms, the side of the cut and the invariance under swapping the cuts on one configuration, whiledeltaShift_and its part ofsosShiftare never compared with a computation of their own, as the edge shifts are withSosModel. A case with coplanar P and Q (c == 0, theden == 0path) and one with ab in the plane of f would cover the branches no test reaches now. ccwByShifts_findsshiftDefOf( p )andshiftDefOf( q )on every call, though only the SoS lambdas use them; each scans all points (several times for a delta point), on top of the scans inshift_. Finding them inside the lambdas keeps the exact path at its old cost.CutTrianglePredicatesCrossingRules: the common-edge crossing leftbrokenwith only a comment. The variants that still fail (the common edge with a vertex of f, twin faces) could go there, to pin whatcommonEdgeCrossingtakes.
Checked, no remarks
The signs and denominators of the exact shifts against the SoS ones (shift_, deltaShift_, sosShift, the four sosAlike callers); deltaShift_ under reversing the segment; shiftSegment for a zero-length segment against the order of the perturbation; the integer widths in deltaShift_ and shiftDiff; SosVerts capacity (at most 19 of 21); common-edge crossings with a vertex of f failed on master and still do.
… a shift first After a failure, points defined alike that their shifts do not tell apart are ordered by their ids after those with a shift, so that less stays a strict total order also with a crossing at a common edge left without a shift between two crossings of the edge that their shifts order against their ids, as twin faces give. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… point without a shift as unshifted As the exact term does, so that the triangle of two points defined alike and a third one without a shift no longer fails where the exact shifts of the two are parallel; a new test checks such triangles against a model of the perturbed shifts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rturbed values shift_ finds the exact shift from the definition that the perturbed one takes and keeps it in the shift, so the callers do not scan the points for it again, and a crossing at a common edge, whose shift deltaShift_ found from the shifts of the crossings of the edges, scans them four times instead of six. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a crossing at their common edge The failure of two points defined alike on a known line with the difference of their shifts along it leaves out a cut of a crossing at their common edge among them, where the bulge or the second-order term decides; setLoopPredicates keys such a crossing by its triangles, so the sweep compares it with the crossings of its edge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The capped product keeps the terms of the full one up to the cap, none below the lowest degree, and the same for a cap between two degrees as for the lower one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ertex of the triangle fail CrossingRules adds to the definitions that make addPoint fail two cuts by triangles with a common edge from a vertex of f, with that vertex at either end of the edge, whose crossing with f is at its end, as they failed before the crossings at a common edge were taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. All points are addressed in the new commits:
Also since the review: three crossings of cuts at a triple edge (d324474); a failure where the expansion of the first-order term stops at the int64 degree limit, instead of the second-order term deciding (a2b7e57); |
MSVC 2019 /Wall flags C4127 where a test condition starts with the build-type constant cTrialDivisor: DeltaCrossing tests its wedges first, and QuadrupleEdge checks ccw in Debug too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fedr
left a comment
There was a problem hiding this comment.
Thanks, all five points are addressed at 278039b and CI is green. Two nits, neither blocking:
shiftNormal_now returns*nafterassert( n ), where it returnednulloptbefore. A triangle with a repeated vertex id has a zero perturbed normal at every stage, so a predicate called after the failedresetdereferences an empty optional in Release.n.value_or( Vector3i64() )would lead to the existing failure instead.mulAswith a run-timemaxDeghas nobreakin the outer loop ondegA > maxDeg, whichmulTohad; it only costs a comparison per remaining term.
…a failure less needs only whether a point has a shift there, not the shift itself; the scaled shift names its fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
The crossings of the two edges of a multiple edge with a triangle are defined alike and told apart by shifts toward their wedges. Where the exact shifts gave zero (an edge of zero length or in the plane of the triangle, a triangle with a zero normal, coincident wedges), the predicates failed or used a non-SoS fallback, and selfBoolean reported nested intersections. Now:
lowestTermOfSumOfProducts(ordered merge) instead of all products;mulAstakes an optional degree cap at run time, and its default path is unchanged;lessstays a strict weak order: points defined alike that the shifts do not tell apart come with a shift first, then by id.Where master's constant-shift first-order fallback answered, the full expansion decides now. Twin faces (two triangles on the same three vertices) stay undecidable.
On a real-world mesh with many multiple edges, selfBoolean's nested-intersection faces go from 32 to 17 (all but one on twin faces; that one fails after the cut on master too), at master's speed (measured before the review fixes).
Test plan
CutTrianglePredicatestests check the CC axioms,DefinedAlikeAlongSideagainst an independent model of the edge shifts,DeltaCrossingagainst a model of the delta shift, plus triple and quadruple edges, a point defined alike without a shift and the order oflessafter a failure;mulAsMaxDegDefinedAlikeAlongSide15 s in DebugGenerated with Claude Code