diff --git a/src/CircularString.php b/src/CircularString.php index f407c5d1..69ed92e3 100644 --- a/src/CircularString.php +++ b/src/CircularString.php @@ -145,13 +145,11 @@ public function geometryTypeBinary() : int #[Override] public function getBoundingBox() : BoundingBox { - $boundingBox = BoundingBox::new(); - - foreach ($this->points as $point) { - $boundingBox = $boundingBox->extendedWithPoint($point); - } - - return $boundingBox; + return array_reduce( + $this->points, + fn (BoundingBox $boundingBox, Point $point) => $boundingBox->extendedWithPoint($point), + BoundingBox::new(), + ); } /** diff --git a/src/CompoundCurve.php b/src/CompoundCurve.php index f73931f6..181d13f9 100644 --- a/src/CompoundCurve.php +++ b/src/CompoundCurve.php @@ -154,13 +154,11 @@ public function geometryTypeBinary() : int #[Override] public function getBoundingBox() : BoundingBox { - $boundingBox = BoundingBox::new(); - - foreach ($this->curves as $curve) { - $boundingBox = $boundingBox->extendedWithBoundingBox($curve->getBoundingBox()); - } - - return $boundingBox; + return array_reduce( + $this->curves, + fn (BoundingBox $boundingBox, Curve $curve) => $boundingBox->extendedWithBoundingBox($curve->getBoundingBox()), + BoundingBox::new(), + ); } /** diff --git a/src/CurvePolygon.php b/src/CurvePolygon.php index 2f7f10b6..48d27292 100644 --- a/src/CurvePolygon.php +++ b/src/CurvePolygon.php @@ -136,13 +136,11 @@ public function geometryTypeBinary() : int #[Override] public function getBoundingBox() : BoundingBox { - $boundingBox = BoundingBox::new(); - - foreach ($this->rings as $ring) { - $boundingBox = $boundingBox->extendedWithBoundingBox($ring->getBoundingBox()); - } - - return $boundingBox; + return array_reduce( + $this->rings, + fn (BoundingBox $boundingBox, Curve $ring) => $boundingBox->extendedWithBoundingBox($ring->getBoundingBox()), + BoundingBox::new(), + ); } #[Override] diff --git a/src/LineString.php b/src/LineString.php index 775d1f86..f1cebd66 100644 --- a/src/LineString.php +++ b/src/LineString.php @@ -187,13 +187,11 @@ public function geometryTypeBinary() : int #[Override] public function getBoundingBox() : BoundingBox { - $boundingBox = BoundingBox::new(); - - foreach ($this->points as $point) { - $boundingBox = $boundingBox->extendedWithPoint($point); - } - - return $boundingBox; + return array_reduce( + $this->points, + fn (BoundingBox $boundingBox, Point $point) => $boundingBox->extendedWithPoint($point), + BoundingBox::new() + ); } /** diff --git a/src/Polygon.php b/src/Polygon.php index 6ff28234..1a20fa25 100644 --- a/src/Polygon.php +++ b/src/Polygon.php @@ -178,13 +178,11 @@ public function geometryTypeBinary() : int #[Override] public function getBoundingBox() : BoundingBox { - $boundingBox = BoundingBox::new(); - - foreach ($this->rings as $ring) { - $boundingBox = $boundingBox->extendedWithBoundingBox($ring->getBoundingBox()); - } - - return $boundingBox; + return array_reduce( + $this->rings, + fn (BoundingBox $carry, LineString $ring) => $carry->extendedWithBoundingBox($ring->getBoundingBox()), + BoundingBox::new() + ); } /** diff --git a/src/PolyhedralSurface.php b/src/PolyhedralSurface.php index ddcd52ad..68480d42 100644 --- a/src/PolyhedralSurface.php +++ b/src/PolyhedralSurface.php @@ -157,13 +157,11 @@ public function geometryTypeBinary() : int #[Override] public function getBoundingBox() : BoundingBox { - $boundingBox = BoundingBox::new(); - - foreach ($this->patches as $patch) { - $boundingBox = $boundingBox->extendedWithBoundingBox($patch->getBoundingBox()); - } - - return $boundingBox; + return array_reduce( + $this->patches, + fn (BoundingBox $boundingBox, Polygon $patch) => $boundingBox->extendedWithBoundingBox($patch->getBoundingBox()), + BoundingBox::new(), + ); } /**