From 2bcc12b096cb88dc151c3ceaba45cbe836b18875 Mon Sep 17 00:00:00 2001 From: Timo van Veen <104511421+TimovVeen@users.noreply.github.com> Date: Mon, 3 Jul 2023 15:38:16 +0200 Subject: [PATCH] Use .lengthSqr() for compare operations (#4827) - Optimisations to some of Create's vector math shortcuts --- .../com/simibubi/create/foundation/utility/VecHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/VecHelper.java b/src/main/java/com/simibubi/create/foundation/utility/VecHelper.java index e92d79f31..188a8e07e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VecHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VecHelper.java @@ -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; }