Skip to content

Make booleans deterministic - #20

Merged
komietty merged 2 commits into
komietty:mainfrom
vvvlladimir:deterministic
Oct 28, 2026
Merged

komietty merged 2 commits into
komietty:mainfrom
vvvlladimir:deterministic

Conversation

@vvvlladimir

Copy link
Copy Markdown
Contributor

Fixes #19

The same two inputs could produce different outputs from run to run, even
on one thread. Two changes, no change to the algorithm:

  • boolean45: HashMap → BTreeMap for the edge-point maps, so faces get
    their new halfedges in key order (as std::map does in the C++ original).
  • ear_clip.rs: ties in the ear and hole queues break by creation order
    instead of Rc address.

test_same_input_same_output runs three cube booleans 30 times each and
fails on main. All existing tests pass with and without rayon and f32.

Happy to adjust naming or style to match the crate.

Replace `HashMap` with `BTreeMap` and introduce sequence counters for
tie-breaking in ear clipping, ensuring consistent output across runs
regardless of memory allocation order.
@komietty

komietty commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

Thanks for the fix, the determinism change itself looks good.
One request, could you drop src/par.rs from this PR? It isn't related to the determinism fix.

@vvvlladimir

Copy link
Copy Markdown
Contributor Author

Dropped src/par.rs, thanks!

@komietty

Copy link
Copy Markdown
Owner

LGTM. Thank you for your PR.

@komietty
komietty merged commit f267930 into komietty:main Oct 28, 2026
4 checks passed
@vvvlladimir
vvvlladimir deleted the deterministic branch October 29, 2026 00:14
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.

Same inputs can give different triangulations from run to run

2 participants