mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 21:40:08 +00:00
yet another micro opt
This commit is contained in:
1 parent
6fd72b8f06
commit
f384d09376
1 file changed
+3
-3
+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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user