1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 17:19:50 +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
{
$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);
}

View File

@@ -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);
}

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.
*
* @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)
);

View File

@@ -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
);
}

View File

@@ -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;

View File

@@ -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());