Skip to content

Commit

Permalink
change pow() to **
Browse files Browse the repository at this point in the history
  • Loading branch information
Péter Báthory committed Aug 22, 2022
1 parent 2cf5345 commit facd8fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
25 changes: 12 additions & 13 deletions src/Geometry/LineString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Geometry/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use function gettype;
use function is_finite;
use function is_numeric;
use function pow;
use function sqrt;

/**
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Benchmark/Geometry/LineStringBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUpLineString(): void

/**
* @BeforeMethods("setUpLineString")
* @Revs(200)
* @Revs(100)
*/
public function benchInvertXY(): void
{
Expand All @@ -25,7 +25,7 @@ public function benchInvertXY(): void

/**
* @BeforeMethods("setUpLineString")
* @Revs(1000)
* @Revs(200)
*/
public function benchIsEmpty(): void
{
Expand Down Expand Up @@ -74,7 +74,7 @@ public function benchExplodeTrue(): void

/**
* @BeforeMethods("setUpLineString")
* @Revs(1000)
* @Revs(200)
*/
public function benchGeometryN(): void
{
Expand All @@ -83,7 +83,7 @@ public function benchGeometryN(): void

/**
* @BeforeMethods("setUpLineString")
* @Revs(1000)
* @Revs(200)
*/
public function benchEndPoint(): void
{
Expand Down
6 changes: 4 additions & 2 deletions tests/Benchmark/Geometry/PolygonBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function benchCreatePolygon(array $params): void

/**
* @BeforeMethods("setUpPolygonLarge")
* @Revs(1000)
* @Revs(200)
*/
public function benchIsEmpty(): void
{
Expand All @@ -48,7 +48,7 @@ public function benchIsEmpty(): void

/**
* @BeforeMethods("setUpPolygonLarge")
* @Revs(1000)
* @Revs(200)
*/
public function benchExteriorRing(): void
{
Expand All @@ -57,6 +57,7 @@ public function benchExteriorRing(): void

/**
* @BeforeMethods("setUpPolygonSmall")
* @Revs(10)
*/
public function benchGetPoints(): void
{
Expand All @@ -65,6 +66,7 @@ public function benchGetPoints(): void

/**
* @BeforeMethods("setUpPolygonSmall")
* @Revs(10)
*/
public function benchArea(): void
{
Expand Down

0 comments on commit facd8fb

Please sign in to comment.