Nef_3: Fix ID_support_handler logic error - #9478
Open
GilesBathgate wants to merge 1 commit into
Open
Conversation
…loop merging methods
Contributor
Author
|
A better approach would be to refactor the code duplication into something like this: int unify_indices(int idx1, int idx2) {
int root1 = get_hash(idx1);
int root2 = get_hash(idx2);
if (root1 == root2) return root2;
// Union by ID: The numerically smaller index becomes the parent
if (root1 < root2) {
set_hash(idx2, root1);
return root1;
} else {
set_hash(idx1, root2);
return root2;
}
}Then replace the repeated code with: int index = unify_indices(se1->get_index(), se2->get_index());
se->set_index(index);
index = unify_indices(se1->twin()->get_index(), se2->twin()->get_index());
se->twin()->set_index(index);Should that be out of scope for a simple bug fix? |
Member
|
Successfully tested in CGAL-6.3-Ic-31 |
Member
|
Can you please also add the testcase that produces an error. Does it segfault, trigger an assertion, or "only" produce a wrong result? |
GilesBathgate
commented
Jul 20, 2026
| const int id3 = 20; | ||
| const int id4 = 21; | ||
|
|
||
| // edge-edge |
Contributor
Author
There was a problem hiding this comment.
@afabri The test case is already added. As mentioned in the summary, the test fails without the fix applied.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
This fixes a logical error in ID_support_handler (probably caused by a typo)
First I should explain that in this code:
cgal/Nef_3/include/CGAL/Nef_3/ID_support_handler.h
Lines 304 to 314 in 2e165ee
The assignment of se1's hashed index to se1's hashed index (line 308) is a no-op
H[x₁] ← H[x₁]likewise the assignment of sl2's hashed index to sl2's hashed index (line 313) is a no-op. These no-op's don't really matter but for the sake of correctness I've removed them. The real problem is with this code:
cgal/Nef_3/include/CGAL/Nef_3/ID_support_handler.h
Line 276 in 2e165ee
The intention here isn't a no-op the intention is for it to merge the indexes using the union find.
set_hash(se2->twin()->get_index(), index1);I have created a failing test that passes when the fix is applied. However in a more general sense this bug doesn't create a topological, or geometric flaw, because in the correct logic is applied in another pass:
cgal/Nef_3/include/CGAL/Nef_3/SNC_SM_overlayer.h
Lines 320 to 334 in 2e165ee
In certain cases cycling the svertices means visiting the same halfedges via each local sphere but with the indexes reversed (
index2 < index1) so it falls into the branch of code where the logic is correct.Release Management