Silently remove duplicate consecutive prism vertices#60
Merged
stevengj merged 3 commits intoNanoComp:masterfrom Feb 2, 2022
Merged
Silently remove duplicate consecutive prism vertices#60stevengj merged 3 commits intoNanoComp:masterfrom
stevengj merged 3 commits intoNanoComp:masterfrom
Conversation
stevengj
reviewed
Jan 26, 2022
utils/geom.c
Outdated
| "consecutive prism vertices are duplicates."); | ||
| } | ||
| CHECK(!vector3_equal(vertices[num_vertices-1], vertices[0]), | ||
| "consecutive prism vertices are duplicates."); |
Collaborator
There was a problem hiding this comment.
Note that a CHECK failure will call exit, which won't be that nice from e.g. Python.
Collaborator
There was a problem hiding this comment.
For example, to delete consecutive equal vertices, including the last point, you could do:
int i = 0; // last non-deleted vertex
for (j = 1; j < num_vertices; ++j) {
if (!vector3_equal(vertices[i], vertices[j])) {
i += 1;
if (i < j) vertices[i] = vertices[j];
}
}
num_vertices = i + 1 - vector3_equal(vertices[0], vertices[i]);
prsm->vertices.num_items = num_vertices;
Collaborator
There was a problem hiding this comment.
(In principle, you could then call realloc to save a bit of memory in vertices, but it's probably not worth it — realloc is potentially unsafe if the memory was not allocated with malloc.)
Collaborator
Author
There was a problem hiding this comment.
Fixed. I included a realloc if the number of vertices has changed since the vertices array (via the items member of prsm->vertices) is allocated with malloc:
Lines 246 to 248 in 76deb2a
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.
Fixes NanoComp/meep#1905.