1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 18:02:45 +02:00

Rename Rectangle::alignPivot() to movePivot()

This commit is contained in:
Oliver Vogel
2022-07-19 19:28:32 +02:00
parent abd8376257
commit 2c4a6921d8
6 changed files with 29 additions and 31 deletions

View File

@@ -54,8 +54,8 @@ class PlaceModifier implements ModifierInterface
protected function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface protected function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface
{ {
$image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y); $image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y);
$watermark_size = $watermark->getSize()->alignPivot($this->position); $watermark_size = $watermark->getSize()->movePivot($this->position);
return $image_size->getRelativePositionTo($watermark_size); return $image_size->getRelativePositionTo($watermark_size);
} }

View File

@@ -47,8 +47,8 @@ class PlaceModifier implements ModifierInterface
protected function getPosition(ImageInterface $image, Image $watermark): PointInterface protected function getPosition(ImageInterface $image, Image $watermark): PointInterface
{ {
$image_size = $image->getSize()->alignPivot($this->position, $this->offset_x, $this->offset_y); $image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y);
$watermark_size = $watermark->getSize()->alignPivot($this->position); $watermark_size = $watermark->getSize()->movePivot($this->position);
return $image_size->getRelativePositionTo($watermark_size); return $image_size->getRelativePositionTo($watermark_size);
} }

View File

