mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
Use .lengthSqr() for compare operations (#4827)
- Optimisations to some of Create's vector math shortcuts
This commit is contained in:
parent
440d7e0e39
commit
2bcc12b096
1 changed files with 3 additions and 3 deletions
|
@ -187,7 +187,7 @@ public class VecHelper {
|
|||
}
|
||||
|
||||
public static Vec3 clamp(Vec3 vec, float maxLength) {
|
||||
return vec.length() > maxLength ? vec.normalize()
|
||||
return vec.lengthSqr() > maxLength * maxLength ? vec.normalize()
|
||||
.scale(maxLength) : vec;
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class VecHelper {
|
|||
public static Vec3 intersectSphere(Vec3 origin, Vec3 lineDirection, Vec3 sphereCenter, double radius) {
|
||||
if (lineDirection.equals(Vec3.ZERO))
|
||||
return null;
|
||||
if (lineDirection.length() != 1)
|
||||
if (lineDirection.lengthSqr() != 1)
|
||||
lineDirection = lineDirection.normalize();
|
||||
|
||||
Vec3 diff = origin.subtract(sphereCenter);
|
||||
|
@ -319,7 +319,7 @@ public class VecHelper {
|
|||
return null;
|
||||
if (intersect[0] < 0 || intersect[1] < 0)
|
||||
return null;
|
||||
if (intersect[0] > pDiff.length() || intersect[1] > qDiff.length())
|
||||
if (intersect[0] * intersect[0] > pDiff.lengthSqr() || intersect[1] * intersect[1] > qDiff.lengthSqr())
|
||||
return null;
|
||||
return intersect;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue