Skip to content

Commit dea905f

Browse files
committed
fixed handling of rect parametrers in PShape
1 parent 994eebc commit dea905f

File tree

4 files changed

+55
-122
lines changed

4 files changed

+55
-122
lines changed

core/src/processing/opengl/PGraphics2D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static protected PShapeOpenGL createShapeImpl(PApplet parent,
346346
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
347347
shape.setKind(QUAD);
348348
} else if (kind == RECT) {
349-
if (len != 4 && len != 5 && len != 8) {
349+
if (len != 4 && len != 5 && len != 8 && len != 9) {
350350
showWarning("Wrong number of parameters");
351351
return null;
352352
}

core/src/processing/opengl/PGraphics3D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static protected PShapeOpenGL createShapeImpl(PApplet parent,
217217
shape = new PShapeOpenGL(parent, PShape.PRIMITIVE);
218218
shape.setKind(QUAD);
219219
} else if (kind == RECT) {
220-
if (len != 4 && len != 5 && len != 8) {
220+
if (len != 4 && len != 5 && len != 8 && len != 9) {
221221
showWarning("Wrong number of parameters");
222222
return null;
223223
}

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,40 +2908,6 @@ public void quad(float x1, float y1, float x2, float y2,
29082908
endShape();
29092909
}
29102910

2911-
//////////////////////////////////////////////////////////////
2912-
2913-
// RECT
2914-
2915-
// public void rectMode(int mode)
2916-
2917-
@Override
2918-
public void rect(float a, float b, float c, float d) {
2919-
beginShape(QUADS);
2920-
defaultEdges = false;
2921-
normalMode = NORMAL_MODE_SHAPE;
2922-
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
2923-
ambientColor, specularColor, emissiveColor, shininess);
2924-
inGeo.setNormal(normalX, normalY, normalZ);
2925-
inGeo.addRect(a, b, c, d, fill, stroke, rectMode);
2926-
endShape();
2927-
}
2928-
2929-
2930-
@Override
2931-
public void rect(float a, float b, float c, float d,
2932-
float tl, float tr, float br, float bl) {
2933-
beginShape(POLYGON);
2934-
defaultEdges = false;
2935-
normalMode = NORMAL_MODE_SHAPE;
2936-
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
2937-
ambientColor, specularColor, emissiveColor, shininess);
2938-
inGeo.setNormal(normalX, normalY, normalZ);
2939-
inGeo.addRect(a, b, c, d, tl, tr, br, bl,
2940-
fill, stroke, bezierDetail, rectMode);
2941-
endShape(CLOSE);
2942-
}
2943-
2944-
// protected void rectImpl(float x1, float y1, float x2, float y2)
29452911

29462912
//////////////////////////////////////////////////////////////
29472913

@@ -8634,39 +8600,7 @@ void addQuad(float x1, float y1, float z1,
86348600
}
86358601

86368602
void addRect(float a, float b, float c, float d,
8637-
boolean fill, boolean stroke, int rectMode) {
8638-
float hradius, vradius;
8639-
switch (rectMode) {
8640-
case CORNERS:
8641-
break;
8642-
case CORNER:
8643-
c += a; d += b;
8644-
break;
8645-
case RADIUS:
8646-
hradius = c;
8647-
vradius = d;
8648-
c = a + hradius;
8649-
d = b + vradius;
8650-
a -= hradius;
8651-
b -= vradius;
8652-
break;
8653-
case CENTER:
8654-
hradius = c / 2.0f;
8655-
vradius = d / 2.0f;
8656-
c = a + hradius;
8657-
d = b + vradius;
8658-
a -= hradius;
8659-
b -= vradius;
8660-
}
8661-
8662-
if (a > c) {
8663-
float temp = a; a = c; c = temp;
8664-
}
8665-
8666-
if (b > d) {
8667-
float temp = b; b = d; d = temp;
8668-
}
8669-
8603+
boolean fill, boolean stroke) {
86708604
addQuad(a, b, 0,
86718605
c, b, 0,
86728606
c, d, 0,
@@ -8676,45 +8610,7 @@ void addRect(float a, float b, float c, float d,
86768610

86778611
void addRect(float a, float b, float c, float d,
86788612
float tl, float tr, float br, float bl,
8679-
boolean fill, boolean stroke, int detail, int rectMode) {
8680-
float hradius, vradius;
8681-
switch (rectMode) {
8682-
case CORNERS:
8683-
break;
8684-
case CORNER:
8685-
c += a; d += b;
8686-
break;
8687-
case RADIUS:
8688-
hradius = c;
8689-
vradius = d;
8690-
c = a + hradius;
8691-
d = b + vradius;
8692-
a -= hradius;
8693-
b -= vradius;
8694-
break;
8695-
case CENTER:
8696-
hradius = c / 2.0f;
8697-
vradius = d / 2.0f;
8698-
c = a + hradius;
8699-
d = b + vradius;
8700-
a -= hradius;
8701-
b -= vradius;
8702-
}
8703-
8704-
if (a > c) {
8705-
float temp = a; a = c; c = temp;
8706-
}
8707-
8708-
if (b > d) {
8709-
float temp = b; b = d; d = temp;
8710-
}
8711-
8712-
float maxRounding = PApplet.min((c - a) / 2, (d - b) / 2);
8713-
if (tl > maxRounding) tl = maxRounding;
8714-
if (tr > maxRounding) tr = maxRounding;
8715-
if (br > maxRounding) br = maxRounding;
8716-
if (bl > maxRounding) bl = maxRounding;
8717-
8613+
boolean fill, boolean stroke, int detail) {
87188614
if (nonZero(tr)) {
87198615
addVertex(c-tr, b, VERTEX);
87208616
addQuadraticVertex(c, b, 0, c, b+tr, 0,

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,20 +2713,18 @@ protected void tessellateRect() {
27132713
float a = 0, b = 0, c = 0, d = 0;
27142714
float tl = 0, tr = 0, br = 0, bl = 0;
27152715
boolean rounded = false;
2716-
if (params.length == 4) {
2716+
int mode = rectMode;
2717+
2718+
if (params.length == 4 || params.length == 5) {
27172719
a = params[0];
27182720
b = params[1];
27192721
c = params[2];
27202722
d = params[3];
2723+
if (params.length == 5) {
2724+
mode = (int)(params[4]);
2725+
}
27212726
rounded = false;
2722-
} else if (params.length == 5) {
2723-
a = params[0];
2724-
b = params[1];
2725-
c = params[2];
2726-
d = params[3];
2727-
tl = tr = br = bl = params[4];
2728-
rounded = true;
2729-
} else if (params.length == 8) {
2727+
} else if (params.length == 8 || params.length == 9) {
27302728
a = params[0];
27312729
b = params[1];
27322730
c = params[2];
@@ -2735,20 +2733,59 @@ protected void tessellateRect() {
27352733
tr = params[5];
27362734
br = params[6];
27372735
bl = params[7];
2736+
if (params.length == 9) {
2737+
mode = (int)(params[8]);
2738+
}
27382739
rounded = true;
27392740
}
27402741

2742+
float hradius, vradius;
2743+
switch (mode) {
2744+
case CORNERS:
2745+
break;
2746+
case CORNER:
2747+
c += a; d += b;
2748+
break;
2749+
case RADIUS:
2750+
hradius = c;
2751+
vradius = d;
2752+
c = a + hradius;
2753+
d = b + vradius;
2754+
a -= hradius;
2755+
b -= vradius;
2756+
break;
2757+
case CENTER:
2758+
hradius = c / 2.0f;
2759+
vradius = d / 2.0f;
2760+
c = a + hradius;
2761+
d = b + vradius;
2762+
a -= hradius;
2763+
b -= vradius;
2764+
}
2765+
2766+
if (a > c) {
2767+
float temp = a; a = c; c = temp;
2768+
}
2769+
2770+
if (b > d) {
2771+
float temp = b; b = d; d = temp;
2772+
}
2773+
2774+
float maxRounding = PApplet.min((c - a) / 2, (d - b) / 2);
2775+
if (tl > maxRounding) tl = maxRounding;
2776+
if (tr > maxRounding) tr = maxRounding;
2777+
if (br > maxRounding) br = maxRounding;
2778+
if (bl > maxRounding) bl = maxRounding;
2779+
27412780
inGeo.setMaterial(fillColor, strokeColor, strokeWeight,
27422781
ambientColor, specularColor, emissiveColor, shininess);
27432782
inGeo.setNormal(normalX, normalY, normalZ);
27442783
if (rounded) {
2745-
inGeo.addRect(a, b, c, d,
2746-
tl, tr, br, bl,
2747-
fill, stroke, bezierDetail, CORNER);
2784+
inGeo.addRect(a, b, c, d, tl, tr, br, bl,
2785+
fill, stroke, bezierDetail);
27482786
tessellator.tessellatePolygon(false, true, true);
27492787
} else {
2750-
inGeo.addRect(a, b, c, d,
2751-
fill, stroke, CORNER);
2788+
inGeo.addRect(a, b, c, d, fill, stroke);
27522789
tessellator.tessellateQuads();
27532790
}
27542791
}

0 commit comments

Comments
 (0)