mirror of
https://github.com/Intervention/image.git
synced 2025-08-17 19:26:25 +02:00
Add Drawable improvements & preparation for future features
* Add DrawableFactoryInterface * Add universal Drawable factory class * Add x/y setter methods to PointInterface * Replace Point::class type hints by PointInterface::class
This commit is contained in:
@@ -15,6 +15,7 @@ use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Interfaces\FontInterface;
|
||||
use Intervention\Image\Interfaces\FrameInterface;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
use Intervention\Image\Interfaces\SpecializedInterface;
|
||||
use Intervention\Image\Modifiers\TextModifier as GenericTextModifier;
|
||||
use Intervention\Image\Typography\Line;
|
||||
@@ -112,14 +113,14 @@ class TextModifier extends GenericTextModifier implements SpecializedInterface
|
||||
* @param FrameInterface $frame
|
||||
* @param Line $textline
|
||||
* @param null|ImagickDraw $draw
|
||||
* @param Point $offset
|
||||
* @param PointInterface $offset
|
||||
* @return void
|
||||
*/
|
||||
private function maybeDrawTextline(
|
||||
FrameInterface $frame,
|
||||
Line $textline,
|
||||
?ImagickDraw $draw = null,
|
||||
Point $offset = new Point(),
|
||||
PointInterface $offset = new Point(),
|
||||
): void {
|
||||
if ($draw !== null) {
|
||||
$frame->native()->annotateImage(
|
||||
|
@@ -15,8 +15,8 @@ use Intervention\Image\Interfaces\DrawableInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
/**
|
||||
* @implements IteratorAggregate<Point>
|
||||
* @implements ArrayAccess<int, Point>
|
||||
* @implements IteratorAggregate<PointInterface>
|
||||
* @implements ArrayAccess<int, PointInterface>
|
||||
*/
|
||||
class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
|
||||
{
|
||||
@@ -26,7 +26,7 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Create new bezier instance
|
||||
*
|
||||
* @param array<Point> $points
|
||||
* @param array<PointInterface> $points
|
||||
* @param PointInterface $pivot
|
||||
* @return void
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Implement iteration through all points of bezier
|
||||
*
|
||||
* @return Traversable<Point>
|
||||
* @return Traversable<PointInterface>
|
||||
*/
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
@@ -69,10 +69,10 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Change pivot point to given point
|
||||
*
|
||||
* @param Point $pivot
|
||||
* @param PointInterface $pivot
|
||||
* @return Bezier
|
||||
*/
|
||||
public function setPivot(Point $pivot): self
|
||||
public function setPivot(PointInterface $pivot): self
|
||||
{
|
||||
$this->pivot = $pivot;
|
||||
|
||||
@@ -82,9 +82,9 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Return first control point of bezier
|
||||
*
|
||||
* @return ?Point
|
||||
* @return ?PointInterface
|
||||
*/
|
||||
public function first(): ?Point
|
||||
public function first(): ?PointInterface
|
||||
{
|
||||
if ($point = reset($this->points)) {
|
||||
return $point;
|
||||
@@ -96,9 +96,9 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Return second control point of bezier
|
||||
*
|
||||
* @return ?Point
|
||||
* @return ?PointInterface
|
||||
*/
|
||||
public function second(): ?Point
|
||||
public function second(): ?PointInterface
|
||||
{
|
||||
if (array_key_exists(1, $this->points)) {
|
||||
return $this->points[1];
|
||||
@@ -110,9 +110,9 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Return third control point of bezier
|
||||
*
|
||||
* @return ?Point
|
||||
* @return ?PointInterface
|
||||
*/
|
||||
public function third(): ?Point
|
||||
public function third(): ?PointInterface
|
||||
{
|
||||
if (array_key_exists(2, $this->points)) {
|
||||
return $this->points[2];
|
||||
@@ -124,9 +124,9 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Return last control point of bezier
|
||||
*
|
||||
* @return ?Point
|
||||
* @return ?PointInterface
|
||||
*/
|
||||
public function last(): ?Point
|
||||
public function last(): ?PointInterface
|
||||
{
|
||||
if ($point = end($this->points)) {
|
||||
return $point;
|
||||
@@ -160,7 +160,7 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
* Return point at given offset
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function offsetGet($offset): mixed
|
||||
{
|
||||
@@ -171,7 +171,7 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
* Set point at given offset
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param Point $value
|
||||
* @param PointInterface $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value): void
|
||||
@@ -193,10 +193,10 @@ class Bezier implements IteratorAggregate, Countable, ArrayAccess, DrawableInter
|
||||
/**
|
||||
* Add given point to bezier
|
||||
*
|
||||
* @param Point $point
|
||||
* @param PointInterface $point
|
||||
* @return Bezier
|
||||
*/
|
||||
public function addPoint(Point $point): self
|
||||
public function addPoint(PointInterface $point): self
|
||||
{
|
||||
$this->points[] = $point;
|
||||
|
||||
|
@@ -6,18 +6,20 @@ namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Bezier;
|
||||
use Intervention\Image\Interfaces\DrawableFactoryInterface;
|
||||
use Intervention\Image\Interfaces\DrawableInterface;
|
||||
|
||||
class BezierFactory
|
||||
class BezierFactory implements DrawableFactoryInterface
|
||||
{
|
||||
protected Bezier $bezier;
|
||||
|
||||
/**
|
||||
* Create new factory instance
|
||||
*
|
||||
* @param callable|Bezier $init
|
||||
* @param null|callable|Bezier $init
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(callable|Bezier $init)
|
||||
public function __construct(null|callable|Bezier $init = null)
|
||||
{
|
||||
$this->bezier = is_a($init, Bezier::class) ? $init : new Bezier([]);
|
||||
|
||||
@@ -26,6 +28,16 @@ class BezierFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableFactoryInterface::create()
|
||||
*/
|
||||
public function create(): DrawableInterface
|
||||
{
|
||||
return $this->bezier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the bezier to be produced
|
||||
*
|
||||
|
@@ -4,8 +4,44 @@ declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
class CircleFactory extends EllipseFactory
|
||||
use Intervention\Image\Geometry\Circle;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Interfaces\DrawableFactoryInterface;
|
||||
use Intervention\Image\Interfaces\DrawableInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class CircleFactory implements DrawableFactoryInterface
|
||||
{
|
||||
protected Circle $circle;
|
||||
|
||||
/**
|
||||
* Create new factory instance
|
||||
*
|
||||
* @param PointInterface $pivot
|
||||
* @param null|callable|Circle $init
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
protected PointInterface $pivot = new Point(),
|
||||
null|callable|Circle $init = null,
|
||||
) {
|
||||
$this->circle = is_a($init, Circle::class) ? $init : new Circle(0, $pivot);
|
||||
|
||||
if (is_callable($init)) {
|
||||
$init($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableFactoryInterface::create()
|
||||
*/
|
||||
public function create(): DrawableInterface
|
||||
{
|
||||
return $this->circle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the radius of the circle to be produced
|
||||
*
|
||||
@@ -14,7 +50,7 @@ class CircleFactory extends EllipseFactory
|
||||
*/
|
||||
public function radius(int $radius): self
|
||||
{
|
||||
$this->ellipse->setSize($radius * 2, $radius * 2);
|
||||
$this->circle->setSize($radius * 2, $radius * 2);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -27,8 +63,45 @@ class CircleFactory extends EllipseFactory
|
||||
*/
|
||||
public function diameter(int $diameter): self
|
||||
{
|
||||
$this->ellipse->setSize($diameter, $diameter);
|
||||
$this->circle->setSize($diameter, $diameter);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background color of the circle to be produced
|
||||
*
|
||||
* @param mixed $color
|
||||
* @return CircleFactory
|
||||
*/
|
||||
public function background(mixed $color): self
|
||||
{
|
||||
$this->circle->setBackgroundColor($color);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the border color & border size of the ellipse to be produced
|
||||
*
|
||||
* @param mixed $color
|
||||
* @param int $size
|
||||
* @return CircleFactory
|
||||
*/
|
||||
public function border(mixed $color, int $size = 1): self
|
||||
{
|
||||
$this->circle->setBorder($color, $size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce the circle
|
||||
*
|
||||
* @return Circle
|
||||
*/
|
||||
public function __invoke(): Circle
|
||||
{
|
||||
return $this->circle;
|
||||
}
|
||||
}
|
||||
|
69
src/Geometry/Factories/Drawable.php
Normal file
69
src/Geometry/Factories/Drawable.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
class Drawable
|
||||
{
|
||||
/**
|
||||
* Creeate BezierFactory statically
|
||||
*
|
||||
* @return BezierFactory
|
||||
*/
|
||||
public static function bezier(): BezierFactory
|
||||
{
|
||||
return new BezierFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creeate CircleFactory statically
|
||||
*
|
||||
* @return CircleFactory
|
||||
*/
|
||||
public static function circle(): CircleFactory
|
||||
{
|
||||
return new CircleFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Create EllipseFactory statically
|
||||
*
|
||||
* @return EllipseFactory
|
||||
*/
|
||||
public static function ellipse(): EllipseFactory
|
||||
{
|
||||
return new EllipseFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creeate LineFactory statically
|
||||
*
|
||||
* @return LineFactory
|
||||
*/
|
||||
public static function line(): LineFactory
|
||||
{
|
||||
return new LineFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creeate PolygonFactory statically
|
||||
*
|
||||
* @return PolygonFactory
|
||||
*/
|
||||
public static function polygon(): PolygonFactory
|
||||
{
|
||||
return new PolygonFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creeate RectangleFactory statically
|
||||
*
|
||||
* @return RectangleFactory
|
||||
*/
|
||||
public static function rectangle(): RectangleFactory
|
||||
{
|
||||
return new RectangleFactory();
|
||||
}
|
||||
}
|
@@ -6,20 +6,25 @@ namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
use Intervention\Image\Geometry\Ellipse;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Interfaces\DrawableFactoryInterface;
|
||||
use Intervention\Image\Interfaces\DrawableInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class EllipseFactory
|
||||
class EllipseFactory implements DrawableFactoryInterface
|
||||
{
|
||||
protected Ellipse $ellipse;
|
||||
|
||||
/**
|
||||
* Create new factory instance
|
||||
*
|
||||
* @param Point $pivot
|
||||
* @param callable|Ellipse $init
|
||||
* @param PointInterface $pivot
|
||||
* @param null|callable|Ellipse $init
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(protected Point $pivot, callable|Ellipse $init)
|
||||
{
|
||||
public function __construct(
|
||||
protected PointInterface $pivot = new Point(),
|
||||
null|callable|Ellipse $init = null,
|
||||
) {
|
||||
$this->ellipse = is_a($init, Ellipse::class) ? $init : new Ellipse(0, 0, $pivot);
|
||||
|
||||
if (is_callable($init)) {
|
||||
@@ -27,6 +32,16 @@ class EllipseFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableFactoryInterface::create()
|
||||
*/
|
||||
public function create(): DrawableInterface
|
||||
{
|
||||
return $this->ellipse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the ellipse to be produced
|
||||
*
|
||||
|
@@ -6,18 +6,20 @@ namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Line;
|
||||
use Intervention\Image\Interfaces\DrawableFactoryInterface;
|
||||
use Intervention\Image\Interfaces\DrawableInterface;
|
||||
|
||||
class LineFactory
|
||||
class LineFactory implements DrawableFactoryInterface
|
||||
{
|
||||
protected Line $line;
|
||||
|
||||
/**
|
||||
* Create the factory instance
|
||||
*
|
||||
* @param callable|Line $init
|
||||
* @param null|callable|Line $init
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(callable|Line $init)
|
||||
public function __construct(null|callable|Line $init = null)
|
||||
{
|
||||
$this->line = is_a($init, Line::class) ? $init : new Line(new Point(), new Point());
|
||||
|
||||
@@ -26,6 +28,16 @@ class LineFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableFactoryInterface::create()
|
||||
*/
|
||||
public function create(): DrawableInterface
|
||||
{
|
||||
return $this->line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color of the line to be produced
|
||||
*
|
||||
|
@@ -6,18 +6,20 @@ namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Polygon;
|
||||
use Intervention\Image\Interfaces\DrawableFactoryInterface;
|
||||
use Intervention\Image\Interfaces\DrawableInterface;
|
||||
|
||||
class PolygonFactory
|
||||
class PolygonFactory implements DrawableFactoryInterface
|
||||
{
|
||||
protected Polygon $polygon;
|
||||
|
||||
/**
|
||||
* Create new factory instance
|
||||
*
|
||||
* @param callable|Polygon $init
|
||||
* @param null|callable|Polygon $init
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(callable|Polygon $init)
|
||||
public function __construct(null|callable|Polygon $init = null)
|
||||
{
|
||||
$this->polygon = is_a($init, Polygon::class) ? $init : new Polygon([]);
|
||||
|
||||
@@ -26,6 +28,16 @@ class PolygonFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableFactoryInterface::create()
|
||||
*/
|
||||
public function create(): DrawableInterface
|
||||
{
|
||||
return $this->polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the polygon to be produced
|
||||
*
|
||||
|
@@ -6,20 +6,25 @@ namespace Intervention\Image\Geometry\Factories;
|
||||
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Geometry\Rectangle;
|
||||
use Intervention\Image\Interfaces\DrawableFactoryInterface;
|
||||
use Intervention\Image\Interfaces\DrawableInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class RectangleFactory
|
||||
class RectangleFactory implements DrawableFactoryInterface
|
||||
{
|
||||
protected Rectangle $rectangle;
|
||||
|
||||
/**
|
||||
* Create new instance
|
||||
*
|
||||
* @param Point $pivot
|
||||
* @param callable|Rectangle $init
|
||||
* @param PointInterface $pivot
|
||||
* @param null|callable|Rectangle $init
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(protected Point $pivot, callable|Rectangle $init)
|
||||
{
|
||||
public function __construct(
|
||||
protected PointInterface $pivot = new Point(),
|
||||
null|callable|Rectangle $init = null,
|
||||
) {
|
||||
$this->rectangle = is_a($init, Rectangle::class) ? $init : new Rectangle(0, 0, $pivot);
|
||||
|
||||
if (is_callable($init)) {
|
||||
@@ -27,6 +32,16 @@ class RectangleFactory
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableFactoryInterface::create()
|
||||
*/
|
||||
public function create(): DrawableInterface
|
||||
{
|
||||
return $this->rectangle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the rectangle to be produced
|
||||
*
|
||||
|
@@ -17,14 +17,14 @@ class Line implements DrawableInterface
|
||||
/**
|
||||
* Create new line instance
|
||||
*
|
||||
* @param Point $start
|
||||
* @param Point $end
|
||||
* @param PointInterface $start
|
||||
* @param PointInterface $end
|
||||
* @param int $width
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
protected Point $start,
|
||||
protected Point $end,
|
||||
protected PointInterface $start,
|
||||
protected PointInterface $end,
|
||||
protected int $width = 1
|
||||
) {
|
||||
}
|
||||
@@ -39,6 +39,18 @@ class Line implements DrawableInterface
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DrawableInterface::setPosition()
|
||||
*/
|
||||
public function setPosition(PointInterface $position): DrawableInterface
|
||||
{
|
||||
$this->start = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return line width
|
||||
*
|
||||
@@ -65,9 +77,9 @@ class Line implements DrawableInterface
|
||||
/**
|
||||
* Get starting point of line
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function start(): Point
|
||||
public function start(): PointInterface
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
@@ -75,9 +87,9 @@ class Line implements DrawableInterface
|
||||
/**
|
||||
* get end point of line
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function end(): Point
|
||||
public function end(): PointInterface
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
@@ -85,10 +97,10 @@ class Line implements DrawableInterface
|
||||
/**
|
||||
* Set starting point of line
|
||||
*
|
||||
* @param Point $start
|
||||
* @param PointInterface $start
|
||||
* @return Line
|
||||
*/
|
||||
public function setStart(Point $start): self
|
||||
public function setStart(PointInterface $start): self
|
||||
{
|
||||
$this->start = $start;
|
||||
|
||||
@@ -128,10 +140,10 @@ class Line implements DrawableInterface
|
||||
/**
|
||||
* Set end point of line
|
||||
*
|
||||
* @param Point $end
|
||||
* @param PointInterface $end
|
||||
* @return Line
|
||||
*/
|
||||
public function setEnd(Point $end): self
|
||||
public function setEnd(PointInterface $end): self
|
||||
{
|
||||
$this->end = $end;
|
||||
|
||||
|
@@ -22,9 +22,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets X coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $x
|
||||
* @see PointInterface::setX()
|
||||
*/
|
||||
public function setX(int $x): self
|
||||
{
|
||||
@@ -34,9 +34,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get X coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int
|
||||
* @see PointInterface::x()
|
||||
*/
|
||||
public function x(): int
|
||||
{
|
||||
@@ -44,9 +44,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Y coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $y
|
||||
* @see PointInterface::setY()
|
||||
*/
|
||||
public function setY(int $y): self
|
||||
{
|
||||
@@ -56,9 +56,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Y coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int
|
||||
* @see PointInterface::y()
|
||||
*/
|
||||
public function y(): int
|
||||
{
|
||||
@@ -66,9 +66,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Move X coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $value
|
||||
* @see PointInterface::moveX()
|
||||
*/
|
||||
public function moveX(int $value): self
|
||||
{
|
||||
@@ -78,9 +78,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Move Y coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $value
|
||||
* @see PointInterface::moveY()
|
||||
*/
|
||||
public function moveY(int $value): self
|
||||
{
|
||||
@@ -89,17 +89,20 @@ class Point implements PointInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see PointInterface::move()
|
||||
*/
|
||||
public function move(int $x, int $y): self
|
||||
{
|
||||
return $this->moveX($x)->moveY($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets both X and Y coordinate
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @return Point
|
||||
* @see PointInterface::setPosition()
|
||||
*/
|
||||
public function setPosition(int $x, int $y): self
|
||||
{
|
||||
@@ -110,11 +113,9 @@ class Point implements PointInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate point ccw around pivot
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param float $angle
|
||||
* @param PointInterface $pivot
|
||||
* @return Point
|
||||
* @see PointInterface::rotate()
|
||||
*/
|
||||
public function rotate(float $angle, PointInterface $pivot): self
|
||||
{
|
||||
|
@@ -15,8 +15,8 @@ use Intervention\Image\Interfaces\DrawableInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
/**
|
||||
* @implements IteratorAggregate<Point>
|
||||
* @implements ArrayAccess<int, Point>
|
||||
* @implements IteratorAggregate<PointInterface>
|
||||
* @implements ArrayAccess<int, PointInterface>
|
||||
*/
|
||||
class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInterface
|
||||
{
|
||||
@@ -26,7 +26,7 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Create new polygon instance
|
||||
*
|
||||
* @param array<Point> $points
|
||||
* @param array<PointInterface> $points
|
||||
* @param PointInterface $pivot
|
||||
* @return void
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Implement iteration through all points of polygon
|
||||
*
|
||||
* @return Traversable<Point>
|
||||
* @return Traversable<PointInterface>
|
||||
*/
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
@@ -69,10 +69,10 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Change pivot point to given point
|
||||
*
|
||||
* @param Point $pivot
|
||||
* @param PointInterface $pivot
|
||||
* @return Polygon
|
||||
*/
|
||||
public function setPivot(Point $pivot): self
|
||||
public function setPivot(PointInterface $pivot): self
|
||||
{
|
||||
$this->pivot = $pivot;
|
||||
|
||||
@@ -82,9 +82,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return first point of polygon
|
||||
*
|
||||
* @return ?Point
|
||||
* @return ?PointInterface
|
||||
*/
|
||||
public function first(): ?Point
|
||||
public function first(): ?PointInterface
|
||||
{
|
||||
if ($point = reset($this->points)) {
|
||||
return $point;
|
||||
@@ -96,9 +96,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return last point of polygon
|
||||
*
|
||||
* @return ?Point
|
||||
* @return ?PointInterface
|
||||
*/
|
||||
public function last(): ?Point
|
||||
public function last(): ?PointInterface
|
||||
{
|
||||
if ($point = end($this->points)) {
|
||||
return $point;
|
||||
@@ -132,7 +132,7 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
* Return point at given offset
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function offsetGet($offset): mixed
|
||||
{
|
||||
@@ -143,7 +143,7 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
* Set point at given offset
|
||||
*
|
||||
* @param mixed $offset
|
||||
* @param Point $value
|
||||
* @param PointInterface $value
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value): void
|
||||
@@ -165,10 +165,10 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Add given point to polygon
|
||||
*
|
||||
* @param Point $point
|
||||
* @param PointInterface $point
|
||||
* @return Polygon
|
||||
*/
|
||||
public function addPoint(Point $point): self
|
||||
public function addPoint(PointInterface $point): self
|
||||
{
|
||||
$this->points[] = $point;
|
||||
|
||||
@@ -198,9 +198,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return most left point of all points in polygon
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function mostLeftPoint(): Point
|
||||
public function mostLeftPoint(): PointInterface
|
||||
{
|
||||
$points = [];
|
||||
foreach ($this->points as $point) {
|
||||
@@ -220,9 +220,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return most right point in polygon
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function mostRightPoint(): Point
|
||||
public function mostRightPoint(): PointInterface
|
||||
{
|
||||
$points = [];
|
||||
foreach ($this->points as $point) {
|
||||
@@ -242,9 +242,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return most top point in polygon
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function mostTopPoint(): Point
|
||||
public function mostTopPoint(): PointInterface
|
||||
{
|
||||
$points = [];
|
||||
foreach ($this->points as $point) {
|
||||
@@ -264,9 +264,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return most bottom point in polygon
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function mostBottomPoint(): Point
|
||||
public function mostBottomPoint(): PointInterface
|
||||
{
|
||||
$points = [];
|
||||
foreach ($this->points as $point) {
|
||||
@@ -286,9 +286,9 @@ class Polygon implements IteratorAggregate, Countable, ArrayAccess, DrawableInte
|
||||
/**
|
||||
* Return point in absolute center of the polygon
|
||||
*
|
||||
* @return Point
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function centerPoint(): Point
|
||||
public function centerPoint(): PointInterface
|
||||
{
|
||||
return new Point(
|
||||
$this->mostRightPoint()->x() - (intval(round($this->width() / 2))),
|
||||
|
39
src/Interfaces/DrawableFactoryInterface.php
Normal file
39
src/Interfaces/DrawableFactoryInterface.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Interfaces;
|
||||
|
||||
interface DrawableFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Create the end product of the factory
|
||||
*
|
||||
* @return DrawableInterface
|
||||
*/
|
||||
public function create(): DrawableInterface;
|
||||
|
||||
/**
|
||||
* Create the end product by invoking the factory
|
||||
*
|
||||
* @return DrawableInterface
|
||||
*/
|
||||
public function __invoke(): DrawableInterface;
|
||||
|
||||
/**
|
||||
* Define the background color of the drawable object
|
||||
*
|
||||
* @param mixed $color
|
||||
* @return DrawableFactoryInterface
|
||||
*/
|
||||
public function background(mixed $color): self;
|
||||
|
||||
/**
|
||||
* Set the border size & color of the drawable object to be produced
|
||||
*
|
||||
* @param mixed $color
|
||||
* @param int $size
|
||||
* @return DrawableFactoryInterface
|
||||
*/
|
||||
public function border(mixed $color, int $size = 1): self;
|
||||
}
|
@@ -20,6 +20,45 @@ interface PointInterface
|
||||
*/
|
||||
public function y(): int;
|
||||
|
||||
/**
|
||||
* Set x position
|
||||
*
|
||||
* @param int $x
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function setX(int $x): self;
|
||||
|
||||
/**
|
||||
* Set y position
|
||||
*
|
||||
* @param int $y
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function setY(int $y): self;
|
||||
|
||||
/**
|
||||
* Move X coordinate
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
public function moveX(int $value): self;
|
||||
|
||||
/**
|
||||
* Move Y coordinate
|
||||
*
|
||||
* @param int $value
|
||||
*/
|
||||
public function moveY(int $value): self;
|
||||
|
||||
/**
|
||||
* Move position of current point by given coordinates
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function move(int $x, int $y): self;
|
||||
|
||||
/**
|
||||
* Set position of point
|
||||
*
|
||||
@@ -28,4 +67,13 @@ interface PointInterface
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function setPosition(int $x, int $y): self;
|
||||
|
||||
/**
|
||||
* Rotate point counter clock wise around given pivot point
|
||||
*
|
||||
* @param float $angle
|
||||
* @param PointInterface $pivot
|
||||
* @return PointInterface
|
||||
*/
|
||||
public function rotate(float $angle, self $pivot): self;
|
||||
}
|
||||
|
@@ -5,13 +5,13 @@ declare(strict_types=1);
|
||||
namespace Intervention\Image\Modifiers;
|
||||
|
||||
use Intervention\Image\Drivers\SpecializableModifier;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class FillModifier extends SpecializableModifier
|
||||
{
|
||||
public function __construct(
|
||||
public mixed $color,
|
||||
public ?Point $position = null
|
||||
public ?PointInterface $position = null
|
||||
) {
|
||||
}
|
||||
|
||||
|
@@ -10,12 +10,13 @@ use Intervention\Image\Exceptions\RuntimeException;
|
||||
use Intervention\Image\Geometry\Point;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\FontInterface;
|
||||
use Intervention\Image\Interfaces\PointInterface;
|
||||
|
||||
class TextModifier extends SpecializableModifier
|
||||
{
|
||||
public function __construct(
|
||||
public string $text,
|
||||
public Point $position,
|
||||
public PointInterface $position,
|
||||
public FontInterface $font
|
||||
) {
|
||||
}
|
||||
@@ -69,7 +70,7 @@ class TextModifier extends SpecializableModifier
|
||||
* Return array of offset points to draw text stroke effect below the actual text
|
||||
*
|
||||
* @param FontInterface $font
|
||||
* @return array<Point>
|
||||
* @return array<PointInterface>
|
||||
*/
|
||||
protected function strokeOffsets(FontInterface $font): array
|
||||
{
|
||||
|
@@ -75,10 +75,10 @@ class Line implements IteratorAggregate, Countable
|
||||
/**
|
||||
* Set position of current line
|
||||
*
|
||||
* @param Point $point
|
||||
* @param PointInterface $point
|
||||
* @return Line
|
||||
*/
|
||||
public function setPosition(Point $point): self
|
||||
public function setPosition(PointInterface $point): self
|
||||
{
|
||||
$this->position = $point;
|
||||
|
||||
|
47
tests/Unit/Geometry/Factories/DrawableTest.php
Normal file
47
tests/Unit/Geometry/Factories/DrawableTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Intervention\Image\Tests\Unit\Geometry\Factories;
|
||||
|
||||
use Intervention\Image\Geometry\Factories\BezierFactory;
|
||||
use Intervention\Image\Geometry\Factories\CircleFactory;
|
||||
use Intervention\Image\Geometry\Factories\Drawable;
|
||||
use Intervention\Image\Geometry\Factories\EllipseFactory;
|
||||
use Intervention\Image\Geometry\Factories\LineFactory;
|
||||
use Intervention\Image\Geometry\Factories\PolygonFactory;
|
||||
use Intervention\Image\Geometry\Factories\RectangleFactory;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
final class DrawableTest extends BaseTestCase
|
||||
{
|
||||
public function testBezier(): void
|
||||
{
|
||||
$this->assertInstanceOf(BezierFactory::class, Drawable::bezier());
|
||||
}
|
||||
|
||||
public function testCircle(): void
|
||||
{
|
||||
$this->assertInstanceOf(CircleFactory::class, Drawable::circle());
|
||||
}
|
||||
|
||||
public function testEllipse(): void
|
||||
{
|
||||
$this->assertInstanceOf(EllipseFactory::class, Drawable::ellipse());
|
||||
}
|
||||
|
||||
public function testLine(): void
|
||||
{
|
||||
$this->assertInstanceOf(LineFactory::class, Drawable::line());
|
||||
}
|
||||
|
||||
public function testPolygon(): void
|
||||
{
|
||||
$this->assertInstanceOf(PolygonFactory::class, Drawable::polygon());
|
||||
}
|
||||
|
||||
public function testRectangle(): void
|
||||
{
|
||||
$this->assertInstanceOf(RectangleFactory::class, Drawable::rectangle());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user