From f8f3baca0e78145ec0bf5807191667619405626a Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Wed, 20 Jul 2022 16:45:18 +0200 Subject: [PATCH] Consolidate method naming --- src/Drivers/Abstract/AbstractFont.php | 4 +- .../Modifiers/AbstractFitModifier.php | 4 +- src/Drivers/Gd/Font.php | 4 +- src/Drivers/Gd/Modifiers/FillModifier.php | 4 +- src/Drivers/Gd/Modifiers/FitModifier.php | 20 +-- src/Drivers/Gd/Modifiers/ResizeModifier.php | 20 +-- src/Drivers/Imagick/Image.php | 4 +- src/Drivers/Imagick/Modifiers/FitModifier.php | 12 +- .../Imagick/Modifiers/PixelateModifier.php | 6 +- .../Imagick/Modifiers/ResizeModifier.php | 4 +- src/Geometry/Polygon.php | 32 ++-- src/Geometry/Rectangle.php | 50 +++--- src/Geometry/Tools/RectangleResizer.php | 84 ++++----- src/Interfaces/SizeInterface.php | 12 +- src/Typography/Line.php | 2 +- src/Typography/TextBlock.php | 2 +- tests/Drivers/Abstract/AbstractImageTest.php | 8 +- .../Modifiers/AbstractFitModifierTest.php | 16 +- .../Modifiers/AbstractPadModifierTest.php | 16 +- tests/Drivers/Gd/FrameTest.php | 4 +- tests/Geometry/PolygonTest.php | 12 +- tests/Geometry/RectangleResizerTest.php | 168 +++++++++--------- tests/Geometry/RectangleTest.php | 82 ++++----- tests/Typography/TextBlockTest.php | 8 +- 24 files changed, 289 insertions(+), 289 deletions(-) diff --git a/src/Drivers/Abstract/AbstractFont.php b/src/Drivers/Abstract/AbstractFont.php index 6f2530a3..94ef0c4d 100644 --- a/src/Drivers/Abstract/AbstractFont.php +++ b/src/Drivers/Abstract/AbstractFont.php @@ -121,11 +121,11 @@ abstract class AbstractFont implements FontInterface public function capHeight(): int { - return $this->getBoxSize('T')->height(); + return $this->getBoxSize('T')->getHeight(); } public function fontSizeInPixels(): int { - return $this->getBoxSize('Hy')->height(); + return $this->getBoxSize('Hy')->getHeight(); } } diff --git a/src/Drivers/Abstract/Modifiers/AbstractFitModifier.php b/src/Drivers/Abstract/Modifiers/AbstractFitModifier.php index 3c38bf8f..3ba1bacb 100644 --- a/src/Drivers/Abstract/Modifiers/AbstractFitModifier.php +++ b/src/Drivers/Abstract/Modifiers/AbstractFitModifier.php @@ -22,8 +22,8 @@ abstract class AbstractFitModifier $crop = new Rectangle($this->width, $this->height); $crop = $crop->contain( - $imagesize->width(), - $imagesize->height() + $imagesize->getWidth(), + $imagesize->getHeight() )->alignPivotTo($imagesize, $this->position); return $crop; diff --git a/src/Drivers/Gd/Font.php b/src/Drivers/Gd/Font.php index 0371b962..21cf3f24 100644 --- a/src/Drivers/Gd/Font.php +++ b/src/Drivers/Gd/Font.php @@ -26,8 +26,8 @@ class Font extends AbstractFont $box = new Rectangle(0, 0); $chars = mb_strlen($text); if ($chars > 0) { - $box->withWidth($chars * $this->getGdFontWidth()); - $box->withHeight($this->getGdFontHeight()); + $box->setWidth($chars * $this->getGdFontWidth()); + $box->setHeight($this->getGdFontHeight()); } return $box; } diff --git a/src/Drivers/Gd/Modifiers/FillModifier.php b/src/Drivers/Gd/Modifiers/FillModifier.php index 65de556c..0f747342 100644 --- a/src/Drivers/Gd/Modifiers/FillModifier.php +++ b/src/Drivers/Gd/Modifiers/FillModifier.php @@ -45,8 +45,8 @@ class FillModifier implements ModifierInterface $frame->getCore(), 0, 0, - $frame->getSize()->width() - 1, - $frame->getSize()->height() - 1, + $frame->getSize()->getWidth() - 1, + $frame->getSize()->getHeight() - 1, $this->color->toInt() ); } diff --git a/src/Drivers/Gd/Modifiers/FitModifier.php b/src/Drivers/Gd/Modifiers/FitModifier.php index 9da6944f..cf55b8c0 100644 --- a/src/Drivers/Gd/Modifiers/FitModifier.php +++ b/src/Drivers/Gd/Modifiers/FitModifier.php @@ -26,8 +26,8 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface { // create new image $modified = imagecreatetruecolor( - $resize->width(), - $resize->height() + $resize->getWidth(), + $resize->getHeight() ); // get current image @@ -51,20 +51,20 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface $current, 0, 0, - $crop->pivot()->getX(), - $crop->pivot()->getY(), - $resize->width(), - $resize->height(), - $crop->width(), - $crop->height() + $crop->getPivot()->getX(), + $crop->getPivot()->getY(), + $resize->getWidth(), + $resize->getHeight(), + $crop->getWidth(), + $crop->getHeight() ); imagedestroy($current); if ($transIndex != -1) { // @todo refactor because of duplication imagecolortransparent($modified, $transIndex); - for ($y = 0; $y < $resize->height(); ++$y) { - for ($x = 0; $x < $resize->width(); ++$x) { + for ($y = 0; $y < $resize->getHeight(); ++$y) { + for ($x = 0; $x < $resize->getWidth(); ++$x) { if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) { imagesetpixel( $modified, diff --git a/src/Drivers/Gd/Modifiers/ResizeModifier.php b/src/Drivers/Gd/Modifiers/ResizeModifier.php index 2b91e1c6..512491f5 100644 --- a/src/Drivers/Gd/Modifiers/ResizeModifier.php +++ b/src/Drivers/Gd/Modifiers/ResizeModifier.php @@ -34,8 +34,8 @@ class ResizeModifier implements ModifierInterface { // create new image $modified = imagecreatetruecolor( - $resizeTo->width(), - $resizeTo->height() + $resizeTo->getWidth(), + $resizeTo->getHeight() ); // get current image @@ -57,22 +57,22 @@ class ResizeModifier implements ModifierInterface imagecopyresampled( $modified, $current, - $resizeTo->pivot()->getX(), - $resizeTo->pivot()->getY(), + $resizeTo->getPivot()->getX(), + $resizeTo->getPivot()->getY(), 0, 0, - $resizeTo->width(), - $resizeTo->height(), - $frame->getSize()->width(), - $frame->getSize()->height() + $resizeTo->getWidth(), + $resizeTo->getHeight(), + $frame->getSize()->getWidth(), + $frame->getSize()->getHeight() ); imagedestroy($current); if ($transIndex != -1) { // @todo refactor because of duplication imagecolortransparent($modified, $transIndex); - for ($y = 0; $y < $resizeTo->height(); ++$y) { - for ($x = 0; $x < $resizeTo->width(); ++$x) { + for ($y = 0; $y < $resizeTo->getHeight(); ++$y) { + for ($x = 0; $x < $resizeTo->getWidth(); ++$x) { if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) { imagesetpixel( $modified, diff --git a/src/Drivers/Imagick/Image.php b/src/Drivers/Imagick/Image.php index 2bcbdec5..906322af 100644 --- a/src/Drivers/Imagick/Image.php +++ b/src/Drivers/Imagick/Image.php @@ -44,8 +44,8 @@ class Image extends AbstractImage implements ImageInterface, Iterator $size = $frame->getSize(); $imagick->setImagePage( - $size->width(), - $size->height(), + $size->getWidth(), + $size->getHeight(), $frame->getOffsetLeft(), $frame->getOffsetTop() ); diff --git a/src/Drivers/Imagick/Modifiers/FitModifier.php b/src/Drivers/Imagick/Modifiers/FitModifier.php index 910d86e5..f5465c5f 100644 --- a/src/Drivers/Imagick/Modifiers/FitModifier.php +++ b/src/Drivers/Imagick/Modifiers/FitModifier.php @@ -15,15 +15,15 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface foreach ($image as $frame) { $frame->getCore()->extentImage( - $crop->width(), - $crop->height(), - $crop->pivot()->getX(), - $crop->pivot()->getY() + $crop->getWidth(), + $crop->getHeight(), + $crop->getPivot()->getX(), + $crop->getPivot()->getY() ); $frame->getCore()->scaleImage( - $resize->width(), - $resize->height() + $resize->getWidth(), + $resize->getHeight() ); } diff --git a/src/Drivers/Imagick/Modifiers/PixelateModifier.php b/src/Drivers/Imagick/Modifiers/PixelateModifier.php index 7552e401..f59196f7 100644 --- a/src/Drivers/Imagick/Modifiers/PixelateModifier.php +++ b/src/Drivers/Imagick/Modifiers/PixelateModifier.php @@ -27,10 +27,10 @@ class PixelateModifier implements ModifierInterface $size = $frame->getSize(); $frame->getCore()->scaleImage( - max(1, ($size->width() / $this->size)), - max(1, ($size->height() / $this->size)) + max(1, ($size->getWidth() / $this->size)), + max(1, ($size->getHeight() / $this->size)) ); - $frame->getCore()->scaleImage($size->width(), $size->height()); + $frame->getCore()->scaleImage($size->getWidth(), $size->getHeight()); } } diff --git a/src/Drivers/Imagick/Modifiers/ResizeModifier.php b/src/Drivers/Imagick/Modifiers/ResizeModifier.php index 83d163c7..41f3ad68 100644 --- a/src/Drivers/Imagick/Modifiers/ResizeModifier.php +++ b/src/Drivers/Imagick/Modifiers/ResizeModifier.php @@ -19,8 +19,8 @@ class ResizeModifier implements ModifierInterface foreach ($image as $frame) { $frame->getCore()->scaleImage( - $resizeTo->width(), - $resizeTo->height() + $resizeTo->getWidth(), + $resizeTo->getHeight() ); } diff --git a/src/Geometry/Polygon.php b/src/Geometry/Polygon.php index 71291f61..732193f0 100644 --- a/src/Geometry/Polygon.php +++ b/src/Geometry/Polygon.php @@ -19,7 +19,7 @@ class Polygon implements Countable, ArrayAccess * * @return Point */ - public function getPivotPoint(): Point + public function getPivot(): Point { return $this->pivot; } @@ -30,7 +30,7 @@ class Polygon implements Countable, ArrayAccess * @param Point $pivot * @return Polygon */ - public function setPivotPoint(Point $pivot): self + public function setPivot(Point $pivot): self { $this->pivot = $pivot; @@ -138,7 +138,7 @@ class Polygon implements Countable, ArrayAccess * * @return int */ - public function width(): int + public function getWidth(): int { return abs($this->getMostLeftPoint()->getX() - $this->getMostRightPoint()->getX()); } @@ -148,7 +148,7 @@ class Polygon implements Countable, ArrayAccess * * @return int */ - public function height(): int + public function getHeight(): int { return abs($this->getMostBottomPoint()->getY() - $this->getMostTopPoint()->getY()); } @@ -249,8 +249,8 @@ class Polygon implements Countable, ArrayAccess public function getCenterPoint(): Point { return new Point( - $this->getMostRightPoint()->getX() - (intval(round($this->width() / 2))), - $this->getMostTopPoint()->getY() - (intval(round($this->height() / 2))) + $this->getMostRightPoint()->getX() - (intval(round($this->getWidth() / 2))), + $this->getMostTopPoint()->getY() - (intval(round($this->getHeight() / 2))) ); } @@ -265,16 +265,16 @@ class Polygon implements Countable, ArrayAccess switch (strtolower($position)) { case 'center': case 'middle': - $diff = ($this->getCenterPoint()->getX() - $this->pivot->getX()); + $diff = ($this->getCenterPoint()->getX() - $this->getPivot()->getX()); break; case 'right': - $diff = ($this->getMostRightPoint()->getX() - $this->pivot->getX()); + $diff = ($this->getMostRightPoint()->getX() - $this->getPivot()->getX()); break; default: case 'left': - $diff = ($this->getMostLeftPoint()->getX() - $this->pivot->getX()); + $diff = ($this->getMostLeftPoint()->getX() - $this->getPivot()->getX()); break; } @@ -296,16 +296,16 @@ class Polygon implements Countable, ArrayAccess switch (strtolower($position)) { case 'center': case 'middle': - $diff = ($this->getCenterPoint()->getY() - $this->pivot->getY()); + $diff = ($this->getCenterPoint()->getY() - $this->getPivot()->getY()); break; case 'top': - $diff = ($this->getMostTopPoint()->getY() - $this->pivot->getY()) - $this->height(); + $diff = ($this->getMostTopPoint()->getY() - $this->getPivot()->getY()) - $this->getHeight(); break; default: case 'bottom': - $diff = ($this->getMostBottomPoint()->getY() - $this->pivot->getY()) + $this->height(); + $diff = ($this->getMostBottomPoint()->getY() - $this->getPivot()->getY()) + $this->getHeight(); break; } @@ -329,16 +329,16 @@ class Polygon implements Countable, ArrayAccess foreach ($this->points as $point) { // translate point to pivot - $point->setX($point->getX() - $this->pivot->getX()); - $point->setY($point->getY() - $this->pivot->getY()); + $point->setX($point->getX() - $this->getPivot()->getX()); + $point->setY($point->getY() - $this->getPivot()->getY()); // rotate point $x = $point->getX() * $cos - $point->getY() * $sin; $y = $point->getX() * $sin + $point->getY() * $cos; // translate point back - $point->setX($x + $this->pivot->getX()); - $point->setY($y + $this->pivot->getY()); + $point->setX($x + $this->getPivot()->getX()); + $point->setY($y + $this->getPivot()->getY()); } return $this; diff --git a/src/Geometry/Rectangle.php b/src/Geometry/Rectangle.php index 8e0ba2b7..3e6e68fc 100644 --- a/src/Geometry/Rectangle.php +++ b/src/Geometry/Rectangle.php @@ -20,7 +20,7 @@ class Rectangle extends Polygon implements SizeInterface $this->addPoint(new Point($this->pivot->getX(), $this->pivot->getY() - $height)); } - public function withWidth(int $width): self + public function setWidth(int $width): self { $this[1]->setX($this[0]->getX() + $width); $this[2]->setX($this[3]->getX() + $width); @@ -28,7 +28,7 @@ class Rectangle extends Polygon implements SizeInterface return $this; } - public function withHeight(int $height): self + public function setHeight(int $height): self { $this[2]->setY($this[1]->getY() + $height); $this[3]->setY($this[0]->getY() + $height); @@ -36,12 +36,12 @@ class Rectangle extends Polygon implements SizeInterface return $this; } - public function pivot(): Point + public function getPivot(): Point { return $this->pivot; } - public function withPivot(PointInterface $pivot): self + public function setPivot(PointInterface $pivot): self { $this->pivot = $pivot; @@ -65,13 +65,13 @@ class Rectangle extends Polygon implements SizeInterface case 'top-middle': case 'center-top': case 'middle-top': - $x = intval($this->width() / 2); + $x = intval($this->getWidth() / 2); $y = 0 + $offset_y; break; case 'top-right': case 'right-top': - $x = $this->width() - $offset_x; + $x = $this->getWidth() - $offset_x; $y = 0 + $offset_y; break; @@ -81,7 +81,7 @@ class Rectangle extends Polygon implements SizeInterface case 'center-left': case 'middle-left': $x = 0 + $offset_x; - $y = intval($this->height() / 2); + $y = intval($this->getHeight() / 2); break; case 'right': @@ -89,14 +89,14 @@ class Rectangle extends Polygon implements SizeInterface case 'right-middle': case 'center-right': case 'middle-right': - $x = $this->width() - $offset_x; - $y = intval($this->height() / 2); + $x = $this->getWidth() - $offset_x; + $y = intval($this->getHeight() / 2); break; case 'bottom-left': case 'left-bottom': $x = 0 + $offset_x; - $y = $this->height() - $offset_y; + $y = $this->getHeight() - $offset_y; break; case 'bottom': @@ -104,22 +104,22 @@ class Rectangle extends Polygon implements SizeInterface case 'bottom-middle': case 'center-bottom': case 'middle-bottom': - $x = intval($this->width() / 2); - $y = $this->height() - $offset_y; + $x = intval($this->getWidth() / 2); + $y = $this->getHeight() - $offset_y; break; case 'bottom-right': case 'right-bottom': - $x = $this->width() - $offset_x; - $y = $this->height() - $offset_y; + $x = $this->getWidth() - $offset_x; + $y = $this->getHeight() - $offset_y; break; case 'center': case 'middle': case 'center-center': case 'middle-middle': - $x = intval($this->width() / 2) + $offset_x; - $y = intval($this->height() / 2) + $offset_y; + $x = intval($this->getWidth() / 2) + $offset_x; + $y = intval($this->getHeight() / 2) + $offset_y; break; default: @@ -137,10 +137,10 @@ class Rectangle extends Polygon implements SizeInterface public function alignPivotTo(SizeInterface $size, string $position): self { - $reference = new self($size->width(), $size->height()); + $reference = new self($size->getWidth(), $size->getHeight()); $reference->movePivot($position); - $this->movePivot($position)->withPivot( + $this->movePivot($position)->setPivot( $reference->getRelativePositionTo($this) ); @@ -157,23 +157,23 @@ class Rectangle extends Polygon implements SizeInterface public function getRelativePositionTo(SizeInterface $rectangle): PointInterface { return new Point( - $this->pivot()->getX() - $rectangle->pivot()->getX(), - $this->pivot()->getY() - $rectangle->pivot()->getY() + $this->getPivot()->getX() - $rectangle->getPivot()->getX(), + $this->getPivot()->getY() - $rectangle->getPivot()->getY() ); } public function getAspectRatio(): float { - return $this->width() / $this->height(); + return $this->getWidth() / $this->getHeight(); } public function fitsInto(SizeInterface $size): bool { - if ($this->width() > $size->width()) { + if ($this->getWidth() > $size->getWidth()) { return false; } - if ($this->height() > $size->height()) { + if ($this->getHeight() > $size->getHeight()) { return false; } @@ -187,7 +187,7 @@ class Rectangle extends Polygon implements SizeInterface */ public function isLandscape(): bool { - return $this->width() > $this->height(); + return $this->getWidth() > $this->getHeight(); } /** @@ -197,7 +197,7 @@ class Rectangle extends Polygon implements SizeInterface */ public function isPortrait(): bool { - return $this->width() < $this->height(); + return $this->getWidth() < $this->getHeight(); } protected function getResizer(?int $width = null, ?int $height = null): RectangleResizer diff --git a/src/Geometry/Tools/RectangleResizer.php b/src/Geometry/Tools/RectangleResizer.php index 63dbf6a0..f71f765b 100644 --- a/src/Geometry/Tools/RectangleResizer.php +++ b/src/Geometry/Tools/RectangleResizer.php @@ -65,8 +65,8 @@ class RectangleResizer public function toSize(SizeInterface $size): self { - $this->width = $size->width(); - $this->height = $size->height(); + $this->width = $size->getWidth(); + $this->height = $size->getHeight(); return $this; } @@ -74,7 +74,7 @@ class RectangleResizer protected function getProportionalWidth(SizeInterface $size): int { if (! $this->hasTargetHeight()) { - return $size->width(); + return $size->getWidth(); } return (int) round($this->height * $size->getAspectRatio()); @@ -83,7 +83,7 @@ class RectangleResizer protected function getProportionalHeight(SizeInterface $size): int { if (! $this->hasTargetWidth()) { - return $size->height(); + return $size->getHeight(); } return (int) round($this->width / $size->getAspectRatio()); @@ -91,14 +91,14 @@ class RectangleResizer public function resize(SizeInterface $size): SizeInterface { - $resized = new Rectangle($size->width(), $size->height()); + $resized = new Rectangle($size->getWidth(), $size->getHeight()); if ($width = $this->getTargetWidth()) { - $resized->withWidth($width); + $resized->setWidth($width); } if ($height = $this->getTargetHeight()) { - $resized->withHeight($height); + $resized->setHeight($height); } return $resized; @@ -106,17 +106,17 @@ class RectangleResizer public function resizeDown(SizeInterface $size): SizeInterface { - $resized = new Rectangle($size->width(), $size->height()); + $resized = new Rectangle($size->getWidth(), $size->getHeight()); if ($width = $this->getTargetWidth()) { - $resized->withWidth( - min($width, $size->width()) + $resized->setWidth( + min($width, $size->getWidth()) ); } if ($height = $this->getTargetHeight()) { - $resized->withHeight( - min($height, $size->height()) + $resized->setHeight( + min($height, $size->getHeight()) ); } @@ -125,23 +125,23 @@ class RectangleResizer public function scale(SizeInterface $size): SizeInterface { - $resized = new Rectangle($size->width(), $size->height()); + $resized = new Rectangle($size->getWidth(), $size->getHeight()); if ($this->hasTargetWidth() && $this->hasTargetHeight()) { - $resized->withWidth(min( + $resized->setWidth(min( $this->getProportionalWidth($size), $this->getTargetWidth() )); - $resized->withHeight(min( + $resized->setHeight(min( $this->getProportionalHeight($size), $this->getTargetHeight() )); } elseif ($this->hasTargetWidth()) { - $resized->withWidth($this->getTargetWidth()); - $resized->withHeight($this->getProportionalHeight($size)); + $resized->setWidth($this->getTargetWidth()); + $resized->setHeight($this->getProportionalHeight($size)); } elseif ($this->hasTargetHeight()) { - $resized->withWidth($this->getProportionalWidth($size)); - $resized->withHeight($this->getTargetHeight()); + $resized->setWidth($this->getProportionalWidth($size)); + $resized->setHeight($this->getTargetHeight()); } return $resized; @@ -149,36 +149,36 @@ class RectangleResizer public function scaleDown(SizeInterface $size): SizeInterface { - $resized = new Rectangle($size->width(), $size->height()); + $resized = new Rectangle($size->getWidth(), $size->getHeight()); if ($this->hasTargetWidth() && $this->hasTargetHeight()) { - $resized->withWidth(min( + $resized->setWidth(min( $this->getProportionalWidth($size), $this->getTargetWidth(), - $size->width() + $size->getWidth() )); - $resized->withHeight(min( + $resized->setHeight(min( $this->getProportionalHeight($size), $this->getTargetHeight(), - $size->height() + $size->getHeight() )); } elseif ($this->hasTargetWidth()) { - $resized->withWidth(min( + $resized->setWidth(min( $this->getTargetWidth(), - $size->width() + $size->getWidth() )); - $resized->withHeight(min( + $resized->setHeight(min( $this->getProportionalHeight($size), - $size->height() + $size->getHeight() )); } elseif ($this->hasTargetHeight()) { - $resized->withWidth(min( + $resized->setWidth(min( $this->getProportionalWidth($size), - $size->width() + $size->getWidth() )); - $resized->withHeight(min( + $resized->setHeight(min( $this->getTargetHeight(), - $size->height() + $size->getHeight() )); } @@ -193,16 +193,16 @@ class RectangleResizer */ public function cover(SizeInterface $size): SizeInterface { - $resized = new Rectangle($size->width(), $size->height()); + $resized = new Rectangle($size->getWidth(), $size->getHeight()); // auto height - $resized->withWidth($this->getTargetWidth()); - $resized->withHeight($this->getProportionalHeight($size)); + $resized->setWidth($this->getTargetWidth()); + $resized->setHeight($this->getProportionalHeight($size)); if ($resized->fitsInto($this->getTargetSize())) { // auto width - $resized->withWidth($this->getProportionalWidth($size)); - $resized->withHeight($this->getTargetHeight()); + $resized->setWidth($this->getProportionalWidth($size)); + $resized->setHeight($this->getTargetHeight()); } return $resized; @@ -216,16 +216,16 @@ class RectangleResizer */ public function contain(SizeInterface $size): SizeInterface { - $resized = new Rectangle($size->width(), $size->height()); + $resized = new Rectangle($size->getWidth(), $size->getHeight()); // auto height - $resized->withWidth($this->getTargetWidth()); - $resized->withHeight($this->getProportionalHeight($size)); + $resized->setWidth($this->getTargetWidth()); + $resized->setHeight($this->getProportionalHeight($size)); if (!$resized->fitsInto($this->getTargetSize())) { // auto width - $resized->withWidth($this->getProportionalWidth($size)); - $resized->withHeight($this->getTargetHeight()); + $resized->setWidth($this->getProportionalWidth($size)); + $resized->setHeight($this->getTargetHeight()); } return $resized; diff --git a/src/Interfaces/SizeInterface.php b/src/Interfaces/SizeInterface.php index c8a29b8e..58a6d412 100644 --- a/src/Interfaces/SizeInterface.php +++ b/src/Interfaces/SizeInterface.php @@ -4,12 +4,12 @@ namespace Intervention\Image\Interfaces; interface SizeInterface { - public function width(): int; - public function height(): int; - public function pivot(): PointInterface; - public function withWidth(int $width): SizeInterface; - public function withHeight(int $height): SizeInterface; - public function withPivot(PointInterface $pivot): SizeInterface; + public function getWidth(): int; + public function getHeight(): int; + public function getPivot(): PointInterface; + public function setWidth(int $width): SizeInterface; + public function setHeight(int $height): SizeInterface; + public function setPivot(PointInterface $pivot): SizeInterface; public function getAspectRatio(): float; public function fitsInto(SizeInterface $size): bool; public function isLandscape(): bool; diff --git a/src/Typography/Line.php b/src/Typography/Line.php index 10e98665..4f846674 100644 --- a/src/Typography/Line.php +++ b/src/Typography/Line.php @@ -28,7 +28,7 @@ class Line public function widthInFont(FontInterface $font): int { - return $font->getBoxSize($this->text)->width(); + return $font->getBoxSize($this->text)->getWidth(); } public function __toString(): string diff --git a/src/Typography/TextBlock.php b/src/Typography/TextBlock.php index 4593d67f..65e10688 100644 --- a/src/Typography/TextBlock.php +++ b/src/Typography/TextBlock.php @@ -28,7 +28,7 @@ class TextBlock extends Collection )); // set pivot - $box->setPivotPoint($pivot); + $box->setPivot($pivot); // align $box->align($font->getAlign()); diff --git a/tests/Drivers/Abstract/AbstractImageTest.php b/tests/Drivers/Abstract/AbstractImageTest.php index 21bdd857..b6546ccb 100644 --- a/tests/Drivers/Abstract/AbstractImageTest.php +++ b/tests/Drivers/Abstract/AbstractImageTest.php @@ -45,16 +45,16 @@ class AbstractImageTest extends TestCase { $img = $this->abstractImageMock(); $this->assertInstanceOf(Rectangle::class, $img->getSize()); - $this->assertEquals(300, $img->getSize()->width()); - $this->assertEquals(200, $img->getSize()->height()); + $this->assertEquals(300, $img->getSize()->getWidth()); + $this->assertEquals(200, $img->getSize()->getHeight()); } public function testSizeAlias(): void { $img = $this->abstractImageMock(); $this->assertInstanceOf(Rectangle::class, $img->getSize()); - $this->assertEquals(300, $img->size()->width()); - $this->assertEquals(200, $img->size()->height()); + $this->assertEquals(300, $img->size()->getWidth()); + $this->assertEquals(200, $img->size()->getHeight()); } public function testModify(): void diff --git a/tests/Drivers/Abstract/Modifiers/AbstractFitModifierTest.php b/tests/Drivers/Abstract/Modifiers/AbstractFitModifierTest.php index 28ebb3f6..f8678f96 100644 --- a/tests/Drivers/Abstract/Modifiers/AbstractFitModifierTest.php +++ b/tests/Drivers/Abstract/Modifiers/AbstractFitModifierTest.php @@ -29,10 +29,10 @@ class AbstractFitModifierTest extends TestCase $image = (new ImageFactory())->newImage($width, $height); $size = $modifier->getCropSize($image); - static::assertSame($expectedWidth, $size->width()); - static::assertSame($expectedHeight, $size->height()); - static::assertSame($expectedX, $size->pivot()->getX()); - static::assertSame($expectedY, $size->pivot()->getY()); + static::assertSame($expectedWidth, $size->getWidth()); + static::assertSame($expectedHeight, $size->getHeight()); + static::assertSame($expectedX, $size->getPivot()->getX()); + static::assertSame($expectedY, $size->getPivot()->getY()); } public function testGetResizeSize(): void @@ -43,10 +43,10 @@ class AbstractFitModifierTest extends TestCase $size = $modifier->getCropSize($image); $resize = $modifier->getResizeSize($size); - static::assertSame(200, $resize->width()); - static::assertSame(100, $resize->height()); - static::assertSame(0, $resize->pivot()->getX()); - static::assertSame(0, $resize->pivot()->getY()); + static::assertSame(200, $resize->getWidth()); + static::assertSame(100, $resize->getHeight()); + static::assertSame(0, $resize->getPivot()->getX()); + static::assertSame(0, $resize->getPivot()->getY()); } private function getModifier(int $width, int $height, string $position): AbstractFitModifier diff --git a/tests/Drivers/Abstract/Modifiers/AbstractPadModifierTest.php b/tests/Drivers/Abstract/Modifiers/AbstractPadModifierTest.php index 860aa546..4308a3bf 100644 --- a/tests/Drivers/Abstract/Modifiers/AbstractPadModifierTest.php +++ b/tests/Drivers/Abstract/Modifiers/AbstractPadModifierTest.php @@ -31,10 +31,10 @@ final class AbstractPadModifierTest extends TestCase $image = (new ImageFactory())->newImage($width, $height); $size = $modifier->getCropSize($image); - static::assertSame($expectedWidth, $size->width()); - static::assertSame($expectedHeight, $size->height()); - static::assertSame($expectedX, $size->pivot()->getX()); - static::assertSame($expectedY, $size->pivot()->getY()); + static::assertSame($expectedWidth, $size->getWidth()); + static::assertSame($expectedHeight, $size->getHeight()); + static::assertSame($expectedX, $size->getPivot()->getX()); + static::assertSame($expectedY, $size->getPivot()->getY()); } public function testGetResizeSize(): void @@ -44,10 +44,10 @@ final class AbstractPadModifierTest extends TestCase $image = (new ImageFactory())->newImage(300, 200); $resize = $modifier->getResizeSize($image); - static::assertSame(200, $resize->width()); - static::assertSame(100, $resize->height()); - static::assertSame(0, $resize->pivot()->getX()); - static::assertSame(0, $resize->pivot()->getY()); + static::assertSame(200, $resize->getWidth()); + static::assertSame(100, $resize->getHeight()); + static::assertSame(0, $resize->getPivot()->getX()); + static::assertSame(0, $resize->getPivot()->getY()); } private function getModifier(int $width, int $height, $background, string $position): AbstractPadModifier diff --git a/tests/Drivers/Gd/FrameTest.php b/tests/Drivers/Gd/FrameTest.php index a27a42d3..1f5dd254 100644 --- a/tests/Drivers/Gd/FrameTest.php +++ b/tests/Drivers/Gd/FrameTest.php @@ -36,10 +36,10 @@ class FrameTest extends TestCase $core1 = imagecreatetruecolor(3, 2); $core2 = imagecreatetruecolor(3, 3); $frame = new Frame($core1); - $this->assertEquals(2, $frame->getSize()->height()); + $this->assertEquals(2, $frame->getSize()->getHeight()); $result = $frame->setCore($core2); $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(3, $frame->getSize()->height()); + $this->assertEquals(3, $frame->getSize()->getHeight()); } public function testGetSize(): void diff --git a/tests/Geometry/PolygonTest.php b/tests/Geometry/PolygonTest.php index 8428a0cf..c1a4b938 100644 --- a/tests/Geometry/PolygonTest.php +++ b/tests/Geometry/PolygonTest.php @@ -64,7 +64,7 @@ class PolygonTest extends TestCase $this->assertEquals(-100, $result->getY()); } - public function testWidth(): void + public function testGetWidth(): void { $poly = new Polygon([ new Point(12, 45), @@ -72,10 +72,10 @@ class PolygonTest extends TestCase new Point(3, 566), ]); - $this->assertEquals($poly->width(), 35); + $this->assertEquals($poly->getWidth(), 35); } - public function testHeight(): void + public function testGetHeight(): void { $poly = new Polygon([ new Point(12, 45), @@ -83,7 +83,7 @@ class PolygonTest extends TestCase new Point(3, 566), ]); - $this->assertEquals(615, $poly->height()); + $this->assertEquals(615, $poly->getHeight()); $poly = new Polygon([ new Point(250, 207), @@ -92,7 +92,7 @@ class PolygonTest extends TestCase new Point(250, 250), ], new Point(250, 250)); - $this->assertEquals(43, $poly->height()); + $this->assertEquals(43, $poly->getHeight()); } public function testFirst(): void @@ -122,7 +122,7 @@ class PolygonTest extends TestCase public function testGetPivotPoint(): void { $poly = new Polygon(); - $this->assertInstanceOf(Point::class, $poly->getPivotPoint()); + $this->assertInstanceOf(Point::class, $poly->getPivot()); } public function testGetMostLeftPoint(): void diff --git a/tests/Geometry/RectangleResizerTest.php b/tests/Geometry/RectangleResizerTest.php index ea505fba..d45f0207 100644 --- a/tests/Geometry/RectangleResizerTest.php +++ b/tests/Geometry/RectangleResizerTest.php @@ -54,28 +54,28 @@ class RectangleRectangleResizerTest extends TestCase $resizer = new RectangleResizer(); $resizer->toWidth(150); $result = $resizer->resize($size); - $this->assertEquals(150, $result->width()); - $this->assertEquals(200, $result->height()); + $this->assertEquals(150, $result->getWidth()); + $this->assertEquals(200, $result->getHeight()); $size = new Rectangle(300, 200); $resizer = new RectangleResizer(); $resizer->toWidth(20); $resizer->toHeight(10); $result = $resizer->resize($size); - $this->assertEquals(20, $result->width()); - $this->assertEquals(10, $result->height()); + $this->assertEquals(20, $result->getWidth()); + $this->assertEquals(10, $result->getHeight()); $size = new Rectangle(300, 200); $resizer = new RectangleResizer(width: 150); $result = $resizer->resize($size); - $this->assertEquals(150, $result->width()); - $this->assertEquals(200, $result->height()); + $this->assertEquals(150, $result->getWidth()); + $this->assertEquals(200, $result->getHeight()); $size = new Rectangle(300, 200); $resizer = new RectangleResizer(height: 10, width: 20); $result = $resizer->resize($size); - $this->assertEquals(20, $result->width()); - $this->assertEquals(10, $result->height()); + $this->assertEquals(20, $result->getWidth()); + $this->assertEquals(10, $result->getHeight()); } public function testResizeDown() @@ -86,8 +86,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(1000); $resizer->toHeight(2000); $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); // 800x600 > 400x1000 = 400x600 $size = new Rectangle(800, 600); @@ -95,8 +95,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(400); $resizer->toHeight(1000); $result = $resizer->resizeDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); // 800x600 > 1000x400 = 800x400 $size = new Rectangle(800, 600); @@ -104,8 +104,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(1000); $resizer->toHeight(400); $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(400, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(400, $result->getHeight()); // 800x600 > 400x300 = 400x300 $size = new Rectangle(800, 600); @@ -113,24 +113,24 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(400); $resizer->toHeight(300); $result = $resizer->resizeDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); // 800x600 > 1000xnull = 800x600 $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(1000); $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); // 800x600 > nullx1000 = 800x600 $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toHeight(1000); $result = $resizer->resizeDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); } public function testScale() @@ -141,8 +141,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(1000); $resizer->toHeight(2000); $result = $resizer->scale($size); - $this->assertEquals(1000, $result->width()); - $this->assertEquals(750, $result->height()); + $this->assertEquals(1000, $result->getWidth()); + $this->assertEquals(750, $result->getHeight()); // 800x600 > 2000x1000 = 1333x1000 $size = new Rectangle(800, 600); @@ -150,24 +150,24 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(2000); $resizer->toHeight(1000); $result = $resizer->scale($size); - $this->assertEquals(1333, $result->width()); - $this->assertEquals(1000, $result->height()); + $this->assertEquals(1333, $result->getWidth()); + $this->assertEquals(1000, $result->getHeight()); // // 800x600 > nullx3000 = 4000x3000 $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toHeight(3000); $result = $resizer->scale($size); - $this->assertEquals(4000, $result->width()); - $this->assertEquals(3000, $result->height()); + $this->assertEquals(4000, $result->getWidth()); + $this->assertEquals(3000, $result->getHeight()); // // 800x600 > 8000xnull = 8000x6000 $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(8000); $result = $resizer->scale($size); - $this->assertEquals(8000, $result->width()); - $this->assertEquals(6000, $result->height()); + $this->assertEquals(8000, $result->getWidth()); + $this->assertEquals(6000, $result->getHeight()); // // 800x600 > 100x400 = 100x75 $size = new Rectangle(800, 600); @@ -175,8 +175,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(100); $resizer->toHeight(400); $result = $resizer->scale($size); - $this->assertEquals(100, $result->width()); - $this->assertEquals(75, $result->height()); + $this->assertEquals(100, $result->getWidth()); + $this->assertEquals(75, $result->getHeight()); // // 800x600 > 400x100 = 133x100 $size = new Rectangle(800, 600); @@ -184,40 +184,40 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(400); $resizer->toHeight(100); $result = $resizer->scale($size); - $this->assertEquals(133, $result->width()); - $this->assertEquals(100, $result->height()); + $this->assertEquals(133, $result->getWidth()); + $this->assertEquals(100, $result->getHeight()); // // 800x600 > nullx300 = 400x300 $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toHeight(300); $result = $resizer->scale($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); // // 800x600 > 80xnull = 80x60 $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(80); $result = $resizer->scale($size); - $this->assertEquals(80, $result->width()); - $this->assertEquals(60, $result->height()); + $this->assertEquals(80, $result->getWidth()); + $this->assertEquals(60, $result->getHeight()); // // 640x480 > 225xnull = 225x169 $size = new Rectangle(640, 480); $resizer = new RectangleResizer(); $resizer->toWidth(225); $result = $resizer->scale($size); - $this->assertEquals(225, $result->width()); - $this->assertEquals(169, $result->height()); + $this->assertEquals(225, $result->getWidth()); + $this->assertEquals(169, $result->getHeight()); // // 640x480 > 223xnull = 223x167 $size = new Rectangle(640, 480); $resizer = new RectangleResizer(); $resizer->toWidth(223); $result = $resizer->scale($size); - $this->assertEquals(223, $result->width()); - $this->assertEquals(167, $result->height()); + $this->assertEquals(223, $result->getWidth()); + $this->assertEquals(167, $result->getHeight()); // // 600x800 > 300x300 = 225x300 $size = new Rectangle(600, 800); @@ -225,8 +225,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(300); $resizer->toHeight(300); $result = $resizer->scale($size); - $this->assertEquals(225, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(225, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); // // 800x600 > 400x10 = 13x10 $size = new Rectangle(800, 600); @@ -234,8 +234,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(400); $resizer->toHeight(10); $result = $resizer->scale($size); - $this->assertEquals(13, $result->width()); - $this->assertEquals(10, $result->height()); + $this->assertEquals(13, $result->getWidth()); + $this->assertEquals(10, $result->getHeight()); // // 800x600 > 1000x1200 = 1000x750 $size = new Rectangle(800, 600); @@ -243,32 +243,32 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(1000); $resizer->toHeight(1200); $result = $resizer->scale($size); - $this->assertEquals(1000, $result->width()); - $this->assertEquals(750, $result->height()); + $this->assertEquals(1000, $result->getWidth()); + $this->assertEquals(750, $result->getHeight()); $size = new Rectangle(12000, 12); $resizer = new RectangleResizer(); $resizer->toWidth(4000); $resizer->toHeight(3000); $result = $resizer->scale($size); - $this->assertEquals(4000, $result->width()); - $this->assertEquals(4, $result->height()); + $this->assertEquals(4000, $result->getWidth()); + $this->assertEquals(4, $result->getHeight()); $size = new Rectangle(12, 12000); $resizer = new RectangleResizer(); $resizer->toWidth(4000); $resizer->toHeight(3000); $result = $resizer->scale($size); - $this->assertEquals(3, $result->width()); - $this->assertEquals(3000, $result->height()); + $this->assertEquals(3, $result->getWidth()); + $this->assertEquals(3000, $result->getHeight()); $size = new Rectangle(12000, 6000); $resizer = new RectangleResizer(); $resizer->toWidth(4000); $resizer->toHeight(3000); $result = $resizer->scale($size); - $this->assertEquals(4000, $result->width()); - $this->assertEquals(2000, $result->height()); + $this->assertEquals(4000, $result->getWidth()); + $this->assertEquals(2000, $result->getHeight()); } public function testScaleDown() @@ -278,91 +278,91 @@ class RectangleRectangleResizerTest extends TestCase $resizer->toWidth(1000); $resizer->toHeight(2000); $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(1000); $resizer->toHeight(600); $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(1000); $resizer->toHeight(300); $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(400); $resizer->toHeight(1000); $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(400); $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toHeight(300); $result = $resizer->scaleDown($size); - $this->assertEquals(400, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(400, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(1000); $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toHeight(1000); $result = $resizer->scaleDown($size); - $this->assertEquals(800, $result->width()); - $this->assertEquals(600, $result->height()); + $this->assertEquals(800, $result->getWidth()); + $this->assertEquals(600, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(100); $result = $resizer->scaleDown($size); - $this->assertEquals(100, $result->width()); - $this->assertEquals(75, $result->height()); + $this->assertEquals(100, $result->getWidth()); + $this->assertEquals(75, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(300); $resizer->toHeight(200); $result = $resizer->scaleDown($size); - $this->assertEquals(267, $result->width()); - $this->assertEquals(200, $result->height()); + $this->assertEquals(267, $result->getWidth()); + $this->assertEquals(200, $result->getHeight()); $size = new Rectangle(600, 800); $resizer = new RectangleResizer(); $resizer->toWidth(300); $resizer->toHeight(300); $result = $resizer->scaleDown($size); - $this->assertEquals(225, $result->width()); - $this->assertEquals(300, $result->height()); + $this->assertEquals(225, $result->getWidth()); + $this->assertEquals(300, $result->getHeight()); $size = new Rectangle(800, 600); $resizer = new RectangleResizer(); $resizer->toWidth(400); $resizer->toHeight(10); $result = $resizer->scaleDown($size); - $this->assertEquals(13, $result->width()); - $this->assertEquals(10, $result->height()); + $this->assertEquals(13, $result->getWidth()); + $this->assertEquals(10, $result->getHeight()); } /** @@ -373,8 +373,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer = new RectangleResizer(); $resizer->toSize($target); $resized = $resizer->cover($origin); - $this->assertEquals($result->width(), $resized->width()); - $this->assertEquals($result->height(), $resized->height()); + $this->assertEquals($result->getWidth(), $resized->getWidth()); + $this->assertEquals($result->getHeight(), $resized->getHeight()); } public function coverDataProvider(): array @@ -400,8 +400,8 @@ class RectangleRectangleResizerTest extends TestCase $resizer = new RectangleResizer(); $resizer->toSize($target); $resized = $resizer->contain($origin); - $this->assertEquals($result->width(), $resized->width()); - $this->assertEquals($result->height(), $resized->height()); + $this->assertEquals($result->getWidth(), $resized->getWidth()); + $this->assertEquals($result->getHeight(), $resized->getHeight()); } public function containDataProvider(): array @@ -427,10 +427,10 @@ class RectangleRectangleResizerTest extends TestCase $resizer = new RectangleResizer(); $resizer->toSize($target); $resized = $resizer->crop($origin, $position); - $this->assertEquals($result->width(), $resized->width()); - $this->assertEquals($result->height(), $resized->height()); - $this->assertEquals($result->pivot()->getX(), $resized->pivot()->getX()); - $this->assertEquals($result->pivot()->getY(), $resized->pivot()->getY()); + $this->assertEquals($result->getWidth(), $resized->getWidth()); + $this->assertEquals($result->getHeight(), $resized->getHeight()); + $this->assertEquals($result->getPivot()->getX(), $resized->getPivot()->getX()); + $this->assertEquals($result->getPivot()->getY(), $resized->getPivot()->getY()); } public function cropDataProvider(): array diff --git a/tests/Geometry/RectangleTest.php b/tests/Geometry/RectangleTest.php index ddc9e102..87befb70 100644 --- a/tests/Geometry/RectangleTest.php +++ b/tests/Geometry/RectangleTest.php @@ -19,24 +19,24 @@ class RectangleTest extends TestCase $this->assertEquals(-200, $rectangle[2]->getY()); $this->assertEquals(0, $rectangle[3]->getX()); $this->assertEquals(-200, $rectangle[3]->getY()); - $this->assertEquals(300, $rectangle->width()); - $this->assertEquals(200, $rectangle->height()); + $this->assertEquals(300, $rectangle->getWidth()); + $this->assertEquals(200, $rectangle->getHeight()); } public function testWithWidth(): void { $rectangle = new Rectangle(300, 200); - $this->assertEquals(300, $rectangle->width()); - $rectangle->withWidth(400); - $this->assertEquals(400, $rectangle->width()); + $this->assertEquals(300, $rectangle->getWidth()); + $rectangle->setWidth(400); + $this->assertEquals(400, $rectangle->getWidth()); } public function testWithHeight(): void { $rectangle = new Rectangle(300, 200); - $this->assertEquals(200, $rectangle->height()); - $rectangle->withHeight(800); - $this->assertEquals(800, $rectangle->height()); + $this->assertEquals(200, $rectangle->getHeight()); + $rectangle->setHeight(800); + $this->assertEquals(800, $rectangle->getHeight()); } public function testGetAspectRatio() @@ -109,55 +109,55 @@ class RectangleTest extends TestCase public function testSetGetPivot(): void { $box = new Rectangle(800, 600); - $pivot = $box->pivot(); + $pivot = $box->getPivot(); $this->assertInstanceOf(Point::class, $pivot); $this->assertEquals(0, $pivot->getX()); - $result = $box->withPivot(new Point(10, 0)); + $result = $box->setPivot(new Point(10, 0)); $this->assertInstanceOf(Rectangle::class, $result); - $this->assertEquals(10, $box->pivot()->getX()); + $this->assertEquals(10, $box->getPivot()->getX()); } public function testAlignPivot(): void { $box = new Rectangle(640, 480); - $this->assertEquals(0, $box->pivot()->getX()); - $this->assertEquals(0, $box->pivot()->getY()); + $this->assertEquals(0, $box->getPivot()->getX()); + $this->assertEquals(0, $box->getPivot()->getY()); $box->movePivot('top-left', 3, 3); - $this->assertEquals(3, $box->pivot()->getX()); - $this->assertEquals(3, $box->pivot()->getY()); + $this->assertEquals(3, $box->getPivot()->getX()); + $this->assertEquals(3, $box->getPivot()->getY()); $box->movePivot('top', 3, 3); - $this->assertEquals(320, $box->pivot()->getX()); - $this->assertEquals(3, $box->pivot()->getY()); + $this->assertEquals(320, $box->getPivot()->getX()); + $this->assertEquals(3, $box->getPivot()->getY()); $box->movePivot('top-right', 3, 3); - $this->assertEquals(637, $box->pivot()->getX()); - $this->assertEquals(3, $box->pivot()->getY()); + $this->assertEquals(637, $box->getPivot()->getX()); + $this->assertEquals(3, $box->getPivot()->getY()); $box->movePivot('left', 3, 3); - $this->assertEquals(3, $box->pivot()->getX()); - $this->assertEquals(240, $box->pivot()->getY()); + $this->assertEquals(3, $box->getPivot()->getX()); + $this->assertEquals(240, $box->getPivot()->getY()); $box->movePivot('center', 3, 3); - $this->assertEquals(323, $box->pivot()->getX()); - $this->assertEquals(243, $box->pivot()->getY()); + $this->assertEquals(323, $box->getPivot()->getX()); + $this->assertEquals(243, $box->getPivot()->getY()); $box->movePivot('right', 3, 3); - $this->assertEquals(637, $box->pivot()->getX()); - $this->assertEquals(240, $box->pivot()->getY()); + $this->assertEquals(637, $box->getPivot()->getX()); + $this->assertEquals(240, $box->getPivot()->getY()); $box->movePivot('bottom-left', 3, 3); - $this->assertEquals(3, $box->pivot()->getX()); - $this->assertEquals(477, $box->pivot()->getY()); + $this->assertEquals(3, $box->getPivot()->getX()); + $this->assertEquals(477, $box->getPivot()->getY()); $box->movePivot('bottom', 3, 3); - $this->assertEquals(320, $box->pivot()->getX()); - $this->assertEquals(477, $box->pivot()->getY()); + $this->assertEquals(320, $box->getPivot()->getX()); + $this->assertEquals(477, $box->getPivot()->getY()); $result = $box->movePivot('bottom-right', 3, 3); - $this->assertEquals(637, $box->pivot()->getX()); - $this->assertEquals(477, $box->pivot()->getY()); + $this->assertEquals(637, $box->getPivot()->getX()); + $this->assertEquals(477, $box->getPivot()->getY()); $this->assertInstanceOf(Rectangle::class, $result); } @@ -167,32 +167,32 @@ class RectangleTest extends TestCase $container = new Rectangle(800, 600); $size = new Rectangle(200, 100); $size->alignPivotTo($container, 'center'); - $this->assertEquals(300, $size->pivot()->getX()); - $this->assertEquals(250, $size->pivot()->getY()); + $this->assertEquals(300, $size->getPivot()->getX()); + $this->assertEquals(250, $size->getPivot()->getY()); $container = new Rectangle(800, 600); $size = new Rectangle(100, 100); $size->alignPivotTo($container, 'center'); - $this->assertEquals(350, $size->pivot()->getX()); - $this->assertEquals(250, $size->pivot()->getY()); + $this->assertEquals(350, $size->getPivot()->getX()); + $this->assertEquals(250, $size->getPivot()->getY()); $container = new Rectangle(800, 600); $size = new Rectangle(800, 600); $size->alignPivotTo($container, 'center'); - $this->assertEquals(0, $size->pivot()->getX()); - $this->assertEquals(0, $size->pivot()->getY()); + $this->assertEquals(0, $size->getPivot()->getX()); + $this->assertEquals(0, $size->getPivot()->getY()); $container = new Rectangle(100, 100); $size = new Rectangle(800, 600); $size->alignPivotTo($container, 'center'); - $this->assertEquals(-350, $size->pivot()->getX()); - $this->assertEquals(-250, $size->pivot()->getY()); + $this->assertEquals(-350, $size->getPivot()->getX()); + $this->assertEquals(-250, $size->getPivot()->getY()); $container = new Rectangle(100, 100); $size = new Rectangle(800, 600); $size->alignPivotTo($container, 'bottom-right'); - $this->assertEquals(-700, $size->pivot()->getX()); - $this->assertEquals(-500, $size->pivot()->getY()); + $this->assertEquals(-700, $size->getPivot()->getX()); + $this->assertEquals(-500, $size->getPivot()->getY()); } public function testgetRelativePositionTo(): void diff --git a/tests/Typography/TextBlockTest.php b/tests/Typography/TextBlockTest.php index 6f95d212..8b3f6e3a 100644 --- a/tests/Typography/TextBlockTest.php +++ b/tests/Typography/TextBlockTest.php @@ -71,9 +71,9 @@ class TextBlockTest extends TestCase $font->shouldReceive('capHeight')->andReturn(22); $box = $block->getBoundingBox($font, new Point(10, 15)); - $this->assertEquals(300, $box->width()); - $this->assertEquals(82, $box->height()); - $this->assertEquals(10, $box->getPivotPoint()->getX()); - $this->assertEquals(15, $box->getPivotPoint()->getY()); + $this->assertEquals(300, $box->getWidth()); + $this->assertEquals(82, $box->getHeight()); + $this->assertEquals(10, $box->getPivot()->getX()); + $this->assertEquals(15, $box->getPivot()->getY()); } }