mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 11:51:54 +01:00
Handling division-by-zero situation in LineStroker, added MIN_CAPS_JOINS_WEIGHT constant in PGL
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user