Skip to content

Commit

Permalink
fix jaggies on polygonal gradients (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
micycle1 committed Dec 31, 2024
1 parent 9f5cfb1 commit 5c20893
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/main/micycle/peasygradients/PeasyGradients.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,9 @@ public void polygonGradient(Gradient gradient, PVector centerPoint, double angle

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

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

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

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

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

final double theta = Functions.fastAtan2b((renderMidpointY - y), (renderMidpointX - x)); // range = -PI...PI

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

Expand Down

0 comments on commit 5c20893

Please sign in to comment.