Skip to content

Commit

Permalink
Test against bounding boxes before full polygons
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Mar 24, 2024
1 parent 8522d6f commit 6acfa8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/CoordinateOperation/AutoConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,19 @@ protected function validatePath(array $candidatePath, Compound|Geocentric|Geogra
{
foreach ($candidatePath as $pathStep) {
$operation = CoordinateOperations::getOperationData($pathStep['operation']);
if ($boundaryCheckPoint) {
// filter out operations that only operate outside this point
$polygon = $operation['extent'] = $operation['extent'] instanceof BoundingArea ? $operation['extent'] : BoundingArea::createFromExtentCodes($operation['extent']);
if (!$polygon->containsPoint($boundaryCheckPoint)) {

if ($boundaryCheckPoint) { // Filter out operations that only operate outside this point
// First, eliminate based on bounding box if possible, that's quicker as only 4 corners
if (!$operation['extent'] instanceof BoundingArea) {
$bbox = BoundingArea::createFromExtentCodes($operation['extent'], true);
if (!$bbox->containsPoint($boundaryCheckPoint)) {
return false;
}
}

// Then (or only) check the point is inside the full, complex shape
$polygon = $operation['extent'] instanceof BoundingArea ? $operation['extent'] : BoundingArea::createFromExtentCodes($operation['extent']);
if ((!isset($bbox) || $polygon !== $bbox) && !$polygon->containsPoint($boundaryCheckPoint)) {
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Geometry/BoundingArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public static function createWorld(): self
* @internal
* @param string[] $extentCodes
*/
public static function createFromExtentCodes(array $extentCodes): self
public static function createFromExtentCodes(array $extentCodes, bool $boundingBoxOnly = false): self
{
$cacheKey = implode('|', $extentCodes);
$cacheKey = implode('|', $extentCodes) . ($boundingBoxOnly ? 'bboxOnly' : '');
if (!isset(self::$cachedObjects[$cacheKey])) {
$regions = [];

Expand All @@ -121,7 +121,7 @@ public static function createFromExtentCodes(array $extentCodes): self
$pathToExtent = __DIR__ . '/Extents/BoundingBoxOnly/' . $filename;
if (InstalledVersions::isInstalled(RegionMap::PACKAGES[$region])) {
$baseDir = InstalledVersions::getInstallPath(RegionMap::PACKAGES[$region]) . '/src/Geometry/Extents/';
if (file_exists($baseDir . $filename)) {
if ((!$boundingBoxOnly || $region === RegionMap::REGION_GLOBAL) && file_exists($baseDir . $filename)) {
$pathToExtent = $baseDir . $filename;
}
}
Expand Down

0 comments on commit 6acfa8c

Please sign in to comment.