1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-29 17:57:50 +01:00

Implement IteratorAggregate in Polygon::class

This commit is contained in:
Oliver Vogel 2022-07-25 11:13:38 +02:00
parent 39613b731a
commit 7a103cbfa8

View File

@ -3,10 +3,19 @@
namespace Intervention\Image\Geometry;
use ArrayAccess;
use ArrayIterator;
use Countable;
use Traversable;
use IteratorAggregate;
use Intervention\Image\Geometry\Traits\HasBackgroundColor;
use Intervention\Image\Geometry\Traits\HasBorder;
use Intervention\Image\Interfaces\DrawableInterface;
class Polygon implements Countable, ArrayAccess
class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
{
use HasBorder;
use HasBackgroundColor;
public function __construct(
protected array $points = [],
protected ?Point $pivot = null
@ -14,6 +23,11 @@ class Polygon implements Countable, ArrayAccess
$this->pivot = $pivot ? $pivot : new Point();
}
public function getIterator(): Traversable
{
return new ArrayIterator($this->points);
}
/**
* Return current pivot point
*
@ -133,6 +147,13 @@ class Polygon implements Countable, ArrayAccess
return $this;
}
public function point(int $x, int $y): self
{
$this->addPoint(new Point($x, $y));
return $this;
}
/**
* Calculate total horizontal span of polygon
*