Skip to content

Commit ea08780

Browse files
committed
Provide alternative way for mass-calling contains()
1 parent 6f75874 commit ea08780

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/CodeArea.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,19 @@ public function getCenterLongitude(): float
3838
{
3939
return ($this->eastLongitude + $this->westLongitude) / 2;
4040
}
41+
42+
/**
43+
* Returns whether the bounding box specified by the code area (from a decoded Open Location Code) contains the provided point.
44+
*
45+
* @param float $latitude The provided latitude in degrees.
46+
* @param float $longitude The provided longitude in degrees.
47+
* @return bool True if tge coordinates are contained by the code area.
48+
*/
49+
public function contains(float $latitude, float $longitude): bool
50+
{
51+
return $this->southLatitude <= $latitude
52+
&& $latitude < $this->northLatitude
53+
&& $this->westLongitude <= $longitude
54+
&& $longitude < $this->eastLongitude;
55+
}
4156
}

src/OpenLocationCode.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,16 @@ public function recover(float $referenceLatitude, float $referenceLongitude): se
349349
/**
350350
* Returns whether the bounding box specified by the Open Location Code contains the provided point.
351351
*
352+
* @see CodeArea::contains() for the underlying implementation.
353+
*
352354
* @param float $latitude The provided latitude in degrees.
353355
* @param float $longitude The provided longitude in degrees.
354356
* @return bool True if tge coordinates are contained by the code.
355357
*/
356358
public function contains(float $latitude, float $longitude): bool
357359
{
358360
$codeArea = $this->decode();
359-
return $codeArea->southLatitude <= $latitude
360-
&& $latitude < $codeArea->northLatitude
361-
&& $codeArea->westLongitude <= $longitude
362-
&& $longitude < $codeArea->eastLongitude;
361+
return $codeArea->contains($latitude, $longitude);
363362
}
364363

365364
// ---

0 commit comments

Comments
 (0)