Exemple #1
0
 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());
     }
 }
Exemple #2
0
require_once 'libs.php';
$tree = new Sandfox\KDTree\Point();
$yFactor = 3;
$numDimensions = 4;
$totalPoints = 100000;
$resultsToReturn = 5000;
echo "Getting cached tree\n";
$cacheFindStartTime = microtime(true);
$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;