Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgesl committed Sep 3, 2018
1 parent 92ca53e commit 327771c
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 93 deletions.
19 changes: 15 additions & 4 deletions src/main/java/org/marlin/pisces/DMarlinRenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,21 @@ public AATileGenerator getAATileGenerator(Shape s,
// Define the initial clip bounds:
final double[] clipRect = rdrCtx.clipRect;

clipRect[0] = clip.getLoY();
clipRect[1] = clip.getLoY() + clip.getHeight();
clipRect[2] = clip.getLoX();
clipRect[3] = clip.getLoX() + clip.getWidth();
// Adjust the clipping rectangle with the renderer offsets
final double rdrOffX = DRenderer.RDR_OFFSET_X;
final double rdrOffY = DRenderer.RDR_OFFSET_Y;

// add a small rounding error:
final double margin = 1e-3d;

clipRect[0] = clip.getLoY()
- margin + rdrOffY;
clipRect[1] = clip.getLoY() + clip.getHeight()
+ margin + rdrOffY;
clipRect[2] = clip.getLoX()
- margin + rdrOffX;
clipRect[3] = clip.getLoX() + clip.getWidth()
+ margin + rdrOffX;

if (MarlinConst.DO_LOG_CLIP) {
MarlinUtils.logInfo("clipRect (clip): "
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/marlin/pisces/DRendererContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ static DRendererContext createContext() {
boolean closedPath = false;
// clip rectangle (ymin, ymax, xmin, xmax):
final double[] clipRect = new double[4];
// clip inverse scale (mean) to adjust length checks
double clipInvScale = 0.0d;
// CurveBasicMonotonizer instance
final CurveBasicMonotonizer monotonizer;
// CurveClipSplitter instance
Expand Down Expand Up @@ -162,6 +164,7 @@ void dispose() {
stroking = 0;
doClip = false;
closedPath = false;
clipInvScale = 0.0d;

// if context is maked as DIRTY:
if (dirty) {
Expand Down
81 changes: 40 additions & 41 deletions src/main/java/org/marlin/pisces/DTransformingPathConsumer2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ DPathConsumer2D pathClipper(DPathConsumer2D out) {
DPathConsumer2D deltaTransformConsumer(DPathConsumer2D out,
AffineTransform at)
{
if (rdrCtx.doClip) {
adjustClipOffset(rdrCtx.clipRect);
}

if (at == null) {
return out;
}
Expand All @@ -123,48 +119,38 @@ DPathConsumer2D deltaTransformConsumer(DPathConsumer2D out,
// Scale only
if (rdrCtx.doClip) {
// adjust clip rectangle (ymin, ymax, xmin, xmax):
adjustClipScale(rdrCtx.clipRect, mxx, myy);
rdrCtx.clipInvScale = adjustClipScale(rdrCtx.clipRect,
mxx, myy);
}
return dt_DeltaScaleFilter.init(out, mxx, myy);
}
} else {
if (rdrCtx.doClip) {
// adjust clip rectangle (ymin, ymax, xmin, xmax):
adjustClipInverseDelta(rdrCtx.clipRect, mxx, mxy, myx, myy);
rdrCtx.clipInvScale = adjustClipInverseDelta(rdrCtx.clipRect,
mxx, mxy, myx, myy);
}
return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
}
}

private static void adjustClipOffset(final double[] clipRect) {
// Adjust the clipping rectangle with the renderer offsets
final double rdrOffX = DRenderer.RDR_OFFSET_X;
final double rdrOffY = DRenderer.RDR_OFFSET_Y;

// add a small rounding error:
final double margin = 1e-3d;

clipRect[0] -= margin - rdrOffY;
clipRect[1] += margin + rdrOffY;
clipRect[2] -= margin - rdrOffX;
clipRect[3] += margin + rdrOffX;
}

private static void adjustClipScale(final double[] clipRect,
final double mxx, final double myy)
private static double adjustClipScale(final double[] clipRect,
final double mxx, final double myy)
{
// Adjust the clipping rectangle (iv_DeltaScaleFilter):
clipRect[0] /= myy;
clipRect[1] /= myy;
final double scaleY = 1.0d / myy;
clipRect[0] *= scaleY;
clipRect[1] *= scaleY;

if (clipRect[1] < clipRect[0]) {
double tmp = clipRect[0];
clipRect[0] = clipRect[1];
clipRect[1] = tmp;
}

clipRect[2] /= mxx;
clipRect[3] /= mxx;
final double scaleX = 1.0d / mxx;
clipRect[2] *= scaleX;
clipRect[3] *= scaleX;

if (clipRect[3] < clipRect[2]) {
double tmp = clipRect[2];
Expand All @@ -176,11 +162,12 @@ private static void adjustClipScale(final double[] clipRect,
MarlinUtils.logInfo("clipRect (ClipScale): "
+ Arrays.toString(clipRect));
}
return 0.5d * (Math.abs(scaleX) + Math.abs(scaleY));
}

private static void adjustClipInverseDelta(final double[] clipRect,
final double mxx, final double mxy,
final double myx, final double myy)
private static double adjustClipInverseDelta(final double[] clipRect,
final double mxx, final double mxy,
final double myx, final double myy)
{
// Adjust the clipping rectangle (iv_DeltaTransformFilter):
final double det = mxx * myy - mxy * myx;
Expand Down Expand Up @@ -228,6 +215,11 @@ private static void adjustClipInverseDelta(final double[] clipRect,
MarlinUtils.logInfo("clipRect (ClipInverseDelta): "
+ Arrays.toString(clipRect));
}

final double scaleX = Math.sqrt(imxx * imxx + imxy * imxy);
final double scaleY = Math.sqrt(imyx * imyx + imyy * imyy);

return 0.5d * (scaleX + scaleY);
}

DPathConsumer2D inverseDeltaTransformConsumer(DPathConsumer2D out,
Expand All @@ -245,7 +237,7 @@ DPathConsumer2D inverseDeltaTransformConsumer(DPathConsumer2D out,
if (mxx == 1.0d && myy == 1.0d) {
return out;
} else {
return iv_DeltaScaleFilter.init(out, 1.0d/mxx, 1.0d/myy);
return iv_DeltaScaleFilter.init(out, 1.0d / mxx, 1.0d / myy);
}
} else {
final double det = mxx * myy - mxy * myx;
Expand Down Expand Up @@ -562,13 +554,6 @@ static final class PathClipFilter implements DPathConsumer2D {
PathClipFilter init(final DPathConsumer2D out) {
this.out = out;

adjustClipOffset(this.clipRect);

if (MarlinConst.DO_LOG_CLIP) {
MarlinUtils.logInfo("clipRect (PathClipFilter): "
+ Arrays.toString(clipRect));
}

if (MarlinConst.DO_CLIP_SUBDIVIDER) {
// adjust padded clip rectangle:
curveSplitter.init();
Expand Down Expand Up @@ -891,6 +876,11 @@ static final class CurveClipSplitter {

private static final int MAX_N_CURVES = 3 * 4;

private final DRendererContext rdrCtx;

// scaled length threshold:
private double minLength;

// clip rectangle (ymin, ymax, xmin, xmax):
final double[] clipRect;

Expand All @@ -908,14 +898,23 @@ static final class CurveClipSplitter {
private final DCurve curve;

CurveClipSplitter(final DRendererContext rdrCtx) {
this.rdrCtx = rdrCtx;
this.clipRect = rdrCtx.clipRect;
this.curve = rdrCtx.curve;
}

void init() {
this.init_clipRectPad = true;

// TODO: adjust LEN_TH by rough scale ?
if (DO_CHECK_LENGTH) {
this.minLength = (this.rdrCtx.clipInvScale == 0.0d) ? LEN_TH
: (LEN_TH * this.rdrCtx.clipInvScale);

if (MarlinConst.DO_LOG_CLIP) {
MarlinUtils.logInfo("CurveClipSplitter.minLength = "
+ minLength);
}
}
}

private void initPaddedClip() {
Expand Down Expand Up @@ -945,7 +944,7 @@ boolean splitLine(final double x0, final double y0,
MarlinUtils.logInfo("divLine P0(" + x0 + ", " + y0 + ") P1(" + x1 + ", " + y1 + ")");
}

if (DO_CHECK_LENGTH && DHelpers.fastLineLen(x0, y0, x1, y1) <= LEN_TH) {
if (DO_CHECK_LENGTH && DHelpers.fastLineLen(x0, y0, x1, y1) <= minLength) {
return false;
}

Expand All @@ -966,7 +965,7 @@ boolean splitQuad(final double x0, final double y0,
MarlinUtils.logInfo("divQuad P0(" + x0 + ", " + y0 + ") P1(" + x1 + ", " + y1 + ") P2(" + x2 + ", " + y2 + ")");
}

if (DO_CHECK_LENGTH && DHelpers.fastQuadLen(x0, y0, x1, y1, x2, y2) <= LEN_TH) {
if (DO_CHECK_LENGTH && DHelpers.fastQuadLen(x0, y0, x1, y1, x2, y2) <= minLength) {
return false;
}

Expand All @@ -989,7 +988,7 @@ boolean splitCurve(final double x0, final double y0,
MarlinUtils.logInfo("divCurve P0(" + x0 + ", " + y0 + ") P1(" + x1 + ", " + y1 + ") P2(" + x2 + ", " + y2 + ") P3(" + x3 + ", " + y3 + ")");
}

if (DO_CHECK_LENGTH && DHelpers.fastCurvelen(x0, y0, x1, y1, x2, y2, x3, y3) <= LEN_TH) {
if (DO_CHECK_LENGTH && DHelpers.fastCurvelen(x0, y0, x1, y1, x2, y2, x3, y3) <= minLength) {
return false;
}

Expand Down
19 changes: 15 additions & 4 deletions src/main/java/org/marlin/pisces/MarlinRenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,21 @@ public AATileGenerator getAATileGenerator(Shape s,
// Define the initial clip bounds:
final float[] clipRect = rdrCtx.clipRect;

clipRect[0] = clip.getLoY();
clipRect[1] = clip.getLoY() + clip.getHeight();
clipRect[2] = clip.getLoX();
clipRect[3] = clip.getLoX() + clip.getWidth();
// Adjust the clipping rectangle with the renderer offsets
final float rdrOffX = Renderer.RDR_OFFSET_X;
final float rdrOffY = Renderer.RDR_OFFSET_Y;

// add a small rounding error:
final float margin = 1e-3f;

clipRect[0] = clip.getLoY()
- margin + rdrOffY;
clipRect[1] = clip.getLoY() + clip.getHeight()
+ margin + rdrOffY;
clipRect[2] = clip.getLoX()
- margin + rdrOffX;
clipRect[3] = clip.getLoX() + clip.getWidth()
+ margin + rdrOffX;

if (MarlinConst.DO_LOG_CLIP) {
MarlinUtils.logInfo("clipRect (clip): "
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/marlin/pisces/RendererContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ static RendererContext createContext() {
boolean closedPath = false;
// clip rectangle (ymin, ymax, xmin, xmax):
final float[] clipRect = new float[4];
// clip inverse scale (mean) to adjust length checks
float clipInvScale = 0.0f;
// CurveBasicMonotonizer instance
final CurveBasicMonotonizer monotonizer;
// CurveClipSplitter instance
Expand Down Expand Up @@ -159,6 +161,7 @@ void dispose() {
stroking = 0;
doClip = false;
closedPath = false;
clipInvScale = 0.0f;

// if context is maked as DIRTY:
if (dirty) {
Expand Down
Loading

0 comments on commit 327771c

Please sign in to comment.