mirror of
https://github.com/Intervention/image.git
synced 2025-08-06 13:56:30 +02:00
Implement IteratorAggregate in Polygon::class
This commit is contained in:
@@ -3,10 +3,19 @@
|
|||||||
namespace Intervention\Image\Geometry;
|
namespace Intervention\Image\Geometry;
|
||||||
|
|
||||||
use ArrayAccess;
|
use ArrayAccess;
|
||||||
|
use ArrayIterator;
|
||||||
use Countable;
|
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(
|
public function __construct(
|
||||||
protected array $points = [],
|
protected array $points = [],
|
||||||
protected ?Point $pivot = null
|
protected ?Point $pivot = null
|
||||||
@@ -14,6 +23,11 @@ class Polygon implements Countable, ArrayAccess
|
|||||||
$this->pivot = $pivot ? $pivot : new Point();
|
$this->pivot = $pivot ? $pivot : new Point();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getIterator(): Traversable
|
||||||
|
{
|
||||||
|
return new ArrayIterator($this->points);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return current pivot point
|
* Return current pivot point
|
||||||
*
|
*
|
||||||
@@ -133,6 +147,13 @@ class Polygon implements Countable, ArrayAccess
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function point(int $x, int $y): self
|
||||||
|
{
|
||||||
|
$this->addPoint(new Point($x, $y));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate total horizontal span of polygon
|
* Calculate total horizontal span of polygon
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user