diff --git a/android/core/src/processing/opengl/PGL.java b/android/core/src/processing/opengl/PGL.java index 710a2b617..465e28bc4 100644 --- a/android/core/src/processing/opengl/PGL.java +++ b/android/core/src/processing/opengl/PGL.java @@ -100,7 +100,12 @@ public class PGL { /** Maximum dimension of a texture used to hold font data. **/ public static final int MAX_FONT_TEX_SIZE = 256; - + + /** Minimum stroke weight needed to apply the full path stroking + * algorithm that properly generates caps and joing. + */ + public static final float MIN_CAPS_JOINS_WEIGHT = 2.f; + /** Minimum array size to use arrayCopy method(). **/ static protected final int MIN_ARRAYCOPY_SIZE = 2; diff --git a/android/core/src/processing/opengl/geom/LineStroker.java b/android/core/src/processing/opengl/geom/LineStroker.java index 85d035e2b..883e192e1 100644 --- a/android/core/src/processing/opengl/geom/LineStroker.java +++ b/android/core/src/processing/opengl/geom/LineStroker.java @@ -653,13 +653,15 @@ public class LineStroker extends LineSink { long ldx = (long) (px0 - x0); long ldy = (long) (py0 - y0); long llen = lineLength(ldx, ldy); - long s = (long) lineWidth2 * 65536 / llen; + if (0 < llen) { + long s = (long) lineWidth2 * 65536 / llen; - int capx = x0 - (int) (ldx * s >> 16); - int capy = y0 - (int) (ldy * s >> 16); + int capx = x0 - (int) (ldx * s >> 16); + int capy = y0 - (int) (ldy * s >> 16); - emitLineTo(capx + omx, capy + omy); - emitLineTo(capx - omx, capy - omy); + emitLineTo(capx + omx, capy + omy); + emitLineTo(capx - omx, capy - omy); + } } for (int i = rindex - 2; i >= 0; i -= 2) { @@ -674,13 +676,15 @@ public class LineStroker extends LineSink { long ldx = (long) (sx1 - sx0); long ldy = (long) (sy1 - sy0); long llen = lineLength(ldx, ldy); - long s = (long) lineWidth2 * 65536 / llen; + if (0 < llen) { + long s = (long) lineWidth2 * 65536 / llen; - int capx = sx0 - (int) (ldx * s >> 16); - int capy = sy0 - (int) (ldy * s >> 16); + int capx = sx0 - (int) (ldx * s >> 16); + int capy = sy0 - (int) (ldy * s >> 16); - emitLineTo(capx - mx0, capy - my0); - emitLineTo(capx + mx0, capy + my0); + emitLineTo(capx - mx0, capy - my0); + emitLineTo(capx + mx0, capy + my0); + } } emitClose(); diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index 4aa1570be..47a38967b 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -111,6 +111,11 @@ public class PGL { /** Maximum dimension of a texture used to hold font data. **/ public static final int MAX_FONT_TEX_SIZE = 256; + /** Minimum stroke weight needed to apply the full path stroking + * algorithm that properly generates caps and joing. + */ + public static final float MIN_CAPS_JOINS_WEIGHT = 2.1f; + /** Minimum array size to use arrayCopy method(). **/ static protected final int MIN_ARRAYCOPY_SIZE = 2; diff --git a/java/libraries/opengl/src/processing/opengl/geom/LineStroker.java b/java/libraries/opengl/src/processing/opengl/geom/LineStroker.java index 85d035e2b..883e192e1 100644 --- a/java/libraries/opengl/src/processing/opengl/geom/LineStroker.java +++ b/java/libraries/opengl/src/processing/opengl/geom/LineStroker.java @@ -653,13 +653,15 @@ public class LineStroker extends LineSink { long ldx = (long) (px0 - x0); long ldy = (long) (py0 - y0); long llen = lineLength(ldx, ldy); - long s = (long) lineWidth2 * 65536 / llen; + if (0 < llen) { + long s = (long) lineWidth2 * 65536 / llen; - int capx = x0 - (int) (ldx * s >> 16); - int capy = y0 - (int) (ldy * s >> 16); + int capx = x0 - (int) (ldx * s >> 16); + int capy = y0 - (int) (ldy * s >> 16); - emitLineTo(capx + omx, capy + omy); - emitLineTo(capx - omx, capy - omy); + emitLineTo(capx + omx, capy + omy); + emitLineTo(capx - omx, capy - omy); + } } for (int i = rindex - 2; i >= 0; i -= 2) { @@ -674,13 +676,15 @@ public class LineStroker extends LineSink { long ldx = (long) (sx1 - sx0); long ldy = (long) (sy1 - sy0); long llen = lineLength(ldx, ldy); - long s = (long) lineWidth2 * 65536 / llen; + if (0 < llen) { + long s = (long) lineWidth2 * 65536 / llen; - int capx = sx0 - (int) (ldx * s >> 16); - int capy = sy0 - (int) (ldy * s >> 16); + int capx = sx0 - (int) (ldx * s >> 16); + int capy = sy0 - (int) (ldy * s >> 16); - emitLineTo(capx - mx0, capy - my0); - emitLineTo(capx + mx0, capy + my0); + emitLineTo(capx - mx0, capy - my0); + emitLineTo(capx + mx0, capy + my0); + } } emitClose();