Skip to content

CutTrianglePredicates: tell apart the crossings of multiple edges by SoS - #7682

Merged
Grantim merged 21 commits into
masterfrom
cut-predicates-multiple-edges
Dec 5, 2026
Merged

Grantim merged 21 commits into
masterfrom
cut-predicates-multiple-edges

Conversation

@Grantim

@Grantim Grantim commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • the crossing of two cuts by triangles with a common edge is defined alike with the crossings of that edge, moved along its cut;
  • where the exact terms of the shifts are zero, their SoS expansion decides; an expansion that stops at the int64 degree limit fails;
  • the crossings of cuts at a common edge and the crossings of its edges lie on the lines of their cuts, so the side of the third point of the plane of the cut decides two of them, and the bulge three (also at a triple edge);
  • the lowest term of a cross product of expansions comes from lowestTermOfSumOfProducts (ordered merge) instead of all products; mulAs takes an optional degree cap at run time, and its default path is unchanged;
  • after a failure, less stays 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

  • MRTest Release 832/832; the 25 CutTrianglePredicates tests check the CC axioms, DefinedAlikeAlongSide against an independent model of the edge shifts, DeltaCrossing against a model of the delta shift, plus triple and quadruple edges, a point defined alike without a shift and the order of less after a failure; mulAsMaxDeg
  • Debug: CutTrianglePredicates, ContoursCut, Triangulation tests 45/45, no asserts; DefinedAlikeAlongSide 15 s in Debug
  • Boolean regression set vs master 93749d1: Release 3097/3097 and Debug 1262/1262 bit-identical (it has no multiple-edge cases)
  • 3366 spheres, dental, nef benchmarks: within noise of master at the first commit; the review fixes change only points defined alike and the order after a failure, not measured
  • GCC and clang builds: CI

Generated with Claude Code

Grantim and others added 13 commits December 4, 2026 23:12
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 Fedr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: CutTrianglePredicatesDefinedAlikeAlongSide takes 88.7 s on MSVC iterator-debug and 40.9 s on macOS arm64 Debug (4-9 s in Release). Fewer variant tables per check in Debug would do.
  • The delta shift has no independent model: DeltaCrossing checks the CC axioms, the side of the cut and the invariance under swapping the cuts on one configuration, while deltaShift_ and its part of sosShift are never compared with a computation of their own, as the edge shifts are with SosModel. A case with coplanar P and Q (c == 0, the den == 0 path) and one with ab in the plane of f would cover the branches no test reaches now.
  • ccwByShifts_ finds shiftDefOf( p ) and shiftDefOf( 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 in shift_. Finding them inside the lambdas keeps the exact path at its old cost.
  • CutTrianglePredicatesCrossingRules: the common-edge crossing left broken with only a comment. The variants that still fail (the common edge with a vertex of f, twin faces) could go there, to pin what commonEdgeCrossing takes.

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.

Grantim and others added 6 commits December 5, 2026 16:41
… 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>
@Grantim

Grantim commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All points are addressed in the new commits:

  • Empty-optional dereference in DeltaCrossing: fixed in d87bb46, Y takes the common position (1, 1). The test now also takes wedges whose shifted cuts really cross at Y.
  • Debug time: in d87bb46 DefinedAlikeAlongSide takes one of its five wedge sets per segment in Debug (locally 69 s -> 15 s in MSVC Debug); Release keeps the full grid.
  • Independent model of the delta shift: d87bb46 checks the order of XP, XQ and Y against a model of the shifts of the test's own (u - (n.u)/(n.d) d, and the crossing of the shifted cut lines), also with nested wedges. Variants with P and Q in one plane (c == 0), ab in the plane of f, ab of zero length, a flat f and coordinates near 2^30 are checked for the CC axioms and, where ccw says the cuts cross, for Y between the ends of both cuts (08a8799, 743c4c7).
  • shiftDefOf on every call: since 61cd61b ccwByShifts_ finds the shift definitions only for the perturbed terms, and since 46544ba a shift carries its definition, so the exact and the perturbed values share one search.
  • broken in CrossingRules: 65b4412 adds two cuts with a common edge from a vertex of f (as either end of the edge), which still fail in addPoint; twin faces were already there as crossing( p, p ) and its reordered variant.

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); less stays a strict weak order after a failure, with the points that have a shift first (e9ef897); a point defined alike without a shift is unshifted in the perturbed second-order term too, as in the exact one (24ef23e).

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 Fedr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all five points are addressed at 278039b and CI is green. Two nits, neither blocking:

  • shiftNormal_ now returns *n after assert( n ), where it returned nullopt before. A triangle with a repeated vertex id has a zero perturbed normal at every stage, so a predicate called after the failed reset dereferences an empty optional in Release. n.value_or( Vector3i64() ) would lead to the existing failure instead.
  • mulAs with a run-time maxDeg has no break in the outer loop on degA > maxDeg, which mulTo had; 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>
@Grantim
Grantim merged commit 8d48b65 into master Dec 5, 2026
63 checks passed
@Grantim
Grantim deleted the cut-predicates-multiple-edges branch December 5, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants