Skip to content

Commit 93d2f93

Browse files
committed
Fixed issue : Updated the getVertexCount() to take optional boolean value to count children
1 parent 04ecae1 commit 93d2f93

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

core/src/processing/core/PShape.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,8 +2345,18 @@ protected void setPath(int vcount, float[][] verts, int ccount, int[] codes) {
23452345
* @see PShape#getVertex(int)
23462346
* @see PShape#setVertex(int, float, float)
23472347
*/
2348+
public int getVertexCount(boolean includeChildren) {
2349+
if(!includeChildren && family == GROUP){
2350+
PGraphics.showWarning(NO_VERTICES_ERROR);
2351+
}
2352+
else if (family == PRIMITIVE) {
2353+
PGraphics.showWarning(NO_VERTICES_ERROR);
2354+
}
2355+
return vertexCount;
2356+
}
2357+
23482358
public int getVertexCount() {
2349-
if (family == PRIMITIVE) {
2359+
if(family == GROUP || family == PRIMITIVE){
23502360
PGraphics.showWarning(NO_VERTICES_ERROR);
23512361
}
23522362
return vertexCount;

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,15 +1632,23 @@ protected void curveVertexImpl(float x, float y, float z) {
16321632

16331633
// Setters/getters of individual vertices
16341634

1635-
1635+
//for taking the default value as false , so user don't have to explicitly enter false
1636+
// if user don't want to include children vertex count
16361637
@Override
16371638
public int getVertexCount() {
1639+
return getVertexCount(false); // Calls the main method with default false
1640+
}
1641+
@Override
1642+
public int getVertexCount(boolean includeChildren) {
16381643
int count = 0;
16391644
// If the shape is a group, recursively count the vertices of its children
16401645
if (family == GROUP) {
1646+
if(!includeChildren){
1647+
return 0;
1648+
}
16411649
// Iterate through all the child shapes and count their vertices
16421650
for (int i = 0; i < getChildCount(); i++) {
1643-
count += getChild(i).getVertexCount(); // Recursive call to get the vertex count of child shapes
1651+
count += getChild(i).getVertexCount(true); // Recursive call to get the vertex count of child shapes
16441652
}
16451653
} else {
16461654
if (root.tessUpdate) {
@@ -1666,7 +1674,6 @@ public int getVertexCount() {
16661674
}
16671675

16681676

1669-
16701677
@Override
16711678
public PVector getVertex(int index, PVector vec) {
16721679
if (vec == null) vec = new PVector();

0 commit comments

Comments
 (0)