diff --git a/src/Geometry/Circle.php b/src/Geometry/Circle.php index 0180d82b..4e482582 100644 --- a/src/Geometry/Circle.php +++ b/src/Geometry/Circle.php @@ -2,15 +2,16 @@ namespace Intervention\Image\Geometry; +use Intervention\Image\Interfaces\PointInterface; + class Circle extends Ellipse { public function __construct( protected int $diameter, - protected ?Point $pivot = null + protected PointInterface $pivot = new Point() ) { $this->setWidth($diameter); $this->setHeight($diameter); - $this->pivot = $pivot ? $pivot : new Point(); } public function diameter(int $diameter): self diff --git a/src/Geometry/Ellipse.php b/src/Geometry/Ellipse.php index fb37dc7e..f2d7f95c 100644 --- a/src/Geometry/Ellipse.php +++ b/src/Geometry/Ellipse.php @@ -5,6 +5,7 @@ namespace Intervention\Image\Geometry; use Intervention\Image\Geometry\Traits\HasBackgroundColor; use Intervention\Image\Geometry\Traits\HasBorder; use Intervention\Image\Interfaces\DrawableInterface; +use Intervention\Image\Interfaces\PointInterface; class Ellipse implements DrawableInterface { @@ -14,9 +15,9 @@ class Ellipse implements DrawableInterface public function __construct( protected int $width, protected int $height, - protected ?Point $pivot = null + protected PointInterface $pivot = new Point() ) { - $this->pivot = $pivot ? $pivot : new Point(); + // } public function size(int $width, int $height): self diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index 95386096..fb4771f2 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -10,6 +10,7 @@ use IteratorAggregate; use Intervention\Image\Geometry\Traits\HasBackgroundColor; use Intervention\Image\Geometry\Traits\HasBorder; use Intervention\Image\Interfaces\DrawableInterface; +use Intervention\Image\Interfaces\PointInterface; class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface { @@ -18,9 +19,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte public function __construct( protected array $points = [], - protected ?Point $pivot = null + protected PointInterface $pivot = new Point() ) { - $this->pivot = $pivot ? $pivot : new Point(); + // } public function getIterator(): Traversable @@ -31,9 +32,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte /** * Return current pivot point * - * @return Point + * @return PointInterface */ - public function getPivot(): Point + public function getPivot(): PointInterface { return $this->pivot; } diff --git a/src/Geometry/Rectangle.php b/src/Geometry/Rectangle.php index a69d477c..d32609a3 100644 --- a/src/Geometry/Rectangle.php +++ b/src/Geometry/Rectangle.php @@ -17,9 +17,8 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface public function __construct( int $width, int $height, - protected ?Point $pivot = null + protected PointInterface $pivot = new Point() ) { - $this->pivot = $pivot ? $pivot : new Point(); $this->addPoint(new Point($this->pivot->x(), $this->pivot->y())); $this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y())); $this->addPoint(new Point($this->pivot->x() + $width, $this->pivot->y() - $height)); @@ -62,7 +61,7 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return $this; } - public function pivot(): Point + public function pivot(): PointInterface { return $this->pivot; } diff --git a/src/Interfaces/PointInterface.php b/src/Interfaces/PointInterface.php index cbcb7167..9ed05154 100644 --- a/src/Interfaces/PointInterface.php +++ b/src/Interfaces/PointInterface.php @@ -17,4 +17,13 @@ interface PointInterface * @return int */ public function y(): int; + + /** + * Set position of point + * + * @param int $x + * @param int $y + * @return PointInterface + */ + public function setPosition(int $x, int $y): PointInterface; }