diff --git a/src/Math.php b/src/Math.php index ede6bdb..399bea2 100644 --- a/src/Math.php +++ b/src/Math.php @@ -58,7 +58,7 @@ public static function solveQuadratic(float $a, float $b, float $c) : array{ if($a === 0.0){ throw new \InvalidArgumentException("Coefficient a cannot be 0!"); } - $discriminant = $b ** 2 - 4 * $a * $c; + $discriminant = $b * $b - 4 * $a * $c; if($discriminant > 0){ //2 real roots $sqrtDiscriminant = sqrt($discriminant); return [ diff --git a/src/Vector2.php b/src/Vector2.php index e6a8077..cc75185 100644 --- a/src/Vector2.php +++ b/src/Vector2.php @@ -96,7 +96,9 @@ public function distance(Vector2 $pos) : float{ } public function distanceSquared(Vector2 $pos) : float{ - return (($this->x - $pos->x) ** 2) + (($this->y - $pos->y) ** 2); + $dx = $this->x - $pos->x; + $dy = $this->y - $pos->y; + return ($dx * $dx) + ($dy * $dy); } public function length() : float{ diff --git a/src/Vector3.php b/src/Vector3.php index ca8701d..ea0d140 100644 --- a/src/Vector3.php +++ b/src/Vector3.php @@ -216,7 +216,10 @@ public function distance(Vector3 $pos) : float{ } public function distanceSquared(Vector3 $pos) : float{ - return (($this->x - $pos->x) ** 2) + (($this->y - $pos->y) ** 2) + (($this->z - $pos->z) ** 2); + $dx = $this->x - $pos->x; + $dy = $this->y - $pos->y; + $dz = $this->z - $pos->z; + return ($dx * $dx) + ($dy * $dy) + ($dz * $dz); } public function maxPlainDistance(Vector3|Vector2|float $x, float $z = 0) : float{