add a check to Vec3#unit to avoid unnecessary sqrt and division
This commit is contained in:
parent
9e79333e1e
commit
6599c41b14
@ -270,7 +270,9 @@ public record Vec3(double x, double y, double z) {
|
|||||||
* {@return a unit vector with the same direction as this vector}
|
* {@return a unit vector with the same direction as this vector}
|
||||||
*/
|
*/
|
||||||
public @NotNull Vec3 unit() {
|
public @NotNull Vec3 unit() {
|
||||||
return div(length());
|
var squared = squared();
|
||||||
|
if (squared == 1) return this;
|
||||||
|
return div(Math.sqrt(squared));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user