From cda4b768a1641ed0239d44724d6009dc536c2a30 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Tue, 4 Nov 2014 02:35:13 +0100 Subject: [PATCH 1/5] Paths with contours now close in JAVA2D --- core/src/processing/core/PGraphicsJava2D.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 79c5e3016..a8e7c7984 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -66,6 +66,7 @@ public class PGraphicsJava2D extends PGraphics { Composite defaultComposite; GeneralPath gpath; + GeneralPath auxPath; /// break the shape at the next vertex (next vertex() call is a moveto()) boolean breakShape; @@ -597,6 +598,7 @@ public class PGraphicsJava2D extends PGraphics { // this way, just check to see if gpath is null, and if it isn't // then just use it to continue the shape. gpath = null; + auxPath = null; } @@ -752,13 +754,27 @@ public class PGraphicsJava2D extends PGraphics { @Override public void beginContour() { - breakShape = true; + // draw contours to auxiliary path so + // main path can be closed later + GeneralPath contourPath = auxPath; + auxPath = gpath; + gpath = contourPath; + + if (contourPath != null) { // first contour does not break + breakShape = true; + } } @Override public void endContour() { - // does nothing, just need the break in beginContour() + // close this contour + if (gpath != null) gpath.closePath(); + + // switch back to main path + GeneralPath contourPath = gpath; + gpath = auxPath; + auxPath = contourPath; } @@ -769,14 +785,15 @@ public class PGraphicsJava2D extends PGraphics { if (mode == CLOSE) { gpath.closePath(); } + if (auxPath != null) { + gpath.append(auxPath, false); + } drawShape(gpath); } } shape = 0; } - - ////////////////////////////////////////////////////////////// // CLIPPING From 2918509d9f7324ccd780181fb0f80de958ec2c02 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Tue, 4 Nov 2014 02:38:41 +0100 Subject: [PATCH 2/5] BeginContour on PShape without vertices won't crash --- core/src/processing/core/PShape.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/processing/core/PShape.java b/core/src/processing/core/PShape.java index bb8189708..9aae40799 100644 --- a/core/src/processing/core/PShape.java +++ b/core/src/processing/core/PShape.java @@ -618,7 +618,9 @@ public class PShape implements PConstants { protected void beginContourImpl() { - if (vertexCodes.length == vertexCodeCount) { + if (vertexCodes == null) { + vertexCodes = new int[10]; + } else if (vertexCodes.length == vertexCodeCount) { vertexCodes = PApplet.expand(vertexCodes); } vertexCodes[vertexCodeCount++] = BREAK; From 6e2c7f8e80db9e86e7641303eca17e1cdaba8c90 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Tue, 4 Nov 2014 02:45:51 +0100 Subject: [PATCH 3/5] Fixing winding: polygons are now solid --- core/src/processing/opengl/PGraphicsOpenGL.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 484dc8992..c88d0d51c 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2363,7 +2363,7 @@ public class PGraphicsOpenGL extends PGraphics { if (normalMode == NORMAL_MODE_AUTO) inGeo.calcQuadStripNormals(); tessellator.tessellateQuadStrip(); } else if (shape == POLYGON) { - tessellator.tessellatePolygon(false, mode == CLOSE, + tessellator.tessellatePolygon(true, mode == CLOSE, normalMode == NORMAL_MODE_AUTO); } } From afb79fc769e2e94c72f8d5749706cfc9192f2374 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Tue, 4 Nov 2014 09:29:13 +0100 Subject: [PATCH 4/5] Fixing winding: PShapeOpenGL is solid by default --- core/src/processing/opengl/PShapeOpenGL.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index a771ff053..d41f3132a 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -173,7 +173,7 @@ public class PShapeOpenGL extends PShape { protected boolean needBufferInit = false; // Flag to indicate if the shape can have holes or not. - protected boolean solid; + protected boolean solid = true; protected boolean breakShape = false; protected boolean shapeCreated = false; @@ -2995,7 +2995,7 @@ public class PShapeOpenGL extends PShape { if (rounded) { saveBezierVertexSettings(); inGeo.addRect(a, b, c, d, tl, tr, br, bl, stroke); - tessellator.tessellatePolygon(false, true, true); + tessellator.tessellatePolygon(true, true, true); restoreBezierVertexSettings(); } else { inGeo.addRect(a, b, c, d, stroke); @@ -3289,7 +3289,7 @@ public class PShapeOpenGL extends PShape { saveCurveVertexSettings(); tessellator.resetCurveVertexCount(); } - tessellator.tessellatePolygon(false, close, true); + tessellator.tessellatePolygon(true, close, true); if (bez || quad) restoreBezierVertexSettings(); if (curv) restoreCurveVertexSettings(); } From 4161e4c6e88f6ec3597eadc00d948fe6c0143100 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Tue, 4 Nov 2014 10:39:58 +0100 Subject: [PATCH 5/5] Java2D: better error checking for contours --- core/src/processing/core/PGraphicsJava2D.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index a8e7c7984..63e96fe07 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -66,8 +66,12 @@ public class PGraphicsJava2D extends PGraphics { Composite defaultComposite; GeneralPath gpath; + + // path for contours so gpath can be closed GeneralPath auxPath; + boolean openContour; + /// break the shape at the next vertex (next vertex() call is a moveto()) boolean breakShape; @@ -754,8 +758,12 @@ public class PGraphicsJava2D extends PGraphics { @Override public void beginContour() { - // draw contours to auxiliary path so - // main path can be closed later + if (openContour) { + PGraphics.showWarning("Already called beginContour()"); + return; + } + + // draw contours to auxiliary path so main path can be closed later GeneralPath contourPath = auxPath; auxPath = gpath; gpath = contourPath; @@ -763,11 +771,18 @@ public class PGraphicsJava2D extends PGraphics { if (contourPath != null) { // first contour does not break breakShape = true; } + + openContour = true; } @Override public void endContour() { + if (!openContour) { + PGraphics.showWarning("Need to call beginContour() first"); + return; + } + // close this contour if (gpath != null) gpath.closePath(); @@ -775,11 +790,17 @@ public class PGraphicsJava2D extends PGraphics { GeneralPath contourPath = gpath; gpath = auxPath; auxPath = contourPath; + + openContour = false; } @Override public void endShape(int mode) { + if (openContour) { // correct automagically, notify user + endContour(); + PGraphics.showWarning("Missing endContour() before endShape()"); + } if (gpath != null) { // make sure something has been drawn if (shape == POLYGON) { if (mode == CLOSE) {