From 5b6b789ab3f771a89a587c1d7c6d7e4d19f68894 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 29 Sep 2014 13:24:25 +0200 Subject: [PATCH] Improved exponentiation --- src/pocketmine/Player.php | 2 +- src/pocketmine/Server.php | 2 +- .../level/generator/noise/Generator.php | 2 +- .../level/generator/noise/Simplex.php | 42 +++++++++---------- src/pocketmine/level/generator/object/Ore.php | 6 +-- .../level/generator/object/SmallTree.php | 2 +- src/pocketmine/math/Vector3.php | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5e12d2747..8b592e9f2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -695,7 +695,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $generateQueue = new ReversePriorityQueue(); for($X = -$radius; $X <= $radius; ++$X){ for($Z = -$radius; $Z <= $radius; ++$Z){ - $distance = ($X * $X) + ($Z * $Z); + $distance = $X ** 2 + $Z ** 2; if($distance > $radiusSquared){ continue; } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index c0b866129..8eacc583f 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1122,7 +1122,7 @@ class Server{ for($X = -$radius; $X <= $radius; ++$X){ for($Z = -$radius; $Z <= $radius; ++$Z){ - $distance = ($X * $X) + ($Z * $Z); + $distance = $X ** 2 + $Z ** 2; if($distance > $radiusSquared){ continue; } diff --git a/src/pocketmine/level/generator/noise/Generator.php b/src/pocketmine/level/generator/noise/Generator.php index 53cb37eb5..47c848bc5 100644 --- a/src/pocketmine/level/generator/noise/Generator.php +++ b/src/pocketmine/level/generator/noise/Generator.php @@ -42,7 +42,7 @@ abstract class Generator{ } public static function fade($x){ - return $x * $x * $x * ($x * ($x * 6 - 15) + 10); + return $x ** 3 * ($x * ($x * 6 - 15) + 10); } public static function lerp($x, $y, $z){ diff --git a/src/pocketmine/level/generator/noise/Simplex.php b/src/pocketmine/level/generator/noise/Simplex.php index 72c01f8cd..08615bb89 100644 --- a/src/pocketmine/level/generator/noise/Simplex.php +++ b/src/pocketmine/level/generator/noise/Simplex.php @@ -191,36 +191,36 @@ class Simplex extends Perlin{ $gi3 = $this->perm[$ii + 1 + $this->perm[$jj + 1 + $this->perm[$kk + 1]]] % 12; // Calculate the contribution from the four corners - $t0 = 0.6 - $x0 * $x0 - $y0 * $y0 - $z0 * $z0; + $t0 = 0.6 - $x0 ** 2 - $y0 ** 2 - $z0 ** 2; if($t0 < 0){ $n0 = 0.0; }else{ - $t0 *= $t0; - $n0 = $t0 * $t0 * self::dot3D(self::$grad3[$gi0], $x0, $y0, $z0); + $t0 **= 2; + $n0 = $t0 ** 2 * self::dot3D(self::$grad3[$gi0], $x0, $y0, $z0); } - $t1 = 0.6 - $x1 * $x1 - $y1 * $y1 - $z1 * $z1; + $t1 = 0.6 - $x1 ** 2 - $y1 ** 2 - $z1 ** 2; if($t1 < 0){ $n1 = 0.0; }else{ - $t1 *= $t1; - $n1 = $t1 * $t1 * self::dot3D(self::$grad3[$gi1], $x1, $y1, $z1); + $t1 **= 2; + $n1 = $t1 ** 2 * self::dot3D(self::$grad3[$gi1], $x1, $y1, $z1); } - $t2 = 0.6 - $x2 * $x2 - $y2 * $y2 - $z2 * $z2; + $t2 = 0.6 - $x2 ** 2 - $y2 ** 2 - $z2 ** 2; if($t2 < 0){ $n2 = 0.0; }else{ - $t2 *= $t2; - $n2 = $t2 * $t2 * self::dot3D(self::$grad3[$gi2], $x2, $y2, $z2); + $t2 **= 2; + $n2 = $t2 ** 2 * self::dot3D(self::$grad3[$gi2], $x2, $y2, $z2); } - $t3 = 0.6 - $x3 * $x3 - $y3 * $y3 - $z3 * $z3; + $t3 = 0.6 - $x3 ** 2 - $y3 ** 2 - $z3 ** 2; if($t3 < 0){ $n3 = 0.0; }else{ - $t3 *= $t3; - $n3 = $t3 * $t3 * self::dot3D(self::$grad3[$gi3], $x3, $y3, $z3); + $t3 **= 2; + $n3 = $t3 ** 2 * self::dot3D(self::$grad3[$gi3], $x3, $y3, $z3); } // Add contributions from each corner to get the noise value. @@ -272,28 +272,28 @@ class Simplex extends Perlin{ $gi2 = $this->perm[$ii + 1 + $this->perm[$jj + 1]] % 12; // Calculate the contribution from the three corners - $t0 = 0.5 - $x0 * $x0 - $y0 * $y0; + $t0 = 0.5 - $x0 ** 2 - $y0 ** 2; if($t0 < 0){ $n0 = 0.0; }else{ - $t0 *= $t0; - $n0 = $t0 * $t0 * self::dot2D(self::$grad3[$gi0], $x0, $y0); // (x,y) of grad3 used for 2D gradient + $t0 **= 2; + $n0 = $t0 ** 2 * self::dot2D(self::$grad3[$gi0], $x0, $y0); // (x,y) of grad3 used for 2D gradient } - $t1 = 0.5 - $x1 * $x1 - $y1 * $y1; + $t1 = 0.5 - $x1 ** 2 - $y1 ** 2; if($t1 < 0){ $n1 = 0.0; }else{ - $t1 *= $t1; - $n1 = $t1 * $t1 * self::dot2D(self::$grad3[$gi1], $x1, $y1); + $t1 **= 2; + $n1 = $t1 ** 2 * self::dot2D(self::$grad3[$gi1], $x1, $y1); } - $t2 = 0.5 - $x2 * $x2 - $y2 * $y2; + $t2 = 0.5 - $x2 ** 2 - $y2 ** 2; if($t2 < 0){ $n2 = 0.0; }else{ - $t2 *= $t2; - $n2 = $t2 * $t2 * self::dot2D(self::$grad3[$gi2], $x2, $y2); + $t2 **= 2; + $n2 = $t2 ** 2 * self::dot2D(self::$grad3[$gi2], $x2, $y2); } // Add contributions from each corner to get the noise value. diff --git a/src/pocketmine/level/generator/object/Ore.php b/src/pocketmine/level/generator/object/Ore.php index 5fd611b9c..061f09a2d 100644 --- a/src/pocketmine/level/generator/object/Ore.php +++ b/src/pocketmine/level/generator/object/Ore.php @@ -67,17 +67,17 @@ class Ore{ for($x = $startX; $x <= $endX; ++$x){ $sizeX = ($x + 0.5 - $seedX) / $size; - $sizeX *= $sizeX; + $sizeX **= 2; if($sizeX < 1){ for($y = $startY; $y <= $endY; ++$y){ $sizeY = ($y + 0.5 - $seedY) / $size; - $sizeY *= $sizeY; + $sizeY **= 2; if($y > 0 and ($sizeX + $sizeY) < 1){ for($z = $startZ; $z <= $endZ; ++$z){ $sizeZ = ($z + 0.5 - $seedZ) / $size; - $sizeZ *= $sizeZ; + $sizeZ **= 2; if(($sizeX + $sizeY + $sizeZ) < 1 and $level->getBlockIdAt($x, $y, $z) === 1){ $level->setBlockIdAt($x, $y, $z, $this->type->material->getID()); diff --git a/src/pocketmine/level/generator/object/SmallTree.php b/src/pocketmine/level/generator/object/SmallTree.php index bf23da940..ee83efb63 100644 --- a/src/pocketmine/level/generator/object/SmallTree.php +++ b/src/pocketmine/level/generator/object/SmallTree.php @@ -79,7 +79,7 @@ class SmallTree extends Tree{ $bRadius = 3; for($xx = -$bRadius; $xx <= $bRadius; ++$xx){ for($zz = -$bRadius; $zz <= $bRadius; ++$zz){ - if(sqrt(($xx * $xx) + ($zz * $zz)) <= $radius){ + if(sqrt($xx ** 2 + $zz ** 2) <= $radius){ $level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES); $level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type); } diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index 1d8ce0a1e..f22924ab9 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -176,7 +176,7 @@ class Vector3{ } public function lengthSquared(){ - return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z; + return $this->x ** 2 + $this->y ** 2 + $this->z ** 2; } /**