public function testDepthGreaterThanMaxDepthThrowsException() { try { KDTree\KDTree::build([1], 501, 500); $this->fail("no exception thrown"); } catch (\OverflowException $e) { $this->assertEquals("Depth exceeded maximum of 500. Check for exact duplicate points, which cause infinite recursion, or specify the optional maxdepth argument.", $e->getMessage()); } }
$myTree = getCachedTree(); if ($myTree === null) { echo "No cached tree found\n"; echo "Generating a tree with " . $totalPoints . " points existing in " . $numDimensions . " space\n"; $points = generatePoints($totalPoints, $numDimensions, $yFactor); echo "Building tree\n"; $startTime = microtime(true); $myTree = KDTree\KDTree::build($points); $stopTime = microtime(true); echo "Finished building tree in " . ($stopTime - $startTime) . " seconds\n\n"; echo "Caching tree\n"; $cacheWriteStartTime = microtime(true); cacheTree($myTree); $cacheWriteStopTime = microtime(true); echo "Finished caching tree in " . ($cacheWriteStopTime - $cacheWriteStartTime) . " seconds\n"; } else { $cacheFindStopTime = microtime(true); echo "Cache unserialized in " . ($cacheFindStopTime - $cacheFindStartTime) . " seconds\n"; } $originPoint = new KDTree\Point(); $originPoint[] = 0; $originPoint[] = 30; //$originPoint[] = -1; $results = new KDTree\SearchResults($resultsToReturn); echo "Finding nearest " . $resultsToReturn . " nodes from a total of probably " . $totalPoints . " nodes\n"; $startTime = microtime(true); $result = KDTree\KDTree::nearestNeighbour($myTree, $originPoint, $results); $stopTime = microtime(true); echo "Finished search " . ($stopTime - $startTime) . " seconds\n\n"; $nearest = $results->getNearestNode(); var_dump($nearest['data']->getPoint());