예제 #1
0
 public function testMisc()
 {
     $p1 = new WMPoint(0, 0);
     $p2 = new WMPoint(10, 0);
     $p3 = new WMPoint(0, 10);
     $this->assertEquals(50, getTriangleArea($p1, $p2, $p3));
     $p1 = new WMPoint(6, 35);
     $p2 = new WMPoint(15, 10);
     $p3 = new WMPoint(50, 29);
     $this->assertEquals(523, getTriangleArea($p1, $p2, $p3));
 }
 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;
 }