Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from bourgesl/master
Browse files Browse the repository at this point in the history
Marlin-renderer bug fix in the path clipper
  • Loading branch information
avu authored Oct 27, 2019
2 parents 56104ef + 168d3c0 commit 33b1cbb
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 89 deletions.
49 changes: 24 additions & 25 deletions src/share/classes/sun/java2d/marlin/DDasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ final class DDasher implements DPathConsumer2D, MarlinConst {
static final double CURVE_LEN_ERR = MarlinProperties.getCurveLengthError(); // 0.01 initial
static final double MIN_T_INC = 1.0d / (1 << REC_LIMIT);

static final double EPS = 1e-6d;

// More than 24 bits of mantissa means we can no longer accurately
// measure the number of times cycled through the dash array so we
// punt and override the phase to just be 0 past that point.
Expand Down Expand Up @@ -361,7 +363,7 @@ public void lineTo(final double x1, final double y1) {

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -416,13 +418,13 @@ private void _lineTo(final double x1, final double y1) {
boolean _dashOn = dashOn;
double _phase = phase;

double leftInThisDashSegment, d;
double leftInThisDashSegment, rem;

while (true) {
d = _dash[_idx];
leftInThisDashSegment = d - _phase;
leftInThisDashSegment = _dash[_idx] - _phase;
rem = len - leftInThisDashSegment;

if (len <= leftInThisDashSegment) {
if (rem <= EPS) {
_curCurvepts[0] = x1;
_curCurvepts[1] = y1;

Expand All @@ -431,26 +433,21 @@ private void _lineTo(final double x1, final double y1) {
// Advance phase within current dash segment
_phase += len;

// TODO: compare double values using epsilon:
if (len == leftInThisDashSegment) {
// compare values using epsilon:
if (Math.abs(rem) <= EPS) {
_phase = 0.0d;
_idx = (_idx + 1) % _dashLen;
_dashOn = !_dashOn;
}
break;
}

if (_phase == 0.0d) {
_curCurvepts[0] = cx0 + d * cx;
_curCurvepts[1] = cy0 + d * cy;
} else {
_curCurvepts[0] = cx0 + leftInThisDashSegment * cx;
_curCurvepts[1] = cy0 + leftInThisDashSegment * cy;
}
_curCurvepts[0] = cx0 + leftInThisDashSegment * cx;
_curCurvepts[1] = cy0 + leftInThisDashSegment * cy;

goTo(_curCurvepts, 0, 4, _dashOn);

len -= leftInThisDashSegment;
len = rem;
// Advance to next dash segment
_idx = (_idx + 1) % _dashLen;
_dashOn = !_dashOn;
Expand Down Expand Up @@ -506,26 +503,26 @@ public void skipLen() {
_dashOn = (iterations + (_dashOn ? 1L : 0L) & 1L) == 1L;
}

double leftInThisDashSegment, d;
double leftInThisDashSegment, rem;

while (true) {
d = _dash[_idx];
leftInThisDashSegment = d - _phase;
leftInThisDashSegment = _dash[_idx] - _phase;
rem = len - leftInThisDashSegment;

if (len <= leftInThisDashSegment) {
if (rem <= EPS) {
// Advance phase within current dash segment
_phase += len;

// TODO: compare double values using epsilon:
if (len == leftInThisDashSegment) {
// compare values using epsilon:
if (Math.abs(rem) <= EPS) {
_phase = 0.0d;
_idx = (_idx + 1) % _dashLen;
_dashOn = !_dashOn;
}
break;
}

len -= leftInThisDashSegment;
len = rem;
// Advance to next dash segment
_idx = (_idx + 1) % _dashLen;
_dashOn = !_dashOn;
Expand Down Expand Up @@ -579,7 +576,9 @@ private void somethingTo(final int type) {
goTo(_curCurvepts, curCurveoff + 2, type, _dashOn);

_phase += _li.lastSegLen();
if (_phase >= _dash[_idx]) {

// compare values using epsilon:
if (_phase + EPS >= _dash[_idx]) {
_phase = 0.0d;
_idx = (_idx + 1) % _dashLen;
_dashOn = !_dashOn;
Expand Down Expand Up @@ -938,7 +937,7 @@ public void curveTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -1024,7 +1023,7 @@ public void quadTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down
2 changes: 1 addition & 1 deletion src/share/classes/sun/java2d/marlin/DHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static int findSubdivPoints(final DCurve c, final double[] pts,
final double y12 = pts[3] - pts[1];
// if the curve is already parallel to either axis we gain nothing
// from rotating it.
if ((y12 != 0.0d && x12 != 0.0d)) {
if ((y12 != 0.0d) && (x12 != 0.0d)) {
// we rotate it so that the first vector in the control polygon is
// parallel to the x-axis. This will ensure that rotated quarter
// circles won't be subdivided.
Expand Down
15 changes: 9 additions & 6 deletions src/share/classes/sun/java2d/marlin/DStroker.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ private void lineTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -634,6 +634,9 @@ public void closePath() {
emitReverse();

this.prev = CLOSE;
this.cx0 = sx0;
this.cy0 = sy0;
this.cOutCode = sOutCode;

if (opened) {
// do not emit close
Expand Down Expand Up @@ -668,7 +671,9 @@ private void finish(final int outcode) {
// i.e. if caps must be drawn or not ?
// Solution: use the ClosedPathDetector before Stroker to determine
// if the path is a closed path or not
if (!rdrCtx.closedPath) {
if (rdrCtx.closedPath) {
emitReverse();
} else {
if (outcode == 0) {
// current point = end's cap:
if (capStyle == CAP_ROUND) {
Expand All @@ -693,8 +698,6 @@ private void finish(final int outcode) {
}
}
}
} else {
emitReverse();
}
emitClose();
}
Expand Down Expand Up @@ -1058,7 +1061,7 @@ public void curveTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -1206,7 +1209,7 @@ public void quadTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ static final class PathClipFilter implements DPathConsumer2D {

private boolean outside = false;

// The starting point of the path
private double sx0, sy0;

// The current point (TODO stupid repeated info)
private double cx0, cy0;

Expand Down Expand Up @@ -630,17 +633,26 @@ public void closePath() {
finishPath();

out.closePath();

// back to starting point:
this.cOutCode = DHelpers.outcode(sx0, sy0, clipRect);
this.cx0 = sx0;
this.cy0 = sy0;
}

@Override
public void moveTo(final double x0, final double y0) {
finishPath();

this.cOutCode = DHelpers.outcode(x0, y0, clipRect);
this.outside = false;
out.moveTo(x0, y0);

// update starting point:
this.cOutCode = DHelpers.outcode(x0, y0, clipRect);
this.cx0 = x0;
this.cy0 = y0;

this.sx0 = x0;
this.sy0 = y0;
}

@Override
Expand All @@ -655,7 +667,7 @@ public void lineTo(final double xe, final double ye) {

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -754,7 +766,7 @@ public void curveTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -816,7 +828,7 @@ public void quadTo(final double x1, final double y1,

// basic rejection criteria:
if (sideCode == 0) {
// ovelap clip:
// overlap clip:
if (subdivide) {
// avoid reentrance
subdivide = false;
Expand Down Expand Up @@ -1153,13 +1165,13 @@ PathTracer init(DPathConsumer2D out) {

@Override
public void moveTo(double x0, double y0) {
log("moveTo (" + x0 + ", " + y0 + ')');
log("p.moveTo(" + x0 + ", " + y0 + ");");
out.moveTo(x0, y0);
}

@Override
public void lineTo(double x1, double y1) {
log("lineTo (" + x1 + ", " + y1 + ')');
log("p.lineTo(" + x1 + ", " + y1 + ");");
out.lineTo(x1, y1);
}

Expand All @@ -1168,25 +1180,26 @@ public void curveTo(double x1, double y1,
double x2, double y2,
double x3, double y3)
{
log("curveTo P1(" + x1 + ", " + y1 + ") P2(" + x2 + ", " + y2 + ") P3(" + x3 + ", " + y3 + ')');
log("p.curveTo(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ", " + x3 + ", " + y3 + ");");
out.curveTo(x1, y1, x2, y2, x3, y3);
}

@Override
public void quadTo(double x1, double y1, double x2, double y2) {
log("quadTo P1(" + x1 + ", " + y1 + ") P2(" + x2 + ", " + y2 + ')');
public void quadTo(double x1, double y1,
double x2, double y2) {
log("p.quadTo(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ");");
out.quadTo(x1, y1, x2, y2);
}

@Override
public void closePath() {
log("closePath");
log("p.closePath();");
out.closePath();
}

@Override
public void pathDone() {
log("pathDone");
log("p.pathDone();");
out.pathDone();
}

Expand Down
Loading

0 comments on commit 33b1cbb

Please sign in to comment.