diff --git a/src/Geometry/Circle.php b/src/Geometry/Circle.php index 06d10757..15cc4811 100644 --- a/src/Geometry/Circle.php +++ b/src/Geometry/Circle.php @@ -6,6 +6,13 @@ use Intervention\Image\Interfaces\PointInterface; class Circle extends Ellipse { + /** + * Create new Circle instance + * + * @param int $diameter + * @param PointInterface $pivot + * @return void + */ public function __construct( protected int $diameter, protected PointInterface $pivot = new Point() @@ -14,6 +21,12 @@ class Circle extends Ellipse $this->setHeight($diameter); } + /** + * Set diameter of circle + * + * @param int $diameter + * @return Circle + */ public function setDiameter(int $diameter): self { $this->setWidth($diameter); @@ -22,16 +35,32 @@ class Circle extends Ellipse return $this; } + /** + * Get diameter of circle + * + * @return int + */ public function diameter(): int { return $this->diameter; } + /** + * Set radius of circle + * + * @param int $radius + * @return Circle + */ public function setRadius(int $radius): self { return $this->setDiameter(intval($radius * 2)); } + /** + * Get radius of circle + * + * @return int + */ public function radius(): int { return intval($this->diameter / 2); diff --git a/src/Geometry/Ellipse.php b/src/Geometry/Ellipse.php index bccbdfb8..8b95e526 100644 --- a/src/Geometry/Ellipse.php +++ b/src/Geometry/Ellipse.php @@ -12,6 +12,14 @@ class Ellipse implements DrawableInterface use HasBorder; use HasBackgroundColor; + /** + * Create new Ellipse + * + * @param int $width + * @param int $height + * @param PointInterface $pivot + * @return void + */ public function __construct( protected int $width, protected int $height, @@ -19,21 +27,45 @@ class Ellipse implements DrawableInterface ) { } + + /** + * {@inheritdoc} + * + * @see DrawableInterface::position() + */ public function position(): PointInterface { return $this->pivot; } + /** + * Return pivot point of Ellipse + * + * @return PointInterface + */ public function pivot(): PointInterface { return $this->pivot; } + /** + * Set size of Ellipse + * + * @param int $width + * @param int $height + * @return Ellipse + */ public function setSize(int $width, int $height): self { return $this->setWidth($width)->setHeight($height); } + /** + * Set width of Ellipse + * + * @param int $width + * @return Ellipse + */ public function setWidth(int $width): self { $this->width = $width; @@ -41,6 +73,12 @@ class Ellipse implements DrawableInterface return $this; } + /** + * Set height of Ellipse + * + * @param int $height + * @return Ellipse + */ public function setHeight(int $height): self { $this->height = $height; @@ -48,11 +86,21 @@ class Ellipse implements DrawableInterface return $this; } + /** + * Get width of Ellipse + * + * @return int + */ public function width(): int { return $this->width; } + /** + * Get height of Ellipse + * + * @return int + */ public function height(): int { return $this->height; diff --git a/src/Geometry/Line.php b/src/Geometry/Line.php index 58f030c3..51aca33e 100644 --- a/src/Geometry/Line.php +++ b/src/Geometry/Line.php @@ -12,6 +12,14 @@ class Line implements DrawableInterface use HasBorder; use HasBackgroundColor; + /** + * Create new line instance + * + * @param Point $start + * @param Point $end + * @param int $width + * @return void + */ public function __construct( protected Point $start, protected Point $end, @@ -19,16 +27,32 @@ class Line implements DrawableInterface ) { } + /** + * {@inheritdoc} + * + * @see DrawableInterface::position() + */ public function position(): PointInterface { return $this->start; } + /** + * Return line width + * + * @return int + */ public function width(): int { return $this->width; } + /** + * Set line width + * + * @param int $width + * @return Line + */ public function setWidth(int $width): self { $this->width = $width; @@ -36,16 +60,32 @@ class Line implements DrawableInterface return $this; } + /** + * Get starting point of line + * + * @return Point + */ public function start(): Point { return $this->start; } + /** + * get end point of line + * + * @return Point + */ public function end(): Point { return $this->end; } + /** + * Set starting point of line + * + * @param Point $start + * @return Line + */ public function setStart(Point $start): self { $this->start = $start; @@ -53,6 +93,13 @@ class Line implements DrawableInterface return $this; } + /** + * Set starting point of line by coordinates + * + * @param int $x + * @param int $y + * @return Line + */ public function from(int $x, int $y): self { $this->start()->setX($x); @@ -61,6 +108,13 @@ class Line implements DrawableInterface return $this; } + /** + * Set end point of line by coordinates + * + * @param int $x + * @param int $y + * @return Line + */ public function to(int $x, int $y): self { $this->end()->setX($x); @@ -69,6 +123,12 @@ class Line implements DrawableInterface return $this; } + /** + * Set end point of line + * + * @param Point $end + * @return Line + */ public function setEnd(Point $end): self { $this->end = $end; diff --git a/src/Geometry/Pixel.php b/src/Geometry/Pixel.php index eaa2326c..f6784250 100644 --- a/src/Geometry/Pixel.php +++ b/src/Geometry/Pixel.php @@ -6,6 +6,14 @@ use Intervention\Image\Interfaces\ColorInterface; class Pixel extends Point { + /** + * Create new pixel instance + * + * @param ColorInterface $background + * @param int $x + * @param int $y + * @return void + */ public function __construct( protected ColorInterface $background, protected int $x, @@ -13,6 +21,11 @@ class Pixel extends Point ) { } + /** + * {@inheritdoc} + * + * @see DrawableInterface::setBackgroundColor() + */ public function setBackgroundColor(ColorInterface $background): self { $this->background = $background; @@ -20,6 +33,11 @@ class Pixel extends Point return $this; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::backgroundColor() + */ public function backgroundColor(): ColorInterface { return $this->background; diff --git a/src/Geometry/Point.php b/src/Geometry/Point.php index 11b48c9e..d0184aae 100644 --- a/src/Geometry/Point.php +++ b/src/Geometry/Point.php @@ -6,6 +6,13 @@ use Intervention\Image\Interfaces\PointInterface; class Point implements PointInterface { + /** + * Create new point instance + * + * @param int $x + * @param int $y + * @return void + */ public function __construct( protected int $x = 0, protected int $y = 0 diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index f5ba2804..0567a9d6 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -17,17 +17,34 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte use HasBorder; use HasBackgroundColor; + /** + * Create new polygon instance + * + * @param array $points + * @param PointInterface $pivot + * @return void + */ public function __construct( protected array $points = [], protected PointInterface $pivot = new Point() ) { } + /** + * {@inheritdoc} + * + * @see DrawableInterface::position() + */ public function position(): PointInterface { return $this->pivot; } + /** + * Implement iteration through all points of polygon + * + * @return Traversable + */ public function getIterator(): Traversable { return new ArrayIterator($this->points); diff --git a/src/Geometry/Rectangle.php b/src/Geometry/Rectangle.php index 31bbaa37..46b09075 100644 --- a/src/Geometry/Rectangle.php +++ b/src/Geometry/Rectangle.php @@ -9,6 +9,14 @@ use Intervention\Image\Interfaces\SizeInterface; class Rectangle extends Polygon implements SizeInterface, DrawableInterface { + /** + * Create new rectangle instance + * + * @param int $width + * @param int $height + * @param PointInterface $pivot + * @return void + */ public function __construct( int $width, int $height, @@ -20,11 +28,24 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface $this->addPoint(new Point($this->pivot->x(), $this->pivot->y() - $height)); } + /** + * Set size of rectangle + * + * @param int $width + * @param int $height + * @return Rectangle + */ public function setSize(int $width, int $height): self { return $this->setWidth($width)->setHeight($height); } + /** + * Set width of rectangle + * + * @param int $width + * @return Rectangle + */ public function setWidth(int $width): self { $this[1]->setX($this[0]->x() + $width); @@ -33,6 +54,12 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return $this; } + /** + * Set height of rectangle + * + * @param int $height + * @return Rectangle + */ public function setHeight(int $height): self { $this[2]->setY($this[1]->y() + $height); @@ -41,11 +68,22 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return $this; } + /** + * Return pivot point of rectangle + * + * @return PointInterface + */ public function pivot(): PointInterface { return $this->pivot; } + /** + * Set pivot point of rectangle + * + * @param PointInterface $pivot + * @return Rectangle + */ public function setPivot(PointInterface $pivot): self { $this->pivot = $pivot; @@ -53,6 +91,15 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return $this; } + /** + * Move pivot to the given position in the rectangle and adjust the new + * position by given offset values. + * + * @param string $position + * @param int $offset_x + * @param int $offset_y + * @return Rectangle + */ public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): self { switch (strtolower($position)) { @@ -131,6 +178,13 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return $this; } + /** + * Align pivot relative to given size at given position + * + * @param SizeInterface $size + * @param string $position + * @return Rectangle + */ public function alignPivotTo(SizeInterface $size, string $position): self { $reference = new self($size->width(), $size->height()); @@ -143,6 +197,12 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return $this; } + /** + * Return relative position to given rectangle + * + * @param SizeInterface $rectangle + * @return PointInterface + */ public function relativePositionTo(SizeInterface $rectangle): PointInterface { return new Point( @@ -151,11 +211,22 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface ); } + /** + * Return aspect ration of rectangle + * + * @return float + */ public function aspectRatio(): float { return $this->width() / $this->height(); } + /** + * Determine if rectangle fits into given rectangle + * + * @param SizeInterface $size + * @return bool + */ public function fitsInto(SizeInterface $size): bool { if ($this->width() > $size->width()) { @@ -169,21 +240,41 @@ class Rectangle extends Polygon implements SizeInterface, DrawableInterface return true; } + /** + * Determine if rectangle has landscape format + * + * @return bool + */ public function isLandscape(): bool { return $this->width() > $this->height(); } + /** + * Determine if rectangle has landscape format + * + * @return bool + */ public function isPortrait(): bool { return $this->width() < $this->height(); } + /** + * Return most top left point of rectangle + * + * @return PointInterface + */ public function topLeftPoint(): PointInterface { return $this->points[0]; } + /** + * Return bottom right point of rectangle + * + * @return PointInterface + */ public function bottomRightPoint(): PointInterface { return $this->points[2]; diff --git a/src/Geometry/Traits/HasBackgroundColor.php b/src/Geometry/Traits/HasBackgroundColor.php index 4426ead0..bc28d42f 100644 --- a/src/Geometry/Traits/HasBackgroundColor.php +++ b/src/Geometry/Traits/HasBackgroundColor.php @@ -6,6 +6,11 @@ trait HasBackgroundColor { protected mixed $backgroundColor = null; + /** + * {@inheritdoc} + * + * @see DrawableInterface::setBackgroundColor() + */ public function setBackgroundColor(mixed $color): self { $this->backgroundColor = $color; @@ -13,11 +18,21 @@ trait HasBackgroundColor return $this; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::backgroundColor() + */ public function backgroundColor(): mixed { return $this->backgroundColor; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::hasBackgroundColor() + */ public function hasBackgroundColor(): bool { return !empty($this->backgroundColor); diff --git a/src/Geometry/Traits/HasBorder.php b/src/Geometry/Traits/HasBorder.php index 67142f5a..b76bef98 100644 --- a/src/Geometry/Traits/HasBorder.php +++ b/src/Geometry/Traits/HasBorder.php @@ -7,11 +7,21 @@ trait HasBorder protected mixed $borderColor = null; protected int $borderSize = 0; + /** + * {@inheritdoc} + * + * @see DrawableInterface::setBorder() + */ public function setBorder(mixed $color, int $size = 1): self { return $this->setBorderSize($size)->setBorderColor($color); } + /** + * {@inheritdoc} + * + * @see DrawableInterface::setBorderSize() + */ public function setBorderSize(int $size): self { $this->borderSize = $size; @@ -19,11 +29,21 @@ trait HasBorder return $this; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::borderSize() + */ public function borderSize(): int { return $this->borderSize; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::setBorderColor() + */ public function setBorderColor(mixed $color): self { $this->borderColor = $color; @@ -31,11 +51,21 @@ trait HasBorder return $this; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::borderColor() + */ public function borderColor(): mixed { return $this->borderColor; } + /** + * {@inheritdoc} + * + * @see DrawableInterface::hasBorder() + */ public function hasBorder(): bool { return $this->borderSize > 0 && !is_null($this->borderColor); diff --git a/src/Interfaces/DrawableInterface.php b/src/Interfaces/DrawableInterface.php index 4dff75d5..767cae55 100644 --- a/src/Interfaces/DrawableInterface.php +++ b/src/Interfaces/DrawableInterface.php @@ -4,14 +4,78 @@ namespace Intervention\Image\Interfaces; interface DrawableInterface { + /** + * Position of the drawable object + * + * @return PointInterface + */ public function position(): PointInterface; - public function setBackgroundColor(mixed $color); + + /** + * Set the background color of the drawable object + * + * @param mixed $color + * @return DrawableInterface + */ + public function setBackgroundColor(mixed $color): DrawableInterface; + + /** + * Return background color of drawable object + * + * @return mixed + */ public function backgroundColor(): mixed; + + /** + * Determine if a background color was set + * + * @return bool + */ public function hasBackgroundColor(): bool; - public function setBorder(mixed $color, int $size = 1); - public function setBorderSize(int $size); - public function setBorderColor(mixed $color); + + /** + * Set border color & size of the drawable object + * + * @param mixed $color + * @param int $size + * @return DrawableInterface + */ + public function setBorder(mixed $color, int $size = 1): DrawableInterface; + + /** + * Set border size of the drawable object + * + * @param int $size + * @return DrawableInterface + */ + public function setBorderSize(int $size): DrawableInterface; + + /** + * Set border color of the drawable object + * + * @param mixed $color + * @return DrawableInterface + */ + public function setBorderColor(mixed $color): DrawableInterface; + + /** + * Get border size + * + * @return int + */ public function borderSize(): int; + + /** + * Get border color of drawable object + * + * @return mixed + */ public function borderColor(): mixed; + + /** + * Determine if the drawable object has a border + * + * @return bool + */ public function hasBorder(): bool; }