Skip to content

Planar faces: bound a face's points before earcut, retain_boundary_points and the pinched-ring search, which are super-linear in a hostile ring #1748

Closed

Description

@DrunkOnJava

What

The planar face path in src/research/native_saved_mesh.rs (face_indexed, plane_mesh) has no bound on a ring's length, and two steps of it are super-linear in the points of a face: retain_boundary_points (for each point earcut left out, a scan of every triangle against every boundary edge) and, since #1740, split_pinched_rings (a quadratic search for a vertex a ring visits twice, run only after an area mismatch). A ring of EDGE_POINT_BUDGET (100,000) points per edge, as a hostile file can hold, costs far more than the rest of the export, where the trimmed-cell path has MAX_TRIM_LOOPS, STRIP_BUDGET and TRIANGLE_BUDGET.

Found by rvtDevelop's read of #1740 (the quadratic search), which does not hold that PR; retain_boundary_points is older and worse.

Done when

  • A planar face with more points than a stated budget (a few thousand points in all of its rings) is refused with a named reason, planar face budget exceeded, before earcut and retain_boundary_points run, as the trimmed path refuses trim strip budget exceeded.
  • The budget is chosen from the corpus: the largest planar face of the 2023 to 2027 samples and the reference models stays under it by a stated factor, and a pure-helper test holds the refusal at the budget's edge.
  • No export of the unfiltered Measure moves (ifc.sha256), or each face over the budget is listed.

Related

#1740 (RE-434), #1732, RE-430's budgets.

Activity

  1. added
    area:geometry
    priority:P3
    type:feature
    on Nov 11, 2026
  2. DrunkOnJava commented on Nov 11, 2026

    @DrunkOnJava
    OwnerAuthor

    Rows registered before the run (branch fix/1748-planar-face-budget).

    Two diagnostic builds of the planar path (a scratch branch, refs/archive/2026-11-11/scratch/1748-planar-points once it is archived; Measure 43082109644 and 43083431385, 69 models, the held-out pairs left out) printed each model's largest planar face and the most work retain_boundary_points does for one:

    • Points in all rings of a face: 2,308 on Autodesk's Snowdon Towers Architectural, 2,006 on the rme samples, 546 on rac_basic, 464 on the offices, 256 on the housing terrain, 172 on RE1 Architecture; every other model 128 or fewer.
    • Work of retain_boundary_points for one face (one unit per triangle edge tested against a point, plus one per boundary edge where the edge has to be tested against all of them): 14,597,894 on the rme samples, 4,451,767 on the timber office at permit, 3,650,486 on Snowdon Towers Architectural, 1,684,295 on the office as built.

    A points budget alone does not bound a hostile face: for each point earcut leaves out, retain_boundary_points tests every triangle edge against every boundary edge, which is the cube of the face's points where a ring is mostly collinear points (2,308 points is minutes of it, by the count). So the change has two budgets: 10,000 points in all the rings of a face (4.3 times the corpus's largest), checked as each ring is read and before earcut, and 250 million units of work in retain_boundary_points (17 times the corpus's largest, about two seconds of one face), counted as it runs. Past either, the face is refused as planar face budget exceeded and its element keeps its box. Three failure-first tests of the pure helpers (the points budget at its edge and where a count would wrap round, and the boundary search refused at a small budget and, at the real one, putting every point back with the square's area).

    Rows, read from the unfiltered Measure of the head against main (hold iff):

    1. No export moves. ifc.sha256 is the same on both sides for every model, the held-out pairs, the Revit 2025 models and the samples included; if one differs, each face over a budget is listed with its points and work.
    2. No new refusal. saved_mesh_refusals holds no planar face budget exceeded on any model.
    3. The corpus stays under both budgets with the held-out pairs read: the largest face and the most work on every model of the run are under 10,000 points and 250 million units (the diagnostics left the held-out pairs out; row 1 is what reads them).
  3. DrunkOnJava commented on Nov 11, 2026

    @DrunkOnJava
    OwnerAuthor

    The budget is the face's, and the ring split is charged to it (revised after rvtDevelop's read of #1768, head 8c52bb52).

    Two findings, both right. (1) The work counter lived inside retain_boundary_points_within, so it was a budget per call: plane_mesh calls it once for each outer ring and face_indexed calls plane_mesh a second time on the split rings, so a face could ask 250 million units several times over. One counter now belongs to the face (face_indexed makes it, plane_mesh and split_pinched_rings charge it) and the second try runs on what the first left. (2) split_pinched_rings searched for a vertex a ring visits twice with an uncounted double loop that is cubic in a ring of many lobes (150, 300, 600 and 1,200 points of a unique prefix and one lobe per six points cost 145,569, 1,144,269, 9,076,044 and 72,302,094 comparisons in rvtDevelop's replay); every pair it compares is now a unit of the same counter, and a ring that runs it out is refused as planar face budget exceeded. Failure-first tests added: a second call on the face's counter is refused where one alone fits, and a ring of a unique prefix and lobes is refused at a small budget and split at the real one.

    Not in this change, filed as #1770: the point check runs after ring_impl has refined each edge (up to 100,000 points an edge) and a face with regions takes none of the budgets (plane_regions_tile).

    The rows above stand for the new head: Measure 43088503271 (unfiltered, head 8c52bb52 against main 5e3ac5b0) is a repeat of row 1 (every ifc.sha256 the same on both sides, the held-out pairs included), now that the work is counted for the face in all, which can only refuse a face the first run did not: if one export moves, the face is listed with its points and work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:geometrypriority:P3type:feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions