Skip to content

Commit 5c20893

Browse files
committed
fix jaggies on polygonal gradients (#17)
1 parent 9f5cfb1 commit 5c20893

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main/micycle/peasygradients/PeasyGradients.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,9 @@ public void polygonGradient(Gradient gradient, PVector centerPoint, double angle
558558

559559
angle %= SEGMENT_ANGLE; // mod angle to minimise difference between theta and SEGMENT_ANGLE in loop
560560

561-
final double denominator = MIN_LENGTH_RATIO / ((Math.max(renderHeight, renderWidth)) * (0.01 * zoom * FastPow.fastPow(sides, 2.4)));
561+
final double denominator = MIN_LENGTH_RATIO / ((Math.max(renderHeight, renderWidth)) * (0.01 * zoom * FastMath.pow(sides, 2.4)));
562562

563-
final int LUT_SIZE = (int) Functions.min(2000, renderWidth * 10f, renderHeight * 10f); // suitable value?
563+
int LUT_SIZE = (int) Functions.max(2000, renderWidth * 20f, renderHeight * 20f); // suitable value?
564564
final int HALF_LUT_SIZE = (int) (LUT_SIZE / TWO_PI);
565565
final double[] ratioLookup = new double[(LUT_SIZE) + 1]; // LUT
566566

@@ -574,7 +574,7 @@ public void polygonGradient(Gradient gradient, PVector centerPoint, double angle
574574
theta *= Math.PI;
575575
theta -= angle;
576576
theta = (Math.abs(theta) % SEGMENT_ANGLE);
577-
ratioLookup[i] = ((MIN_LENGTH_RATIO * FastMath.cosQuick(theta) + FastMath.sinQuick(theta)) * denominator);
577+
ratioLookup[i] = ((MIN_LENGTH_RATIO * FastMath.cos(theta) + FastMath.sin(theta)) * denominator);
578578
}
579579

580580
makeThreadPool(gradient, renderStrips, PolygonThread.class, renderMidpointX, renderMidpointY, ratioLookup, HALF_LUT_SIZE);
@@ -1169,8 +1169,7 @@ public Boolean call() {
11691169
final double pointDistance = Math.sqrt(yDist * yDist + xDist * xDist); // euclidean dist between (x,y) and midpoint
11701170
xDist--;
11711171

1172-
final double theta = Functions.fastAtan2b((renderMidpointY - y), (renderMidpointX - x)); // range = -PI...PI
1173-
1172+
double theta = FastMath.atan2((renderMidpointY - y), (renderMidpointX - x)); // range = -PI...PI
11741173
// Use LUT: +PI to make theta in range 0...2PI and array index positive
11751174
double polygonRatio = ratioLookup[(int) ((theta + Math.PI) * HALF_LUT_SIZE)]; // use LUT
11761175

0 commit comments

Comments
 (0)