diff --git a/src/Drivers/Gd/Modifiers/PlaceModifier.php b/src/Drivers/Gd/Modifiers/PlaceModifier.php index b90233c9..1c35c435 100644 --- a/src/Drivers/Gd/Modifiers/PlaceModifier.php +++ b/src/Drivers/Gd/Modifiers/PlaceModifier.php @@ -54,8 +54,8 @@ class PlaceModifier implements ModifierInterface protected function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface { - $image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y); - $watermark_size = $watermark->getSize()->alignPivot($this->position); + $image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y); + $watermark_size = $watermark->getSize()->movePivot($this->position); return $image_size->getRelativePositionTo($watermark_size); } diff --git a/src/Drivers/Imagick/Modifiers/PlaceModifier.php b/src/Drivers/Imagick/Modifiers/PlaceModifier.php index 894ba153..d6181c42 100644 --- a/src/Drivers/Imagick/Modifiers/PlaceModifier.php +++ b/src/Drivers/Imagick/Modifiers/PlaceModifier.php @@ -47,8 +47,8 @@ class PlaceModifier implements ModifierInterface protected function getPosition(ImageInterface $image, Image $watermark): PointInterface { - $image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y); - $watermark_size = $watermark->getSize()->alignPivot($this->position); + $image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y); + $watermark_size = $watermark->getSize()->movePivot($this->position); return $image_size->getRelativePositionTo($watermark_size); } diff --git a/src/Geometry/Rectangle.php b/src/Geometry/Rectangle.php index 088ed268..57f9dc0b 100644 --- a/src/Geometry/Rectangle.php +++ b/src/Geometry/Rectangle.php @@ -49,7 +49,7 @@ class Rectangle extends Polygon implements SizeInterface } /** - * Aligns current size's pivot point to given position + * Move current pivot of current rectangle to given position * and moves point automatically by offset. * * @param string $position @@ -57,8 +57,7 @@ class Rectangle extends Polygon implements SizeInterface * @param int $offset_y * @return Rectangle */ - // TODO: rename method to movePivot - public function alignPivot(string $position, int $offset_x = 0, int $offset_y = 0): self + public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): self { switch (strtolower($position)) { case 'top': @@ -136,13 +135,12 @@ class Rectangle extends Polygon implements SizeInterface return $this; } - // TODO: rename to alignPivot public function alignPivotTo(SizeInterface $size, string $position): self { $reference = new self($size->width(), $size->height()); - $reference->alignPivot($position); + $reference->movePivot($position); - $this->alignPivot($position)->withPivot( + $this->movePivot($position)->withPivot( $reference->getRelativePositionTo($this) ); diff --git a/src/Geometry/Tools/Resizer.php b/src/Geometry/Tools/Resizer.php index e90d87b5..62f0f0db 100644 --- a/src/Geometry/Tools/Resizer.php +++ b/src/Geometry/Tools/Resizer.php @@ -241,7 +241,7 @@ class Resizer public function crop(SizeInterface $size, string $position = 'top-left'): SizeInterface { return $this->resize($size)->alignPivotTo( - $size->alignPivot($position), + $size->movePivot($position), $position ); } diff --git a/src/Interfaces/SizeInterface.php b/src/Interfaces/SizeInterface.php index 94579afa..c8a29b8e 100644 --- a/src/Interfaces/SizeInterface.php +++ b/src/Interfaces/SizeInterface.php @@ -14,7 +14,7 @@ interface SizeInterface public function fitsInto(SizeInterface $size): bool; public function isLandscape(): bool; public function isPortrait(): bool; - public function alignPivot(string $position, int $offset_x = 0, int $offset_y = 0): SizeInterface; + public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): SizeInterface; public function alignPivotTo(SizeInterface $size, string $position): SizeInterface; public function getRelativePositionTo(SizeInterface $size): PointInterface; public function resize(?int $width = null, ?int $height = null): SizeInterface; diff --git a/tests/Geometry/RectangleTest.php b/tests/Geometry/RectangleTest.php index 9c42922e..ddc9e102 100644 --- a/tests/Geometry/RectangleTest.php +++ b/tests/Geometry/RectangleTest.php @@ -123,39 +123,39 @@ class RectangleTest extends TestCase $this->assertEquals(0, $box->pivot()->getX()); $this->assertEquals(0, $box->pivot()->getY()); - $box->alignPivot('top-left', 3, 3); + $box->movePivot('top-left', 3, 3); $this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(3, $box->pivot()->getY()); - $box->alignPivot('top', 3, 3); + $box->movePivot('top', 3, 3); $this->assertEquals(320, $box->pivot()->getX()); $this->assertEquals(3, $box->pivot()->getY()); - $box->alignPivot('top-right', 3, 3); + $box->movePivot('top-right', 3, 3); $this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(3, $box->pivot()->getY()); - $box->alignPivot('left', 3, 3); + $box->movePivot('left', 3, 3); $this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(240, $box->pivot()->getY()); - $box->alignPivot('center', 3, 3); + $box->movePivot('center', 3, 3); $this->assertEquals(323, $box->pivot()->getX()); $this->assertEquals(243, $box->pivot()->getY()); - $box->alignPivot('right', 3, 3); + $box->movePivot('right', 3, 3); $this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(240, $box->pivot()->getY()); - $box->alignPivot('bottom-left', 3, 3); + $box->movePivot('bottom-left', 3, 3); $this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(477, $box->pivot()->getY()); - $box->alignPivot('bottom', 3, 3); + $box->movePivot('bottom', 3, 3); $this->assertEquals(320, $box->pivot()->getX()); $this->assertEquals(477, $box->pivot()->getY()); - $result = $box->alignPivot('bottom-right', 3, 3); + $result = $box->movePivot('bottom-right', 3, 3); $this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(477, $box->pivot()->getY()); @@ -199,40 +199,40 @@ class RectangleTest extends TestCase { $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); - $container->alignPivot('top-left'); - $input->alignPivot('top-left'); + $container->movePivot('top-left'); + $input->movePivot('top-left'); $pos = $container->getRelativePositionTo($input); $this->assertEquals(0, $pos->getX()); $this->assertEquals(0, $pos->getY()); $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); - $container->alignPivot('center'); - $input->alignPivot('top-left'); + $container->movePivot('center'); + $input->movePivot('top-left'); $pos = $container->getRelativePositionTo($input); $this->assertEquals(400, $pos->getX()); $this->assertEquals(300, $pos->getY()); $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); - $container->alignPivot('bottom-right'); - $input->alignPivot('top-right'); + $container->movePivot('bottom-right'); + $input->movePivot('top-right'); $pos = $container->getRelativePositionTo($input); $this->assertEquals(600, $pos->getX()); $this->assertEquals(600, $pos->getY()); $container = new Rectangle(800, 600); $input = new Rectangle(200, 100); - $container->alignPivot('center'); - $input->alignPivot('center'); + $container->movePivot('center'); + $input->movePivot('center'); $pos = $container->getRelativePositionTo($input); $this->assertEquals(300, $pos->getX()); $this->assertEquals(250, $pos->getY()); $container = new Rectangle(100, 200); $input = new Rectangle(100, 100); - $container->alignPivot('center'); - $input->alignPivot('center'); + $container->movePivot('center'); + $input->movePivot('center'); $pos = $container->getRelativePositionTo($input); $this->assertEquals(0, $pos->getX()); $this->assertEquals(50, $pos->getY());