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:
parent
39613b731a
commit
7a103cbfa8
@ -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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user