yet another micro opt

This commit is contained in:
Zoë Gidiere committed 2023-10-07 22:11:28 -06:00
1 parent 6fd72b8f06
commit f384d09376
1 file changed
+3 -3
@@ -317,20 +317,20 @@ public class PseudoErosionSampler implements NoiseSampler {
double ldx = x1 - x2; double ldx = x1 - x2;
double ldy = y1 - y2; double ldy = y1 - y2;
double lineLengthSquared = Math.pow(ldx, 2) + Math.pow(ldy, 2); double invLineLengthSquared = 1 / (Math.pow(ldx, 2) + Math.pow(ldy, 2));
double x2dx = x - x2; double x2dx = x - x2;
double y2dx = y - y2; double y2dx = y - y2;
double dotProduct = Math.fma(ldy, y1dx, (ldx * x1dx)); double dotProduct = Math.fma(ldy, y1dx, (ldx * x1dx));
double lt = dotProduct / lineLengthSquared; // Position along the line double lt = dotProduct * invLineLengthSquared; // Position along the line
if (lt > 0) { if (lt > 0) {
return MathUtil.hypot(x1dx, y1dx); // Distance between point 1 and position return MathUtil.hypot(x1dx, y1dx); // Distance between point 1 and position
} else if (lt < -1) { } else if (lt < -1) {
return MathUtil.hypot(x2dx, y2dx); // Distance between point 2 and position return MathUtil.hypot(x2dx, y2dx); // Distance between point 2 and position
} else { } else {
double distance = Math.fma(ldy, x1dx, (-(ldx * y1dx))) / Math.sqrt(lineLengthSquared); double distance = Math.fma(ldy, x1dx, (-(ldx * y1dx))) * Math.sqrt(invLineLengthSquared);
return Math.abs(distance); // Distance from the line return Math.abs(distance); // Distance from the line
} }
} }