} function findConvexHull($points) { if (count($points) < 4) { return $points; } $hull = array(); // Step 1: Find the two points with the min and max x positions. $min_point = array_reduce($points, function ($carry, $item) { return $item["x"] < $carry["x"] ? $item : $carry; }, $points[0]); $max_point = array_reduce($points, function ($carry, $item) { return $item["x"] > $carry["x"] ? $item : $carry; }, $points[0]); array_push($hull, $min_point, $max_point); // Step 2: Use the line between the two points to divide the remaining // points into two sets, one for each side of the line. list($side1, $side2) = partitionSides($min_point, $max_point, $points); $hull = array_merge($hull, buildHullWithTriangles($min_point, $max_point, $side1), buildHullWithTriangles($min_point, $max_point, $side2)); return $hull; } function verifyConvexHull($actual, $expected) { return true; } $quickHull = function () { srand(42); $points = generatePoints(1000); $hull = findConvexHull($points); }; $QuickHull = new BenchmarkSuite('QuickHull', [100000], array(new Benchmark('QuickHull', true, false, 4400, $quickHull)));
use Sandfox\KDTree; //This assumes you have cloned this repo and run composer dumpautoload require_once '../vendor/autoload.php'; 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();