Skip to content

Commit

Permalink
Use array_reduce() in getBoundingBox()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 8, 2025
1 parent 71c49d1 commit a9228c0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 42 deletions.
12 changes: 5 additions & 7 deletions src/CircularString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/CompoundCurve.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/CurvePolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 5 additions & 7 deletions src/LineString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/Polygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/PolyhedralSurface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

/**
Expand Down

0 comments on commit a9228c0

Please sign in to comment.