diff --git a/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java b/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java index 7641756..7213c96 100644 --- a/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java +++ b/src/main/java/eu/jonahbauer/raytracing/math/Vec3.java @@ -270,7 +270,9 @@ public record Vec3(double x, double y, double z) { * {@return a unit vector with the same direction as this vector} */ public @NotNull Vec3 unit() { - return div(length()); + var squared = squared(); + if (squared == 1) return this; + return div(Math.sqrt(squared)); } /**