Skip to content

Commit

Permalink
Fixed regression (check first length out of somethingTo) + clip quads…
Browse files Browse the repository at this point in the history
… (Dasher)
  • Loading branch information
bourgesl committed Jan 18, 2018
1 parent 96d22ce commit 62c522f
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 87 deletions.
63 changes: 43 additions & 20 deletions src/main/java/org/marlin/pisces/DDasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,8 @@ private void goTo_starting(final double[] pts, final int off, final int type) {
firstSegidx = segIdx + len;
}

private static final boolean TRACE = false;

@Override
public void lineTo(final double x1, final double y1) {
if (TRACE) {
System.out.println("lineTo P0(" + cx0 + ", " + cy0 + ") P1(" + x1 + ", " + y1 + ")");
}

final int outcode0 = this.cOutCode;

if (clipRect != null) {
Expand All @@ -353,29 +347,23 @@ public void lineTo(final double x1, final double y1) {
// Should clip
final int orCode = (outcode0 | outcode1);

if (TRACE) {
System.out.println("orCode: "+orCode);
}

if (orCode != 0) {
final int sideCode = outcode0 & outcode1;

if (TRACE) {
System.out.println("sideCode: "+sideCode);
}

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
// subdivide curve => call lineTo() with subdivided curves:
curveSplitter.splitLine(cx0, cy0, x1, y1,
orCode, this);
// subdivide curve => callback with subdivided parts:
boolean ret = curveSplitter.splitLine(cx0, cy0, x1, y1,
orCode, this);
// reentrance is done:
subdivide = true;
return;
if (ret) {
return;
}
}
// already subdivided so render it
} else {
Expand Down Expand Up @@ -847,7 +835,7 @@ public void curveTo(final double x1, final double y1,
subdivide = false;
// subdivide curve => callback with subdivided parts:
boolean ret = curveSplitter.splitCurve(cx0, cy0, x1, y1, x2, y2, x3, y3,
orCode, this);
orCode, this);
// reentrance is done:
subdivide = true;
if (ret) {
Expand Down Expand Up @@ -894,13 +882,48 @@ private void _curveTo(final double x1, final double y1,
public void quadTo(final double x1, final double y1,
final double x2, final double y2)
{
final int outcode0 = this.cOutCode;

if (clipRect != null) {
final int outcode1 = DHelpers.outcode(x1, y1, clipRect);
final int outcode2 = DHelpers.outcode(x2, y2, clipRect);
// TODO

// Should clip
final int orCode = (outcode0 | outcode1 | outcode2);
if (orCode != 0) {
final int sideCode = outcode0 & outcode1 & outcode2;

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
// subdivide curve => call lineTo() with subdivided curves:
boolean ret = curveSplitter.splitQuad(cx0, cy0, x1, y1,
x2, y2, orCode, this);
// reentrance is done:
subdivide = true;
if (ret) {
return;
}
}
// already subdivided so render it
} else {
this.cOutCode = outcode2;
_moveTo(x2, y2);
return;
}
}

this.cOutCode = outcode2;
}
_quadTo(x1, y1, x2, y2);
}

private void _quadTo(final double x1, final double y1,
final double x2, final double y2)
{
final double[] _curCurvepts = curCurvepts;

// monotonize quad:
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/marlin/pisces/DHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ static int findSubdivPoints(final DCurve c, final double[] pts,
return ret;
}

private static double PADDING = 0.5d;

// finds values of t where the curve in pts should be subdivided in order
// to get intersections with the given clip rectangle.
// Stores the points in ts, and returns how many of them there were.
Expand All @@ -270,16 +268,16 @@ static int findClipPoints(final DCurve curve, final double[] pts,
int ret = 0;

if ((outCodeOR & OUTCODE_LEFT) != 0) {
ret += curve.xPoints(ts, ret, clipRect[2] - PADDING);
ret += curve.xPoints(ts, ret, clipRect[2]);
}
if ((outCodeOR & OUTCODE_TOP) != 0) {
ret += curve.yPoints(ts, ret, clipRect[0] - PADDING);
ret += curve.yPoints(ts, ret, clipRect[0]);
}
if ((outCodeOR & OUTCODE_BOTTOM) != 0) {
ret += curve.yPoints(ts, ret, clipRect[1] + PADDING);
ret += curve.yPoints(ts, ret, clipRect[1]);
}
if ((outCodeOR & OUTCODE_RIGHT) != 0) {
ret += curve.xPoints(ts, ret, clipRect[3] + PADDING);
ret += curve.xPoints(ts, ret, clipRect[3]);
}

isort(ts, ret);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/marlin/pisces/DMarlinRenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,10 @@ private static void logSettings(final String reClass) {
+ MarlinProperties.getQuadDecD2());

logInfo("Renderer settings:");

logInfo("MAX_LEN (CurveClipSplitter) = "
+ DTransformingPathConsumer2D.CurveClipSplitter.MAX_LEN); // TODO: use system property

logInfo("CUB_DEC_BND = " + DRenderer.CUB_DEC_BND);
logInfo("CUB_INC_BND = " + DRenderer.CUB_INC_BND);
logInfo("QUAD_DEC_BND = " + DRenderer.QUAD_DEC_BND);
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/marlin/pisces/DStroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ DStroker init(final DPathConsumer2D pc2d,
rdrOffX = scale * DRenderer.RDR_OFFSET_X;
rdrOffY = scale * DRenderer.RDR_OFFSET_Y;
}
// add a small rounding error:
margin += 1e-3d;
// add a rounding error (curve subdivision ~ 0.1px):
margin += DTransformingPathConsumer2D.CLIP_RECT_PADDING;

// bounds as half-open intervals: minX <= x < maxX and minY <= y < maxY
// adjust clip rectangle (ymin, ymax, xmin, xmax):
Expand Down Expand Up @@ -549,11 +549,13 @@ private void lineTo(final double x1, final double y1,
// avoid reentrance
subdivide = false;
// subdivide curve => callback with subdivided parts:
curveSplitter.splitLine(cx0, cy0, x1, y1,
orCode, this);
boolean ret = curveSplitter.splitLine(cx0, cy0, x1, y1,
orCode, this);
// reentrance is done:
subdivide = true;
return;
if (ret) {
return;
}
}
// already subdivided so render it
} else {
Expand Down Expand Up @@ -1070,8 +1072,9 @@ public void curveTo(final double x1, final double y1,
// avoid reentrance
subdivide = false;
// subdivide curve => callback with subdivided parts:
boolean ret = curveSplitter.splitCurve(cx0, cy0, x1, y1, x2, y2, x3, y3,
orCode, this);
boolean ret = curveSplitter.splitCurve(cx0, cy0, x1, y1,
x2, y2, x3, y3,
orCode, this);
// reentrance is done:
subdivide = true;
if (ret) {
Expand Down Expand Up @@ -1217,11 +1220,13 @@ public void quadTo(final double x1, final double y1,
// avoid reentrance
subdivide = false;
// subdivide curve => call lineTo() with subdivided curves:
curveSplitter.splitQuad(cx0, cy0, x1, y1, x2, y2,
orCode, this);
boolean ret = curveSplitter.splitQuad(cx0, cy0, x1, y1,
x2, y2, orCode, this);
// reentrance is done:
subdivide = true;
return;
if (ret) {
return;
}
}
// already subdivided so render it
} else {
Expand Down
Loading

0 comments on commit 62c522f

Please sign in to comment.