Location\Polygon::getReverse PHP Method

getReverse() public method

Create a new polygon with reversed order of points, i. e. reversed polygon direction.
public getReverse ( ) : Polygon
return Polygon
    public function getReverse()
    {
        $reversed = new static();
        foreach (array_reverse($this->points) as $point) {
            $reversed->addPoint($point);
        }
        return $reversed;
    }

Usage Example

Beispiel #1
0
 public function testReverseTwiceWorksAsExpected()
 {
     $polygon = new Polygon();
     $polygon->addPoint(new Coordinate(52.5, 13.5));
     $polygon->addPoint(new Coordinate(64.09999999999999, -21.9));
     $polygon->addPoint(new Coordinate(40.7, -74.0));
     $polygon->addPoint(new Coordinate(33.9, -118.4));
     $doubleReversed = $polygon->getReverse()->getReverse();
     $this->assertEquals($polygon, $doubleReversed);
 }