Skip to content

Fixes #896 : Fixed getVertexCount() method issue of giving output 0 for GROUP shapes #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion core/src/processing/core/PShape.java
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,18 @@ protected void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
* @see PShape#getVertex(int)
* @see PShape#setVertex(int, float, float)
*/
public int getVertexCount(boolean includeChildren) {
if(!includeChildren && family == GROUP){
PGraphics.showWarning(NO_VERTICES_ERROR);
}
else if (family == PRIMITIVE) {
PGraphics.showWarning(NO_VERTICES_ERROR);
}
return vertexCount;
}

public int getVertexCount() {
if (family == GROUP || family == PRIMITIVE) {
if(family == GROUP || family == PRIMITIVE){
PGraphics.showWarning(NO_VERTICES_ERROR);
}
return vertexCount;
Expand Down
31 changes: 23 additions & 8 deletions core/src/processing/opengl/PShapeOpenGL.java
Original file line number Diff line number Diff line change
Expand Up @@ -1632,30 +1632,45 @@ protected void curveVertexImpl(float x, float y, float z) {

// Setters/getters of individual vertices


//for taking the default value as false , so user don't have to explicitly enter false
// if user don't want to include children vertex count
@Override
public int getVertexCount() {
if (family == GROUP) return 0; // Group shapes don't have vertices
else {
return getVertexCount(false); // Calls the main method with default false
}
@Override
public int getVertexCount(boolean includeChildren) {
int count = 0;
// If the shape is a group, recursively count the vertices of its children
if (family == GROUP) {
if(!includeChildren){
return 0;
}
// Iterate through all the child shapes and count their vertices
for (int i = 0; i < getChildCount(); i++) {
count += getChild(i).getVertexCount(true); // Recursive call to get the vertex count of child shapes
}
} else {
if (root.tessUpdate) {
if (root.tessKind == TRIANGLES) {
return lastPolyVertex - firstPolyVertex + 1;
count += lastPolyVertex - firstPolyVertex + 1;
} else if (root.tessKind == LINES) {
return lastLineVertex - firstLineVertex + 1;
count += lastLineVertex - firstLineVertex + 1;
} else if (root.tessKind == POINTS) {
return lastPointVertex - firstPointVertex + 1;
count += lastPointVertex - firstPointVertex + 1;
} else {
return 0;
count += 0; // Handle other cases
}
} else {
if (family == PRIMITIVE || family == PATH) {
// the input geometry of primitive and path shapes is built during
// tessellation
updateTessellation();
}
return inGeo.vertexCount;
count += inGeo.vertexCount;
}
}
return count;
}


Expand Down