foreach ($cityFile as $cityData) { if (!empty($cityData[0])) { if ($cityCount % 1000 == 0) { echo '.'; } $city = new cityPoint($cityData[0], $cityData[1], $cityData[3], $cityData[2]); $quadTree->insert($city); ++$cityCount; } } echo PHP_EOL, "Added {$cityCount} cities to QuadTree", PHP_EOL; return $quadTree; } /* Populate the quadtree */ $startTime = microtime(true); $citiesQuadTree = buildQuadTree(__DIR__ . "/../data/citylist.csv"); $endTime = microtime(true); $callTime = $endTime - $startTime; echo 'Load Time: ', sprintf('%.4f', $callTime), ' s', PHP_EOL; echo 'Current Memory: ', sprintf('%.2f', memory_get_usage(false) / 1024), ' k', PHP_EOL; echo 'Peak Memory: ', sprintf('%.2f', memory_get_peak_usage(false) / 1024), ' k', PHP_EOL, PHP_EOL; /* Search for cities within a bounding box */ $startTime = microtime(true); // Create a bounding box to search in, centred on the specified longitude and latitude $searchCentrePoint = new \QuadTrees\QuadTreeXYPoint($longitude, $latitude); // Create the bounding box with specified dimensions $searchBoundingBox = new \QuadTrees\QuadTreeBoundingBox($searchCentrePoint, $width, $height); // Search the cities QuadTree for all entries that fall within the defined bounding box $searchResult = $citiesQuadTree->search($searchBoundingBox); // Sort the results usort($searchResult, function ($a, $b) {
foreach ($landingFile as $lunarLandingData) { if (!empty($lunarLandingData[0])) { if ($lunarLandingCount % 10 == 0) { echo '.'; } $lunarLanding = new lunarLandingPoint(trim($lunarLandingData[0]), trim($lunarLandingData[1]), trim($lunarLandingData[2]), trim($lunarLandingData[4]), trim($lunarLandingData[3])); $quadTree->insert($lunarLanding); ++$lunarLandingCount; } } echo PHP_EOL, "Added {$lunarLandingCount} lunar landing details to QuadTree", PHP_EOL; return $quadTree; } /* Populate the quadtree */ $startTime = microtime(true); $lunarLandingsQuadTree = buildQuadTree(__DIR__ . "/../data/lunarLandings.csv"); $endTime = microtime(true); $callTime = $endTime - $startTime; echo 'Load Time: ', sprintf('%.4f', $callTime), ' s', PHP_EOL; echo 'Current Memory: ', sprintf('%.2f', memory_get_usage(false) / 1024), ' k', PHP_EOL; echo 'Peak Memory: ', sprintf('%.2f', memory_get_peak_usage(false) / 1024), ' k', PHP_EOL, PHP_EOL; /* Search for lunarLandings within a bounding box */ $startTime = microtime(true); // Create a bounding box to search in, centred on the specified longitude and latitude $searchCentrePoint = new \QuadTrees\QuadTreeXYPoint($longitude, $latitude); // Create the bounding box with specified dimensions $searchBoundingBox = new \QuadTrees\QuadTreeBoundingBox($searchCentrePoint, $width, $height); // Search the lunarLandings QuadTree for all entries that fall within the defined bounding box $searchResult = $lunarLandingsQuadTree->search($searchBoundingBox); // Sort the results usort($searchResult, function ($a, $b) {