Example #1
0
 public function getLength(PolygonInterface $polygon)
 {
     $segments = $this->getFactoriesCollection()->getLineFactory()->createLineSegmentCollection($polygon->getPoints());
     return array_sum(array_map(function (LineSegmentInterface $segment) {
         return $segment->getLength();
     }, $segments->toArray()));
 }
Example #2
0
 /**
  * 
  * (non-PHPdoc)
  * @see \samizdam\Geometry\Plane\Polygons\PolygonInspectorInterface::isRegular()
  * 
  * @param PolygonInterface $polygon
  */
 public function isRegular(PolygonInterface $polygon)
 {
     $points = $polygon->getPoints();
     $segments = $this->getFactoriesCollection()->getLineFactory()->createLineSegmentCollection($points);
     $samleSegment = $segments->current();
     foreach ($segments as $segment) {
         if ($segment->getLength() !== $samleSegment->getLength()) {
             return false;
         }
     }
     $angles = $this->getFactoriesCollection()->getAngleFactory()->createAngleCollection($points);
     $sampleAngle = $angles->current();
     foreach ($angles as $angle) {
         if ($sampleAngle->getSize() !== $angle->getSize()) {
             return false;
         }
     }
     return true;
 }