Skip to content

Fix refine for clockwise meshes - #218

Closed
vera-rubin wants to merge 1 commit into
mapbox:mainfrom
vera-rubin:fix/refine-clockwise
Closed

vera-rubin wants to merge 1 commit into
mapbox:mainfrom
vera-rubin:fix/refine-clockwise

Conversation

@vera-rubin

Copy link
Copy Markdown

For vertices [0, 0, 1, 0, 4, 1, 0, 2], refine leaves diagonal (0,2) unchanged when we reverse the triangles, although the documented refinement should legalize it to (1,3) in either winding.

Tested base commit: 765470e73adfdfe5cd0dfc1c1a398f558cdea3a0.

import earcut, {refine} from './src/earcut.js';
const vertices = [0, 0, 1, 0, 4, 1, 0, 2];
const triangles = earcut(vertices).reverse();
refine(triangles, vertices);
console.log(triangles);
// before: [1, 0, 2, 0, 3, 2]
// after:  [1, 3, 2, 0, 3, 1]

We account for each triangle's winding in the incircle and convexity checks, preserving the existing cocircular tolerance and triangle orientation.

The clockwise regression, full test suite, and build pass.

— ChipLab

@vera-rubin
vera-rubin requested a review from a team as a code owner October 16, 2026 13:29
@vera-rubin
vera-rubin requested review from dcoj and removed request for a team October 16, 2026 13:29
@mourner
mourner requested review from mourner and removed request for dcoj October 16, 2026 14:44
@mourner

mourner commented Oct 17, 2026

Copy link
Copy Markdown
Member

Thanks for the catch and the contribution! I went with a more performant fix in 2ba39c3.

@mourner mourner closed this Oct 17, 2026
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