From facd8fbb0656a9c7b862870ef9fe5a4a865ae25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20B=C3=A1thory?= Date: Mon, 22 Aug 2022 23:26:41 +0200 Subject: [PATCH] change pow() to ** --- src/Geometry/LineString.php | 25 ++++++++++---------- src/Geometry/Point.php | 5 ++-- tests/Benchmark/Geometry/LineStringBench.php | 8 +++---- tests/Benchmark/Geometry/PolygonBench.php | 6 +++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Geometry/LineString.php b/src/Geometry/LineString.php index 07e20587..5cced876 100644 --- a/src/Geometry/LineString.php +++ b/src/Geometry/LineString.php @@ -14,7 +14,6 @@ use function count; use function deg2rad; use function is_nan; -use function pow; use function sin; use function sqrt; use function tan; @@ -116,8 +115,8 @@ public function getCentroidAndLength(float &$length = 0.0): Point if ($previousPoint) { // Equivalent to $previousPoint->distance($point) but much faster $segmentLength = sqrt( - pow(($previousPoint->x() - $point->x()), 2) + - pow(($previousPoint->y() - $point->y()), 2) + ($previousPoint->x() - $point->x()) ** 2 + + ($previousPoint->y() - $point->y()) ** 2 ); $length += $segmentLength; $x += ($previousPoint->x() + $point->x()) / 2 * $segmentLength; @@ -150,8 +149,8 @@ public function length(): float foreach ($this->getComponents() as $point) { if ($previousPoint) { $length += sqrt( - pow(($previousPoint->x() - $point->x()), 2) + - pow(($previousPoint->y() - $point->y()), 2) + ($previousPoint->x() - $point->x()) ** 2 + + ($previousPoint->y() - $point->y()) ** 2 ); } $previousPoint = $point; @@ -167,9 +166,9 @@ public function length3D(): float foreach ($this->getComponents() as $point) { if ($previousPoint) { $length += sqrt( - pow(($previousPoint->x() - $point->x()), 2) + - pow(($previousPoint->y() - $point->y()), 2) + - pow(($previousPoint->z() - $point->z()), 2) + ($previousPoint->x() - $point->x()) ** 2 + + ($previousPoint->y() - $point->y()) ** 2 + + ($previousPoint->z() - $point->z()) ** 2 ); } $previousPoint = $point; @@ -203,16 +202,16 @@ public function greatCircleLength(float $radius = geoPHP::EARTH_WGS84_SEMI_MAJOR $radius * atan2( sqrt( - pow($cosLat2 * sin($deltaLon), 2) + - pow($cosLat1 * $sinLat2 - $sinLat1 * $cosLat2 * $cosDeltaLon, 2) + ($cosLat2 * sin($deltaLon)) ** 2 + + ($cosLat1 * $sinLat2 - $sinLat1 * $cosLat2 * $cosDeltaLon) ** 2 ), $sinLat1 * $sinLat2 + - $cosLat1 * $cosLat2 * $cosDeltaLon + $cosLat1 * $cosLat2 * $cosDeltaLon ); if ($points[$i]->is3D()) { $d = sqrt( - pow($d, 2) + - pow($points[$i + 1]->z() - $points[$i]->z(), 2) + $d ** 2 + + ($points[$i + 1]->z() - $points[$i]->z()) ** 2 ); } diff --git a/src/Geometry/Point.php b/src/Geometry/Point.php index 638ffd85..6e2466f8 100644 --- a/src/Geometry/Point.php +++ b/src/Geometry/Point.php @@ -9,7 +9,6 @@ use function gettype; use function is_finite; use function is_numeric; -use function pow; use function sqrt; /** @@ -328,8 +327,8 @@ public function distance(Geometry $geometry): ?float } if ($geometry->geometryType() == Geometry::POINT) { return sqrt( - pow(($this->x() - $geometry->x()), 2) - + pow(($this->y() - $geometry->y()), 2) + ($this->x() - $geometry->x()) ** 2 + + ($this->y() - $geometry->y()) ** 2 ); } if ($geometry instanceof MultiGeometry) { diff --git a/tests/Benchmark/Geometry/LineStringBench.php b/tests/Benchmark/Geometry/LineStringBench.php index 62a8e6fb..32bad171 100644 --- a/tests/Benchmark/Geometry/LineStringBench.php +++ b/tests/Benchmark/Geometry/LineStringBench.php @@ -16,7 +16,7 @@ public function setUpLineString(): void /** * @BeforeMethods("setUpLineString") - * @Revs(200) + * @Revs(100) */ public function benchInvertXY(): void { @@ -25,7 +25,7 @@ public function benchInvertXY(): void /** * @BeforeMethods("setUpLineString") - * @Revs(1000) + * @Revs(200) */ public function benchIsEmpty(): void { @@ -74,7 +74,7 @@ public function benchExplodeTrue(): void /** * @BeforeMethods("setUpLineString") - * @Revs(1000) + * @Revs(200) */ public function benchGeometryN(): void { @@ -83,7 +83,7 @@ public function benchGeometryN(): void /** * @BeforeMethods("setUpLineString") - * @Revs(1000) + * @Revs(200) */ public function benchEndPoint(): void { diff --git a/tests/Benchmark/Geometry/PolygonBench.php b/tests/Benchmark/Geometry/PolygonBench.php index b53c5799..0e85f11f 100644 --- a/tests/Benchmark/Geometry/PolygonBench.php +++ b/tests/Benchmark/Geometry/PolygonBench.php @@ -39,7 +39,7 @@ public function benchCreatePolygon(array $params): void /** * @BeforeMethods("setUpPolygonLarge") - * @Revs(1000) + * @Revs(200) */ public function benchIsEmpty(): void { @@ -48,7 +48,7 @@ public function benchIsEmpty(): void /** * @BeforeMethods("setUpPolygonLarge") - * @Revs(1000) + * @Revs(200) */ public function benchExteriorRing(): void { @@ -57,6 +57,7 @@ public function benchExteriorRing(): void /** * @BeforeMethods("setUpPolygonSmall") + * @Revs(10) */ public function benchGetPoints(): void { @@ -65,6 +66,7 @@ public function benchGetPoints(): void /** * @BeforeMethods("setUpPolygonSmall") + * @Revs(10) */ public function benchArea(): void {