public final class Stroker extends java.lang.Object implements PathConsumer2D
Modifier and Type | Class and Description |
---|---|
private static class |
Stroker.PolyStack |
Modifier and Type | Field and Description |
---|---|
private static Curve |
c
WORKAROUND **********************************
private void somethingTo(final int type) {
// need these so we can update the state at the end of this method
final float xf = middle[type-2], yf = middle[type-1];
float dxs = middle[2] - middle[0];
float dys = middle[3] - middle[1];
float dxf = middle[type - 2] - middle[type - 4];
float dyf = middle[type - 1] - middle[type - 3];
switch(type) {
case 6:
if ((dxs == 0f && dys == 0f) ||
(dxf == 0f && dyf == 0f)) {
dxs = dxf = middle[4] - middle[0];
dys = dyf = middle[5] - middle[1];
}
break;
case 8:
boolean p1eqp2 = (dxs == 0f && dys == 0f);
boolean p3eqp4 = (dxf == 0f && dyf == 0f);
if (p1eqp2) {
dxs = middle[4] - middle[0];
dys = middle[5] - middle[1];
if (dxs == 0f && dys == 0f) {
dxs = middle[6] - middle[0];
dys = middle[7] - middle[1];
}
}
if (p3eqp4) {
dxf = middle[6] - middle[2];
dyf = middle[7] - middle[3];
if (dxf == 0f && dyf == 0f) {
dxf = middle[6] - middle[0];
dyf = middle[7] - middle[1];
}
}
}
if (dxs == 0f && dys == 0f) {
// this happens iff the "curve" is just a point
lineTo(middle[0], middle[1]);
return;
}
// if these vectors are too small, normalize them, to avoid future
// precision problems.
|
static int |
CAP_BUTT
Constant value for end cap style.
|
static int |
CAP_ROUND
Constant value for end cap style.
|
static int |
CAP_SQUARE
Constant value for end cap style.
|
private int |
capStyle |
private float |
cdx |
private float |
cdy |
private static int |
CLOSE |
private float |
cmx |
private float |
cmy |
private float |
cx0 |
private float |
cy0 |
private static int |
DRAWING_OP_TO |
static int |
JOIN_BEVEL
Constant value for join style.
|
static int |
JOIN_MITER
Constant value for join style.
|
static int |
JOIN_ROUND
Constant value for join style.
|
private int |
joinStyle |
private float |
lineWidth2 |
private float[] |
lp |
private static int |
MAX_N_CURVES |
private float[] |
middle |
private float[] |
miter |
private float |
miterLimitSq |
private static int |
MOVE_TO |
private float[][] |
offset |
private PathConsumer2D |
out |
private int |
prev |
private Stroker.PolyStack |
reverse |
private static float |
ROUND_JOIN_THRESHOLD |
private float[] |
rp |
private float |
sdx |
private float |
sdy |
private float |
smx |
private float |
smy |
private float[] |
subdivTs |
private float |
sx0 |
private float |
sy0 |
Constructor and Description |
---|
Stroker(PathConsumer2D pc2d) |
Stroker(PathConsumer2D pc2d,
float lineWidth,
int capStyle,
int joinStyle,
float miterLimit)
Constructs a
Stroker . |
Modifier and Type | Method and Description |
---|---|
void |
closePath() |
private void |
computeMiter(float x0,
float y0,
float x1,
float y1,
float x0p,
float y0p,
float x1p,
float y1p,
float[] m,
int off) |
private static void |
computeOffset(float lx,
float ly,
float w,
float[] m) |
private int |
computeOffsetCubic(float[] pts,
int off,
float[] leftOff,
float[] rightOff) |
private int |
computeOffsetQuad(float[] pts,
int off,
float[] leftOff,
float[] rightOff) |
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3) |
private void |
drawBezApproxForArc(float cx,
float cy,
float omx,
float omy,
float mx,
float my,
boolean rev) |
private void |
drawJoin(float pdx,
float pdy,
float x0,
float y0,
float dx,
float dy,
float omx,
float omy,
float mx,
float my) |
private void |
drawMiter(float pdx,
float pdy,
float x0,
float y0,
float dx,
float dy,
float omx,
float omy,
float mx,
float my,
boolean rev) |
private void |
drawRoundCap(float cx,
float cy,
float mx,
float my) |
private void |
drawRoundJoin(float cx,
float cy,
float omx,
float omy,
float mx,
float my,
boolean rev) |
private void |
drawRoundJoin(float x,
float y,
float omx,
float omy,
float mx,
float my,
boolean rev,
float threshold) |
private void |
emitClose() |
private void |
emitCurveTo(float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
boolean rev) |
private void |
emitLineTo(float x1,
float y1) |
private void |
emitLineTo(float x1,
float y1,
boolean rev) |
private void |
emitMoveTo(float x0,
float y0) |
private void |
emitQuadTo(float x0,
float y0,
float x1,
float y1,
float x2,
float y2,
boolean rev) |
private void |
emitReverse() |
private static int |
findSubdivPoints(float[] pts,
float[] ts,
int type,
float w) |
private void |
finish() |
private void |
getLineOffsets(float x1,
float y1,
float x2,
float y2,
float[] left,
float[] right) |
private static boolean |
isCW(float dx1,
float dy1,
float dx2,
float dy2) |
void |
lineTo(float x1,
float y1) |
void |
moveTo(float x0,
float y0) |
void |
pathDone() |
void |
quadTo(float x1,
float y1,
float x2,
float y2) |
void |
reset(float lineWidth,
int capStyle,
int joinStyle,
float miterLimit) |
private void |
safecomputeMiter(float x0,
float y0,
float x1,
float y1,
float x0p,
float y0p,
float x1p,
float y1p,
float[] m,
int off) |
void |
setConsumer(PathConsumer2D pc2d) |
private static boolean |
within(float x1,
float y1,
float x2,
float y2,
float ERR) |
private static final int MOVE_TO
private static final int DRAWING_OP_TO
private static final int CLOSE
public static final int JOIN_MITER
public static final int JOIN_ROUND
public static final int JOIN_BEVEL
public static final int CAP_BUTT
public static final int CAP_ROUND
public static final int CAP_SQUARE
private PathConsumer2D out
private int capStyle
private int joinStyle
private float lineWidth2
private final float[][] offset
private final float[] miter
private float miterLimitSq
private int prev
private float sx0
private float sy0
private float sdx
private float sdy
private float cx0
private float cy0
private float cdx
private float cdy
private float smx
private float smy
private float cmx
private float cmy
private final Stroker.PolyStack reverse
private static final float ROUND_JOIN_THRESHOLD
private float[] middle
private float[] lp
private float[] rp
private static final int MAX_N_CURVES
private float[] subdivTs
private static Curve c
public Stroker(PathConsumer2D pc2d, float lineWidth, int capStyle, int joinStyle, float miterLimit)
Stroker
.pc2d
- an output PathConsumer2D
.lineWidth
- the desired line width in pixelscapStyle
- the desired end cap style, one of
CAP_BUTT
, CAP_ROUND
or
CAP_SQUARE
.joinStyle
- the desired line join style, one of
JOIN_MITER
, JOIN_ROUND
or
JOIN_BEVEL
.miterLimit
- the desired miter limitpublic Stroker(PathConsumer2D pc2d)
public void setConsumer(PathConsumer2D pc2d)
public void reset(float lineWidth, int capStyle, int joinStyle, float miterLimit)
private static void computeOffset(float lx, float ly, float w, float[] m)
private static boolean isCW(float dx1, float dy1, float dx2, float dy2)
private void drawRoundJoin(float x, float y, float omx, float omy, float mx, float my, boolean rev, float threshold)
private void drawRoundJoin(float cx, float cy, float omx, float omy, float mx, float my, boolean rev)
private void drawBezApproxForArc(float cx, float cy, float omx, float omy, float mx, float my, boolean rev)
private void drawRoundCap(float cx, float cy, float mx, float my)
private void computeMiter(float x0, float y0, float x1, float y1, float x0p, float y0p, float x1p, float y1p, float[] m, int off)
private void safecomputeMiter(float x0, float y0, float x1, float y1, float x0p, float y0p, float x1p, float y1p, float[] m, int off)
private void drawMiter(float pdx, float pdy, float x0, float y0, float dx, float dy, float omx, float omy, float mx, float my, boolean rev)
public void moveTo(float x0, float y0)
moveTo
in interface PathConsumer2D
public void lineTo(float x1, float y1)
lineTo
in interface PathConsumer2D
public void closePath()
closePath
in interface PathConsumer2D
private void emitReverse()
public void pathDone()
pathDone
in interface PathConsumer2D
private void finish()
private void emitMoveTo(float x0, float y0)
private void emitLineTo(float x1, float y1)
private void emitLineTo(float x1, float y1, boolean rev)
private void emitQuadTo(float x0, float y0, float x1, float y1, float x2, float y2, boolean rev)
private void emitCurveTo(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, boolean rev)
private void emitClose()
private void drawJoin(float pdx, float pdy, float x0, float y0, float dx, float dy, float omx, float omy, float mx, float my)
private static boolean within(float x1, float y1, float x2, float y2, float ERR)
private void getLineOffsets(float x1, float y1, float x2, float y2, float[] left, float[] right)
private int computeOffsetCubic(float[] pts, int off, float[] leftOff, float[] rightOff)
private int computeOffsetQuad(float[] pts, int off, float[] leftOff, float[] rightOff)
private static int findSubdivPoints(float[] pts, float[] ts, int type, float w)
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
curveTo
in interface PathConsumer2D
public void quadTo(float x1, float y1, float x2, float y2)
quadTo
in interface PathConsumer2D