@@ -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. * and moves point automatically by offset.
* *
* @param string $position * @param string $position
@@ -57,8 +57,7 @@ class Rectangle extends Polygon implements SizeInterface
* @param int $offset_y * @param int $offset_y
* @return Rectangle * @return Rectangle
*/ */
// TODO: rename method to movePivot public function movePivot(string $position, int $offset_x = 0, int $offset_y = 0): self
public function alignPivot(string $position, int $offset_x = 0, int $offset_y = 0): self
{ {
switch (strtolower($position)) { switch (strtolower($position)) {
case 'top': case 'top':
@@ -136,13 +135,12 @@ class Rectangle extends Polygon implements SizeInterface
return $this; return $this;
} }
// TODO: rename to alignPivot
public function alignPivotTo(SizeInterface $size, string $position): self public function alignPivotTo(SizeInterface $size, string $position): self
{ {
$reference = new self($size->width(), $size->height()); $reference = new self($size->width(), $size->height());
$reference->alignPivot($position); $reference->movePivot($position);
$this->alignPivot($position)->withPivot( $this->movePivot($position)->withPivot(
$reference->getRelativePositionTo($this) $reference->getRelativePositionTo($this)
); );

View File

@@ -241,7 +241,7 @@ class Resizer
public function crop(SizeInterface $size, string $position = 'top-left'): SizeInterface public function crop(SizeInterface $size, string $position = 'top-left'): SizeInterface
{ {
return $this->resize($size)->alignPivotTo( return $this->resize($size)->alignPivotTo(
$size->alignPivot($position), $size->movePivot($position),
$position $position
); );
} }

View File

@@ -14,7 +14,7 @@ interface SizeInterface
public function fitsInto(SizeInterface $size): bool; public function fitsInto(SizeInterface $size): bool;
public function isLandscape(): bool; public function isLandscape(): bool;
public function isPortrait(): 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 alignPivotTo(SizeInterface $size, string $position): SizeInterface;
public function getRelativePositionTo(SizeInterface $size): PointInterface; public function getRelativePositionTo(SizeInterface $size): PointInterface;
public function resize(?int $width = null, ?int $height = null): SizeInterface; public function resize(?int $width = null, ?int $height = null): SizeInterface;

View File

@@ -123,39 +123,39 @@ class RectangleTest extends TestCase
$this->assertEquals(0, $box->pivot()->getX()); $this->assertEquals(0, $box->pivot()->getX());
$this->assertEquals(0, $box->pivot()->getY()); $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()->getX());
$this->assertEquals(3, $box->pivot()->getY()); $this->assertEquals(3, $box->pivot()->getY());
$box->alignPivot('top', 3, 3); $box->movePivot('top', 3, 3);
$this->assertEquals(320, $box->pivot()->getX()); $this->assertEquals(320, $box->pivot()->getX());
$this->assertEquals(3, $box->pivot()->getY()); $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(637, $box->pivot()->getX());
$this->assertEquals(3, $box->pivot()->getY()); $this->assertEquals(3, $box->pivot()->getY());
$box->alignPivot('left', 3, 3); $box->movePivot('left', 3, 3);
$this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(3, $box->pivot()->getX());
$this->assertEquals(240, $box->pivot()->getY()); $this->assertEquals(240, $box->pivot()->getY());
$box->alignPivot('center', 3, 3); $box->movePivot('center', 3, 3);
$this->assertEquals(323, $box->pivot()->getX()); $this->assertEquals(323, $box->pivot()->getX());
$this->assertEquals(243, $box->pivot()->getY()); $this->assertEquals(243, $box->pivot()->getY());
$box->alignPivot('right', 3, 3); $box->movePivot('right', 3, 3);
$this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(637, $box->pivot()->getX());
$this->assertEquals(240, $box->pivot()->getY()); $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(3, $box->pivot()->getX());
$this->assertEquals(477, $box->pivot()->getY()); $this->assertEquals(477, $box->pivot()->getY());
$box->alignPivot('bottom', 3, 3); $box->movePivot('bottom', 3, 3);
$this->assertEquals(320, $box->pivot()->getX()); $this->assertEquals(320, $box->pivot()->getX());
$this->assertEquals(477, $box->pivot()->getY()); $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(637, $box->pivot()->getX());
$this->assertEquals(477, $box->pivot()->getY()); $this->assertEquals(477, $box->pivot()->getY());
@@ -199,40 +199,40 @@ class RectangleTest extends TestCase
{ {
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$input = new Rectangle(200, 100); $input = new Rectangle(200, 100);
$container->alignPivot('top-left'); $container->movePivot('top-left');
$input->alignPivot('top-left'); $input->movePivot('top-left');
$pos = $container->getRelativePositionTo($input); $pos = $container->getRelativePositionTo($input);
$this->assertEquals(0, $pos->getX()); $this->assertEquals(0, $pos->getX());
$this->assertEquals(0, $pos->getY()); $this->assertEquals(0, $pos->getY());
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$input = new Rectangle(200, 100); $input = new Rectangle(200, 100);
$container->alignPivot('center'); $container->movePivot('center');
$input->alignPivot('top-left'); $input->movePivot('top-left');
$pos = $container->getRelativePositionTo($input); $pos = $container->getRelativePositionTo($input);
$this->assertEquals(400, $pos->getX()); $this->assertEquals(400, $pos->getX());
$this->assertEquals(300, $pos->getY()); $this->assertEquals(300, $pos->getY());
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$input = new Rectangle(200, 100); $input = new Rectangle(200, 100);
$container->alignPivot('bottom-right'); $container->movePivot('bottom-right');
$input->alignPivot('top-right'); $input->movePivot('top-right');
$pos = $container->getRelativePositionTo($input); $pos = $container->getRelativePositionTo($input);
$this->assertEquals(600, $pos->getX()); $this->assertEquals(600, $pos->getX());
$this->assertEquals(600, $pos->getY()); $this->assertEquals(600, $pos->getY());
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$input = new Rectangle(200, 100); $input = new Rectangle(200, 100);
$container->alignPivot('center'); $container->movePivot('center');
$input->alignPivot('center'); $input->movePivot('center');
$pos = $container->getRelativePositionTo($input); $pos = $container->getRelativePositionTo($input);
$this->assertEquals(300, $pos->getX()); $this->assertEquals(300, $pos->getX());
$this->assertEquals(250, $pos->getY()); $this->assertEquals(250, $pos->getY());
$container = new Rectangle(100, 200); $container = new Rectangle(100, 200);
$input = new Rectangle(100, 100); $input = new Rectangle(100, 100);
$container->alignPivot('center'); $container->movePivot('center');
$input->alignPivot('center'); $input->movePivot('center');
$pos = $container->getRelativePositionTo($input); $pos = $container->getRelativePositionTo($input);
$this->assertEquals(0, $pos->getX()); $this->assertEquals(0, $pos->getX());
$this->assertEquals(50, $pos->getY()); $this->assertEquals(50, $pos->getY());