function simplify($epsilon = 1.0E-10) { $output = new WMSpine(); $output->addPoint($this->points[0][0]); $maxStartIndex = count($this->points) - 2; $skip = 0; for ($n = 1; $n <= $maxStartIndex; $n++) { // figure out the area of the triangle formed by this point, and the one before and after $area = getTriangleArea($this->points[$n - 1][0], $this->points[$n][0], $this->points[$n + 1][0]); if ($area > $epsilon) { $output->addPoint($this->points[$n][0]); } else { // ignore n $skip++; } } wm_debug("Skipped {$skip} points of {$maxStartIndex}\n"); $output->addPoint($this->points[$maxStartIndex + 1][0]); return $output; }
function testDistanceSearch() { $testSpine = new WMSpine(); $testSpine->addPoint(new WMPoint(50, 50)); $testSpine->addPoint(new WMPoint(150, 50)); $testSpine->addPoint(new WMPoint(150, 150)); $this->assertEquals(200, $testSpine->totalDistance()); $this->assertEquals(3, $testSpine->pointCount()); $index = $testSpine->findIndexNearDistance(110); $this->assertEquals(1, $index); $index = $testSpine->findIndexNearDistance(90); $this->assertEquals(0, $index); $testSpine->addPoint(new WMPoint(0, 150)); $testSpine->addPoint(new WMPoint(0, 0)); $this->assertEquals(500, $testSpine->totalDistance()); $index = $testSpine->findIndexNearDistance(250); $this->assertEquals(2, $index); $index = $testSpine->findIndexNearDistance(600); $this->assertEquals(4, $index); $index = $testSpine->findIndexNearDistance(100); $this->assertEquals(1, $index); $index = $testSpine->findIndexNearDistance(100); $this->assertEquals(1, $index); $index = $testSpine->findIndexNearDistance(-100); $this->assertEquals(0, $index); }