Skip to content

Fix contour grouping when holes precede their outer boundary - #278

Open
vilicvane wants to merge 1 commit into
sgenoud:mainfrom
vilicvane:fix/contour-overlap-groups
Open

vilicvane wants to merge 1 commit into
sgenoud:mainfrom
vilicvane:fix/contour-overlap-groups

Conversation

@vilicvane

Copy link
Copy Markdown

When two disjoint holes appear before their enclosing contour, organiseBlueprints can treat one hole as a separate filled region. This also affects text glyphs such as DejaVu Sans B, producing overlapping solids and incorrect embossed or engraved text.

groupByBoundingBoxOverlap assigns a tentative group to later overlapping contours. When both holes overlap the same outer contour, the second assignment overwrites the first without merging the existing groups. Containment is then evaluated separately, so one hole loses its outer boundary.

This change joins connected bounding-box groups with a disjoint-set structure before collecting contours. It preserves input order within groups and first-seen group order. The existing containment and geometry-building logic remains in use.

Minimal reproduction

No font file is needed:

const main = ({ drawRectangle, organiseBlueprints }) => {
  const contours = [
    drawRectangle(2, 2).translate(-2, 0).blueprint,
    drawRectangle(2, 2).translate(2, 0).blueprint,
    drawRectangle(10, 10).blueprint,
  ];
  return organiseBlueprints(contours).sketchOnPlane("XY").extrude(1);
};

The expected result is one solid with two holes and volume 92. Before this change, the result contains two overlapping solids with a summed volume of 100 and only one recognized hole.

Validation

  • Added 55 regression cases covering all input permutations for two holes, a nested island with its own hole, and disconnected regions, plus empty/single-contour inputs. The tests check contour membership, ordering, and extruded volumes.
  • Confirmed the two holes-first permutations fail before the fix and all 55 cases pass afterward.
  • npm run prepare-packages
  • npm test — all 163 tests pass across the four tested workspaces.
  • npm run typecheck
  • npm run build --workspace=studio
  • npm run build --workspace=replicad-app-example
  • Prettier check on both changed files and git diff --check.

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.

1 participant