1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-28 16:19:50 +02:00

Consolidate method naming

This commit is contained in:
Oliver Vogel
2022-07-20 16:45:18 +02:00
parent 321ac466f3
commit f8f3baca0e
24 changed files with 289 additions and 289 deletions

View File

@@ -121,11 +121,11 @@ abstract class AbstractFont implements FontInterface
public function capHeight(): int public function capHeight(): int
{ {
return $this->getBoxSize('T')->height(); return $this->getBoxSize('T')->getHeight();
} }
public function fontSizeInPixels(): int public function fontSizeInPixels(): int
{ {
return $this->getBoxSize('Hy')->height(); return $this->getBoxSize('Hy')->getHeight();
} }
} }

View File

@@ -22,8 +22,8 @@ abstract class AbstractFitModifier
$crop = new Rectangle($this->width, $this->height); $crop = new Rectangle($this->width, $this->height);
$crop = $crop->contain( $crop = $crop->contain(
$imagesize->width(), $imagesize->getWidth(),
$imagesize->height() $imagesize->getHeight()
)->alignPivotTo($imagesize, $this->position); )->alignPivotTo($imagesize, $this->position);
return $crop; return $crop;

View File

@@ -26,8 +26,8 @@ class Font extends AbstractFont
$box = new Rectangle(0, 0); $box = new Rectangle(0, 0);
$chars = mb_strlen($text); $chars = mb_strlen($text);
if ($chars > 0) { if ($chars > 0) {
$box->withWidth($chars * $this->getGdFontWidth()); $box->setWidth($chars * $this->getGdFontWidth());
$box->withHeight($this->getGdFontHeight()); $box->setHeight($this->getGdFontHeight());
} }
return $box; return $box;
} }

View File

@@ -45,8 +45,8 @@ class FillModifier implements ModifierInterface
$frame->getCore(), $frame->getCore(),
0, 0,
0, 0,
$frame->getSize()->width() - 1, $frame->getSize()->getWidth() - 1,
$frame->getSize()->height() - 1, $frame->getSize()->getHeight() - 1,
$this->color->toInt() $this->color->toInt()
); );
} }

View File

@@ -26,8 +26,8 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface
{ {
// create new image // create new image
$modified = imagecreatetruecolor( $modified = imagecreatetruecolor(
$resize->width(), $resize->getWidth(),
$resize->height() $resize->getHeight()
); );
// get current image // get current image
@@ -51,20 +51,20 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface
$current, $current,
0, 0,
0, 0,
$crop->pivot()->getX(), $crop->getPivot()->getX(),
$crop->pivot()->getY(), $crop->getPivot()->getY(),
$resize->width(), $resize->getWidth(),
$resize->height(), $resize->getHeight(),
$crop->width(), $crop->getWidth(),
$crop->height() $crop->getHeight()
); );
imagedestroy($current); imagedestroy($current);
if ($transIndex != -1) { // @todo refactor because of duplication if ($transIndex != -1) { // @todo refactor because of duplication
imagecolortransparent($modified, $transIndex); imagecolortransparent($modified, $transIndex);
for ($y = 0; $y < $resize->height(); ++$y) { for ($y = 0; $y < $resize->getHeight(); ++$y) {
for ($x = 0; $x < $resize->width(); ++$x) { for ($x = 0; $x < $resize->getWidth(); ++$x) {
if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) { if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) {
imagesetpixel( imagesetpixel(
$modified, $modified,

View File

@@ -34,8 +34,8 @@ class ResizeModifier implements ModifierInterface
{ {
// create new image // create new image
$modified = imagecreatetruecolor( $modified = imagecreatetruecolor(
$resizeTo->width(), $resizeTo->getWidth(),
$resizeTo->height() $resizeTo->getHeight()
); );
// get current image // get current image
@@ -57,22 +57,22 @@ class ResizeModifier implements ModifierInterface
imagecopyresampled( imagecopyresampled(
$modified, $modified,
$current, $current,
$resizeTo->pivot()->getX(), $resizeTo->getPivot()->getX(),
$resizeTo->pivot()->getY(), $resizeTo->getPivot()->getY(),
0, 0,
0, 0,
$resizeTo->width(), $resizeTo->getWidth(),
$resizeTo->height(), $resizeTo->getHeight(),
$frame->getSize()->width(), $frame->getSize()->getWidth(),
$frame->getSize()->height() $frame->getSize()->getHeight()
); );
imagedestroy($current); imagedestroy($current);
if ($transIndex != -1) { // @todo refactor because of duplication if ($transIndex != -1) { // @todo refactor because of duplication
imagecolortransparent($modified, $transIndex); imagecolortransparent($modified, $transIndex);
for ($y = 0; $y < $resizeTo->height(); ++$y) { for ($y = 0; $y < $resizeTo->getHeight(); ++$y) {
for ($x = 0; $x < $resizeTo->width(); ++$x) { for ($x = 0; $x < $resizeTo->getWidth(); ++$x) {
if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) { if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) {
imagesetpixel( imagesetpixel(
$modified, $modified,

View File

@@ -44,8 +44,8 @@ class Image extends AbstractImage implements ImageInterface, Iterator
$size = $frame->getSize(); $size = $frame->getSize();
$imagick->setImagePage( $imagick->setImagePage(
$size->width(), $size->getWidth(),
$size->height(), $size->getHeight(),
$frame->getOffsetLeft(), $frame->getOffsetLeft(),
$frame->getOffsetTop() $frame->getOffsetTop()
); );

View File

@@ -15,15 +15,15 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface
foreach ($image as $frame) { foreach ($image as $frame) {
$frame->getCore()->extentImage( $frame->getCore()->extentImage(
$crop->width(), $crop->getWidth(),
$crop->height(), $crop->getHeight(),
$crop->pivot()->getX(), $crop->getPivot()->getX(),
$crop->pivot()->getY() $crop->getPivot()->getY()
); );
$frame->getCore()->scaleImage( $frame->getCore()->scaleImage(
$resize->width(), $resize->getWidth(),
$resize->height() $resize->getHeight()
); );
} }

View File

@@ -27,10 +27,10 @@ class PixelateModifier implements ModifierInterface
$size = $frame->getSize(); $size = $frame->getSize();
$frame->getCore()->scaleImage( $frame->getCore()->scaleImage(
max(1, ($size->width() / $this->size)), max(1, ($size->getWidth() / $this->size)),
max(1, ($size->height() / $this->size)) max(1, ($size->getHeight() / $this->size))
); );
$frame->getCore()->scaleImage($size->width(), $size->height()); $frame->getCore()->scaleImage($size->getWidth(), $size->getHeight());
} }
} }

View File

@@ -19,8 +19,8 @@ class ResizeModifier implements ModifierInterface
foreach ($image as $frame) { foreach ($image as $frame) {
$frame->getCore()->scaleImage( $frame->getCore()->scaleImage(
$resizeTo->width(), $resizeTo->getWidth(),
$resizeTo->height() $resizeTo->getHeight()
); );
} }

View File

@@ -19,7 +19,7 @@ class Polygon implements Countable, ArrayAccess
* *
* @return Point * @return Point
*/ */
public function getPivotPoint(): Point public function getPivot(): Point
{ {
return $this->pivot; return $this->pivot;
} }
@@ -30,7 +30,7 @@ class Polygon implements Countable, ArrayAccess
* @param Point $pivot * @param Point $pivot
* @return Polygon * @return Polygon
*/ */
public function setPivotPoint(Point $pivot): self public function setPivot(Point $pivot): self
{ {
$this->pivot = $pivot; $this->pivot = $pivot;
@@ -138,7 +138,7 @@ class Polygon implements Countable, ArrayAccess
* *
* @return int * @return int
*/ */
public function width(): int public function getWidth(): int
{ {
return abs($this->getMostLeftPoint()->getX() - $this->getMostRightPoint()->getX()); return abs($this->getMostLeftPoint()->getX() - $this->getMostRightPoint()->getX());
} }
@@ -148,7 +148,7 @@ class Polygon implements Countable, ArrayAccess
* *
* @return int * @return int
*/ */
public function height(): int public function getHeight(): int
{ {
return abs($this->getMostBottomPoint()->getY() - $this->getMostTopPoint()->getY()); return abs($this->getMostBottomPoint()->getY() - $this->getMostTopPoint()->getY());
} }
@@ -249,8 +249,8 @@ class Polygon implements Countable, ArrayAccess
public function getCenterPoint(): Point public function getCenterPoint(): Point
{ {
return new Point( return new Point(
$this->getMostRightPoint()->getX() - (intval(round($this->width() / 2))), $this->getMostRightPoint()->getX() - (intval(round($this->getWidth() / 2))),
$this->getMostTopPoint()->getY() - (intval(round($this->height() / 2))) $this->getMostTopPoint()->getY() - (intval(round($this->getHeight() / 2)))
); );
} }
@@ -265,16 +265,16 @@ class Polygon implements Countable, ArrayAccess
switch (strtolower($position)) { switch (strtolower($position)) {
case 'center': case 'center':
case 'middle': case 'middle':
$diff = ($this->getCenterPoint()->getX() - $this->pivot->getX()); $diff = ($this->getCenterPoint()->getX() - $this->getPivot()->getX());
break; break;
case 'right': case 'right':
$diff = ($this->getMostRightPoint()->getX() - $this->pivot->getX()); $diff = ($this->getMostRightPoint()->getX() - $this->getPivot()->getX());
break; break;
default: default:
case 'left': case 'left':
$diff = ($this->getMostLeftPoint()->getX() - $this->pivot->getX()); $diff = ($this->getMostLeftPoint()->getX() - $this->getPivot()->getX());
break; break;
} }
@@ -296,16 +296,16 @@ class Polygon implements Countable, ArrayAccess
switch (strtolower($position)) { switch (strtolower($position)) {
case 'center': case 'center':
case 'middle': case 'middle':
$diff = ($this->getCenterPoint()->getY() - $this->pivot->getY()); $diff = ($this->getCenterPoint()->getY() - $this->getPivot()->getY());
break; break;
case 'top': case 'top':
$diff = ($this->getMostTopPoint()->getY() - $this->pivot->getY()) - $this->height(); $diff = ($this->getMostTopPoint()->getY() - $this->getPivot()->getY()) - $this->getHeight();
break; break;
default: default:
case 'bottom': case 'bottom':
$diff = ($this->getMostBottomPoint()->getY() - $this->pivot->getY()) + $this->height(); $diff = ($this->getMostBottomPoint()->getY() - $this->getPivot()->getY()) + $this->getHeight();
break; break;
} }
@@ -329,16 +329,16 @@ class Polygon implements Countable, ArrayAccess
foreach ($this->points as $point) { foreach ($this->points as $point) {
// translate point to pivot // translate point to pivot
$point->setX($point->getX() - $this->pivot->getX()); $point->setX($point->getX() - $this->getPivot()->getX());
$point->setY($point->getY() - $this->pivot->getY()); $point->setY($point->getY() - $this->getPivot()->getY());
// rotate point // rotate point
$x = $point->getX() * $cos - $point->getY() * $sin; $x = $point->getX() * $cos - $point->getY() * $sin;
$y = $point->getX() * $sin + $point->getY() * $cos; $y = $point->getX() * $sin + $point->getY() * $cos;
// translate point back // translate point back
$point->setX($x + $this->pivot->getX()); $point->setX($x + $this->getPivot()->getX());
$point->setY($y + $this->pivot->getY()); $point->setY($y + $this->getPivot()->getY());
} }
return $this; return $this;

View File

@@ -20,7 +20,7 @@ class Rectangle extends Polygon implements SizeInterface
$this->addPoint(new Point($this->pivot->getX(), $this->pivot->getY() - $height)); $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[1]->setX($this[0]->getX() + $width);
$this[2]->setX($this[3]->getX() + $width); $this[2]->setX($this[3]->getX() + $width);
@@ -28,7 +28,7 @@ class Rectangle extends Polygon implements SizeInterface
return $this; return $this;
} }
public function withHeight(int $height): self public function setHeight(int $height): self
{ {
$this[2]->setY($this[1]->getY() + $height); $this[2]->setY($this[1]->getY() + $height);
$this[3]->setY($this[0]->getY() + $height); $this[3]->setY($this[0]->getY() + $height);
@@ -36,12 +36,12 @@ class Rectangle extends Polygon implements SizeInterface
return $this; return $this;
} }
public function pivot(): Point public function getPivot(): Point
{ {
return $this->pivot; return $this->pivot;
} }
public function withPivot(PointInterface $pivot): self public function setPivot(PointInterface $pivot): self
{ {
$this->pivot = $pivot; $this->pivot = $pivot;
@@ -65,13 +65,13 @@ class Rectangle extends Polygon implements SizeInterface
case 'top-middle': case 'top-middle':
case 'center-top': case 'center-top':
case 'middle-top': case 'middle-top':
$x = intval($this->width() / 2); $x = intval($this->getWidth() / 2);
$y = 0 + $offset_y; $y = 0 + $offset_y;
break; break;
case 'top-right': case 'top-right':
case 'right-top': case 'right-top':
$x = $this->width() - $offset_x; $x = $this->getWidth() - $offset_x;
$y = 0 + $offset_y; $y = 0 + $offset_y;
break; break;
@@ -81,7 +81,7 @@ class Rectangle extends Polygon implements SizeInterface
case 'center-left': case 'center-left':
case 'middle-left': case 'middle-left':
$x = 0 + $offset_x; $x = 0 + $offset_x;
$y = intval($this->height() / 2); $y = intval($this->getHeight() / 2);
break; break;
case 'right': case 'right':
@@ -89,14 +89,14 @@ class Rectangle extends Polygon implements SizeInterface
case 'right-middle': case 'right-middle':
case 'center-right': case 'center-right':
case 'middle-right': case 'middle-right':
$x = $this->width() - $offset_x; $x = $this->getWidth() - $offset_x;
$y = intval($this->height() / 2); $y = intval($this->getHeight() / 2);
break; break;
case 'bottom-left': case 'bottom-left':
case 'left-bottom': case 'left-bottom':
$x = 0 + $offset_x; $x = 0 + $offset_x;
$y = $this->height() - $offset_y; $y = $this->getHeight() - $offset_y;
break; break;
case 'bottom': case 'bottom':
@@ -104,22 +104,22 @@ class Rectangle extends Polygon implements SizeInterface
case 'bottom-middle': case 'bottom-middle':
case 'center-bottom': case 'center-bottom':
case 'middle-bottom': case 'middle-bottom':
$x = intval($this->width() / 2); $x = intval($this->getWidth() / 2);
$y = $this->height() - $offset_y; $y = $this->getHeight() - $offset_y;
break; break;
case 'bottom-right': case 'bottom-right':
case 'right-bottom': case 'right-bottom':
$x = $this->width() - $offset_x; $x = $this->getWidth() - $offset_x;
$y = $this->height() - $offset_y; $y = $this->getHeight() - $offset_y;
break; break;
case 'center': case 'center':
case 'middle': case 'middle':
case 'center-center': case 'center-center':
case 'middle-middle': case 'middle-middle':
$x = intval($this->width() / 2) + $offset_x; $x = intval($this->getWidth() / 2) + $offset_x;
$y = intval($this->height() / 2) + $offset_y; $y = intval($this->getHeight() / 2) + $offset_y;
break; break;
default: default:
@@ -137,10 +137,10 @@ class Rectangle extends Polygon implements SizeInterface
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->getWidth(), $size->getHeight());
$reference->movePivot($position); $reference->movePivot($position);
$this->movePivot($position)->withPivot( $this->movePivot($position)->setPivot(
$reference->getRelativePositionTo($this) $reference->getRelativePositionTo($this)
); );
@@ -157,23 +157,23 @@ class Rectangle extends Polygon implements SizeInterface
public function getRelativePositionTo(SizeInterface $rectangle): PointInterface public function getRelativePositionTo(SizeInterface $rectangle): PointInterface
{ {
return new Point( return new Point(
$this->pivot()->getX() - $rectangle->pivot()->getX(), $this->getPivot()->getX() - $rectangle->getPivot()->getX(),
$this->pivot()->getY() - $rectangle->pivot()->getY() $this->getPivot()->getY() - $rectangle->getPivot()->getY()
); );
} }
public function getAspectRatio(): float public function getAspectRatio(): float
{ {
return $this->width() / $this->height(); return $this->getWidth() / $this->getHeight();
} }
public function fitsInto(SizeInterface $size): bool public function fitsInto(SizeInterface $size): bool
{ {
if ($this->width() > $size->width()) { if ($this->getWidth() > $size->getWidth()) {
return false; return false;
} }
if ($this->height() > $size->height()) { if ($this->getHeight() > $size->getHeight()) {
return false; return false;
} }
@@ -187,7 +187,7 @@ class Rectangle extends Polygon implements SizeInterface
*/ */
public function isLandscape(): bool 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 public function isPortrait(): bool
{ {
return $this->width() < $this->height(); return $this->getWidth() < $this->getHeight();
} }
protected function getResizer(?int $width = null, ?int $height = null): RectangleResizer protected function getResizer(?int $width = null, ?int $height = null): RectangleResizer

View File

@@ -65,8 +65,8 @@ class RectangleResizer
public function toSize(SizeInterface $size): self public function toSize(SizeInterface $size): self
{ {
$this->width = $size->width(); $this->width = $size->getWidth();
$this->height = $size->height(); $this->height = $size->getHeight();
return $this; return $this;
} }
@@ -74,7 +74,7 @@ class RectangleResizer
protected function getProportionalWidth(SizeInterface $size): int protected function getProportionalWidth(SizeInterface $size): int
{ {
if (! $this->hasTargetHeight()) { if (! $this->hasTargetHeight()) {
return $size->width(); return $size->getWidth();
} }
return (int) round($this->height * $size->getAspectRatio()); return (int) round($this->height * $size->getAspectRatio());
@@ -83,7 +83,7 @@ class RectangleResizer
protected function getProportionalHeight(SizeInterface $size): int protected function getProportionalHeight(SizeInterface $size): int
{ {
if (! $this->hasTargetWidth()) { if (! $this->hasTargetWidth()) {
return $size->height(); return $size->getHeight();
} }
return (int) round($this->width / $size->getAspectRatio()); return (int) round($this->width / $size->getAspectRatio());
@@ -91,14 +91,14 @@ class RectangleResizer
public function resize(SizeInterface $size): SizeInterface public function resize(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->getWidth(), $size->getHeight());
if ($width = $this->getTargetWidth()) { if ($width = $this->getTargetWidth()) {
$resized->withWidth($width); $resized->setWidth($width);
} }
if ($height = $this->getTargetHeight()) { if ($height = $this->getTargetHeight()) {
$resized->withHeight($height); $resized->setHeight($height);
} }
return $resized; return $resized;
@@ -106,17 +106,17 @@ class RectangleResizer
public function resizeDown(SizeInterface $size): SizeInterface public function resizeDown(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->getWidth(), $size->getHeight());
if ($width = $this->getTargetWidth()) { if ($width = $this->getTargetWidth()) {
$resized->withWidth( $resized->setWidth(
min($width, $size->width()) min($width, $size->getWidth())
); );
} }
if ($height = $this->getTargetHeight()) { if ($height = $this->getTargetHeight()) {
$resized->withHeight( $resized->setHeight(
min($height, $size->height()) min($height, $size->getHeight())
); );
} }
@@ -125,23 +125,23 @@ class RectangleResizer
public function scale(SizeInterface $size): SizeInterface 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()) { if ($this->hasTargetWidth() && $this->hasTargetHeight()) {
$resized->withWidth(min( $resized->setWidth(min(
$this->getProportionalWidth($size), $this->getProportionalWidth($size),
$this->getTargetWidth() $this->getTargetWidth()
)); ));
$resized->withHeight(min( $resized->setHeight(min(
$this->getProportionalHeight($size), $this->getProportionalHeight($size),
$this->getTargetHeight() $this->getTargetHeight()
)); ));
} elseif ($this->hasTargetWidth()) { } elseif ($this->hasTargetWidth()) {
$resized->withWidth($this->getTargetWidth()); $resized->setWidth($this->getTargetWidth());
$resized->withHeight($this->getProportionalHeight($size)); $resized->setHeight($this->getProportionalHeight($size));
} elseif ($this->hasTargetHeight()) { } elseif ($this->hasTargetHeight()) {
$resized->withWidth($this->getProportionalWidth($size)); $resized->setWidth($this->getProportionalWidth($size));
$resized->withHeight($this->getTargetHeight()); $resized->setHeight($this->getTargetHeight());
} }
return $resized; return $resized;
@@ -149,36 +149,36 @@ class RectangleResizer
public function scaleDown(SizeInterface $size): SizeInterface 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()) { if ($this->hasTargetWidth() && $this->hasTargetHeight()) {
$resized->withWidth(min( $resized->setWidth(min(
$this->getProportionalWidth($size), $this->getProportionalWidth($size),
$this->getTargetWidth(), $this->getTargetWidth(),
$size->width() $size->getWidth()
)); ));
$resized->withHeight(min( $resized->setHeight(min(
$this->getProportionalHeight($size), $this->getProportionalHeight($size),
$this->getTargetHeight(), $this->getTargetHeight(),
$size->height() $size->getHeight()
)); ));
} elseif ($this->hasTargetWidth()) { } elseif ($this->hasTargetWidth()) {
$resized->withWidth(min( $resized->setWidth(min(
$this->getTargetWidth(), $this->getTargetWidth(),
$size->width() $size->getWidth()
)); ));
$resized->withHeight(min( $resized->setHeight(min(
$this->getProportionalHeight($size), $this->getProportionalHeight($size),
$size->height() $size->getHeight()
)); ));
} elseif ($this->hasTargetHeight()) { } elseif ($this->hasTargetHeight()) {
$resized->withWidth(min( $resized->setWidth(min(
$this->getProportionalWidth($size), $this->getProportionalWidth($size),
$size->width() $size->getWidth()
)); ));
$resized->withHeight(min( $resized->setHeight(min(
$this->getTargetHeight(), $this->getTargetHeight(),
$size->height() $size->getHeight()
)); ));
} }
@@ -193,16 +193,16 @@ class RectangleResizer
*/ */
public function cover(SizeInterface $size): SizeInterface public function cover(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->getWidth(), $size->getHeight());
// auto height // auto height
$resized->withWidth($this->getTargetWidth()); $resized->setWidth($this->getTargetWidth());
$resized->withHeight($this->getProportionalHeight($size)); $resized->setHeight($this->getProportionalHeight($size));
if ($resized->fitsInto($this->getTargetSize())) { if ($resized->fitsInto($this->getTargetSize())) {
// auto width // auto width
$resized->withWidth($this->getProportionalWidth($size)); $resized->setWidth($this->getProportionalWidth($size));
$resized->withHeight($this->getTargetHeight()); $resized->setHeight($this->getTargetHeight());
} }
return $resized; return $resized;
@@ -216,16 +216,16 @@ class RectangleResizer
*/ */
public function contain(SizeInterface $size): SizeInterface public function contain(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->getWidth(), $size->getHeight());
// auto height // auto height
$resized->withWidth($this->getTargetWidth()); $resized->setWidth($this->getTargetWidth());
$resized->withHeight($this->getProportionalHeight($size)); $resized->setHeight($this->getProportionalHeight($size));
if (!$resized->fitsInto($this->getTargetSize())) { if (!$resized->fitsInto($this->getTargetSize())) {
// auto width // auto width
$resized->withWidth($this->getProportionalWidth($size)); $resized->setWidth($this->getProportionalWidth($size));
$resized->withHeight($this->getTargetHeight()); $resized->setHeight($this->getTargetHeight());
} }
return $resized; return $resized;

View File

@@ -4,12 +4,12 @@ namespace Intervention\Image\Interfaces;
interface SizeInterface interface SizeInterface
{ {
public function width(): int; public function getWidth(): int;
public function height(): int; public function getHeight(): int;
public function pivot(): PointInterface; public function getPivot(): PointInterface;
public function withWidth(int $width): SizeInterface; public function setWidth(int $width): SizeInterface;
public function withHeight(int $height): SizeInterface; public function setHeight(int $height): SizeInterface;
public function withPivot(PointInterface $pivot): SizeInterface; public function setPivot(PointInterface $pivot): SizeInterface;
public function getAspectRatio(): float; public function getAspectRatio(): float;
public function fitsInto(SizeInterface $size): bool; public function fitsInto(SizeInterface $size): bool;
public function isLandscape(): bool; public function isLandscape(): bool;

View File

@@ -28,7 +28,7 @@ class Line
public function widthInFont(FontInterface $font): int public function widthInFont(FontInterface $font): int
{ {
return $font->getBoxSize($this->text)->width(); return $font->getBoxSize($this->text)->getWidth();
} }
public function __toString(): string public function __toString(): string

View File

@@ -28,7 +28,7 @@ class TextBlock extends Collection
)); ));
// set pivot // set pivot
$box->setPivotPoint($pivot); $box->setPivot($pivot);
// align // align
$box->align($font->getAlign()); $box->align($font->getAlign());

View File

@@ -45,16 +45,16 @@ class AbstractImageTest extends TestCase
{ {
$img = $this->abstractImageMock(); $img = $this->abstractImageMock();
$this->assertInstanceOf(Rectangle::class, $img->getSize()); $this->assertInstanceOf(Rectangle::class, $img->getSize());
$this->assertEquals(300, $img->getSize()->width()); $this->assertEquals(300, $img->getSize()->getWidth());
$this->assertEquals(200, $img->getSize()->height()); $this->assertEquals(200, $img->getSize()->getHeight());
} }
public function testSizeAlias(): void public function testSizeAlias(): void
{ {
$img = $this->abstractImageMock(); $img = $this->abstractImageMock();
$this->assertInstanceOf(Rectangle::class, $img->getSize()); $this->assertInstanceOf(Rectangle::class, $img->getSize());
$this->assertEquals(300, $img->size()->width()); $this->assertEquals(300, $img->size()->getWidth());
$this->assertEquals(200, $img->size()->height()); $this->assertEquals(200, $img->size()->getHeight());
} }
public function testModify(): void public function testModify(): void

View File

@@ -29,10 +29,10 @@ class AbstractFitModifierTest extends TestCase
$image = (new ImageFactory())->newImage($width, $height); $image = (new ImageFactory())->newImage($width, $height);
$size = $modifier->getCropSize($image); $size = $modifier->getCropSize($image);
static::assertSame($expectedWidth, $size->width()); static::assertSame($expectedWidth, $size->getWidth());
static::assertSame($expectedHeight, $size->height()); static::assertSame($expectedHeight, $size->getHeight());
static::assertSame($expectedX, $size->pivot()->getX()); static::assertSame($expectedX, $size->getPivot()->getX());
static::assertSame($expectedY, $size->pivot()->getY()); static::assertSame($expectedY, $size->getPivot()->getY());
} }
public function testGetResizeSize(): void public function testGetResizeSize(): void
@@ -43,10 +43,10 @@ class AbstractFitModifierTest extends TestCase
$size = $modifier->getCropSize($image); $size = $modifier->getCropSize($image);
$resize = $modifier->getResizeSize($size); $resize = $modifier->getResizeSize($size);
static::assertSame(200, $resize->width()); static::assertSame(200, $resize->getWidth());
static::assertSame(100, $resize->height()); static::assertSame(100, $resize->getHeight());
static::assertSame(0, $resize->pivot()->getX()); static::assertSame(0, $resize->getPivot()->getX());
static::assertSame(0, $resize->pivot()->getY()); static::assertSame(0, $resize->getPivot()->getY());
} }
private function getModifier(int $width, int $height, string $position): AbstractFitModifier private function getModifier(int $width, int $height, string $position): AbstractFitModifier

View File

@@ -31,10 +31,10 @@ final class AbstractPadModifierTest extends TestCase
$image = (new ImageFactory())->newImage($width, $height); $image = (new ImageFactory())->newImage($width, $height);
$size = $modifier->getCropSize($image); $size = $modifier->getCropSize($image);
static::assertSame($expectedWidth, $size->width()); static::assertSame($expectedWidth, $size->getWidth());
static::assertSame($expectedHeight, $size->height()); static::assertSame($expectedHeight, $size->getHeight());
static::assertSame($expectedX, $size->pivot()->getX()); static::assertSame($expectedX, $size->getPivot()->getX());
static::assertSame($expectedY, $size->pivot()->getY()); static::assertSame($expectedY, $size->getPivot()->getY());
} }
public function testGetResizeSize(): void public function testGetResizeSize(): void
@@ -44,10 +44,10 @@ final class AbstractPadModifierTest extends TestCase
$image = (new ImageFactory())->newImage(300, 200); $image = (new ImageFactory())->newImage(300, 200);
$resize = $modifier->getResizeSize($image); $resize = $modifier->getResizeSize($image);
static::assertSame(200, $resize->width()); static::assertSame(200, $resize->getWidth());
static::assertSame(100, $resize->height()); static::assertSame(100, $resize->getHeight());
static::assertSame(0, $resize->pivot()->getX()); static::assertSame(0, $resize->getPivot()->getX());
static::assertSame(0, $resize->pivot()->getY()); static::assertSame(0, $resize->getPivot()->getY());
} }
private function getModifier(int $width, int $height, $background, string $position): AbstractPadModifier private function getModifier(int $width, int $height, $background, string $position): AbstractPadModifier

View File

@@ -36,10 +36,10 @@ class FrameTest extends TestCase
$core1 = imagecreatetruecolor(3, 2); $core1 = imagecreatetruecolor(3, 2);
$core2 = imagecreatetruecolor(3, 3); $core2 = imagecreatetruecolor(3, 3);
$frame = new Frame($core1); $frame = new Frame($core1);
$this->assertEquals(2, $frame->getSize()->height()); $this->assertEquals(2, $frame->getSize()->getHeight());
$result = $frame->setCore($core2); $result = $frame->setCore($core2);
$this->assertInstanceOf(Frame::class, $result); $this->assertInstanceOf(Frame::class, $result);
$this->assertEquals(3, $frame->getSize()->height()); $this->assertEquals(3, $frame->getSize()->getHeight());
} }
public function testGetSize(): void public function testGetSize(): void

View File

@@ -64,7 +64,7 @@ class PolygonTest extends TestCase
$this->assertEquals(-100, $result->getY()); $this->assertEquals(-100, $result->getY());
} }
public function testWidth(): void public function testGetWidth(): void
{ {
$poly = new Polygon([ $poly = new Polygon([
new Point(12, 45), new Point(12, 45),
@@ -72,10 +72,10 @@ class PolygonTest extends TestCase
new Point(3, 566), 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([ $poly = new Polygon([
new Point(12, 45), new Point(12, 45),
@@ -83,7 +83,7 @@ class PolygonTest extends TestCase
new Point(3, 566), new Point(3, 566),
]); ]);
$this->assertEquals(615, $poly->height()); $this->assertEquals(615, $poly->getHeight());
$poly = new Polygon([ $poly = new Polygon([
new Point(250, 207), new Point(250, 207),
@@ -92,7 +92,7 @@ class PolygonTest extends TestCase
new Point(250, 250), new Point(250, 250),
], new Point(250, 250)); ], new Point(250, 250));
$this->assertEquals(43, $poly->height()); $this->assertEquals(43, $poly->getHeight());
} }
public function testFirst(): void public function testFirst(): void
@@ -122,7 +122,7 @@ class PolygonTest extends TestCase
public function testGetPivotPoint(): void public function testGetPivotPoint(): void
{ {
$poly = new Polygon(); $poly = new Polygon();
$this->assertInstanceOf(Point::class, $poly->getPivotPoint()); $this->assertInstanceOf(Point::class, $poly->getPivot());
} }
public function testGetMostLeftPoint(): void public function testGetMostLeftPoint(): void

View File

@@ -54,28 +54,28 @@ class RectangleRectangleResizerTest extends TestCase
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(150); $resizer->toWidth(150);
$result = $resizer->resize($size); $result = $resizer->resize($size);
$this->assertEquals(150, $result->width()); $this->assertEquals(150, $result->getWidth());
$this->assertEquals(200, $result->height()); $this->assertEquals(200, $result->getHeight());
$size = new Rectangle(300, 200); $size = new Rectangle(300, 200);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(20); $resizer->toWidth(20);
$resizer->toHeight(10); $resizer->toHeight(10);
$result = $resizer->resize($size); $result = $resizer->resize($size);
$this->assertEquals(20, $result->width()); $this->assertEquals(20, $result->getWidth());
$this->assertEquals(10, $result->height()); $this->assertEquals(10, $result->getHeight());
$size = new Rectangle(300, 200); $size = new Rectangle(300, 200);
$resizer = new RectangleResizer(width: 150); $resizer = new RectangleResizer(width: 150);
$result = $resizer->resize($size); $result = $resizer->resize($size);
$this->assertEquals(150, $result->width()); $this->assertEquals(150, $result->getWidth());
$this->assertEquals(200, $result->height()); $this->assertEquals(200, $result->getHeight());
$size = new Rectangle(300, 200); $size = new Rectangle(300, 200);
$resizer = new RectangleResizer(height: 10, width: 20); $resizer = new RectangleResizer(height: 10, width: 20);
$result = $resizer->resize($size); $result = $resizer->resize($size);
$this->assertEquals(20, $result->width()); $this->assertEquals(20, $result->getWidth());
$this->assertEquals(10, $result->height()); $this->assertEquals(10, $result->getHeight());
} }
public function testResizeDown() public function testResizeDown()
@@ -86,8 +86,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(2000); $resizer->toHeight(2000);
$result = $resizer->resizeDown($size); $result = $resizer->resizeDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
// 800x600 > 400x1000 = 400x600 // 800x600 > 400x1000 = 400x600
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -95,8 +95,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(400); $resizer->toWidth(400);
$resizer->toHeight(1000); $resizer->toHeight(1000);
$result = $resizer->resizeDown($size); $result = $resizer->resizeDown($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
// 800x600 > 1000x400 = 800x400 // 800x600 > 1000x400 = 800x400
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -104,8 +104,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(400); $resizer->toHeight(400);
$result = $resizer->resizeDown($size); $result = $resizer->resizeDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(400, $result->height()); $this->assertEquals(400, $result->getHeight());
// 800x600 > 400x300 = 400x300 // 800x600 > 400x300 = 400x300
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -113,24 +113,24 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(400); $resizer->toWidth(400);
$resizer->toHeight(300); $resizer->toHeight(300);
$result = $resizer->resizeDown($size); $result = $resizer->resizeDown($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
// 800x600 > 1000xnull = 800x600 // 800x600 > 1000xnull = 800x600
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(1000); $resizer->toWidth(1000);
$result = $resizer->resizeDown($size); $result = $resizer->resizeDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
// 800x600 > nullx1000 = 800x600 // 800x600 > nullx1000 = 800x600
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toHeight(1000); $resizer->toHeight(1000);
$result = $resizer->resizeDown($size); $result = $resizer->resizeDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
} }
public function testScale() public function testScale()
@@ -141,8 +141,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(2000); $resizer->toHeight(2000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(1000, $result->width()); $this->assertEquals(1000, $result->getWidth());
$this->assertEquals(750, $result->height()); $this->assertEquals(750, $result->getHeight());
// 800x600 > 2000x1000 = 1333x1000 // 800x600 > 2000x1000 = 1333x1000
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -150,24 +150,24 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(2000); $resizer->toWidth(2000);
$resizer->toHeight(1000); $resizer->toHeight(1000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(1333, $result->width()); $this->assertEquals(1333, $result->getWidth());
$this->assertEquals(1000, $result->height()); $this->assertEquals(1000, $result->getHeight());
// // 800x600 > nullx3000 = 4000x3000 // // 800x600 > nullx3000 = 4000x3000
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toHeight(3000); $resizer->toHeight(3000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(4000, $result->width()); $this->assertEquals(4000, $result->getWidth());
$this->assertEquals(3000, $result->height()); $this->assertEquals(3000, $result->getHeight());
// // 800x600 > 8000xnull = 8000x6000 // // 800x600 > 8000xnull = 8000x6000
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(8000); $resizer->toWidth(8000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(8000, $result->width()); $this->assertEquals(8000, $result->getWidth());
$this->assertEquals(6000, $result->height()); $this->assertEquals(6000, $result->getHeight());
// // 800x600 > 100x400 = 100x75 // // 800x600 > 100x400 = 100x75
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -175,8 +175,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(100); $resizer->toWidth(100);
$resizer->toHeight(400); $resizer->toHeight(400);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(100, $result->width()); $this->assertEquals(100, $result->getWidth());
$this->assertEquals(75, $result->height()); $this->assertEquals(75, $result->getHeight());
// // 800x600 > 400x100 = 133x100 // // 800x600 > 400x100 = 133x100
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -184,40 +184,40 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(400); $resizer->toWidth(400);
$resizer->toHeight(100); $resizer->toHeight(100);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(133, $result->width()); $this->assertEquals(133, $result->getWidth());
$this->assertEquals(100, $result->height()); $this->assertEquals(100, $result->getHeight());
// // 800x600 > nullx300 = 400x300 // // 800x600 > nullx300 = 400x300
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toHeight(300); $resizer->toHeight(300);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
// // 800x600 > 80xnull = 80x60 // // 800x600 > 80xnull = 80x60
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(80); $resizer->toWidth(80);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(80, $result->width()); $this->assertEquals(80, $result->getWidth());
$this->assertEquals(60, $result->height()); $this->assertEquals(60, $result->getHeight());
// // 640x480 > 225xnull = 225x169 // // 640x480 > 225xnull = 225x169
$size = new Rectangle(640, 480); $size = new Rectangle(640, 480);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(225); $resizer->toWidth(225);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(225, $result->width()); $this->assertEquals(225, $result->getWidth());
$this->assertEquals(169, $result->height()); $this->assertEquals(169, $result->getHeight());
// // 640x480 > 223xnull = 223x167 // // 640x480 > 223xnull = 223x167
$size = new Rectangle(640, 480); $size = new Rectangle(640, 480);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(223); $resizer->toWidth(223);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(223, $result->width()); $this->assertEquals(223, $result->getWidth());
$this->assertEquals(167, $result->height()); $this->assertEquals(167, $result->getHeight());
// // 600x800 > 300x300 = 225x300 // // 600x800 > 300x300 = 225x300
$size = new Rectangle(600, 800); $size = new Rectangle(600, 800);
@@ -225,8 +225,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(300); $resizer->toWidth(300);
$resizer->toHeight(300); $resizer->toHeight(300);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(225, $result->width()); $this->assertEquals(225, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
// // 800x600 > 400x10 = 13x10 // // 800x600 > 400x10 = 13x10
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -234,8 +234,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(400); $resizer->toWidth(400);
$resizer->toHeight(10); $resizer->toHeight(10);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(13, $result->width()); $this->assertEquals(13, $result->getWidth());
$this->assertEquals(10, $result->height()); $this->assertEquals(10, $result->getHeight());
// // 800x600 > 1000x1200 = 1000x750 // // 800x600 > 1000x1200 = 1000x750
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
@@ -243,32 +243,32 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(1200); $resizer->toHeight(1200);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(1000, $result->width()); $this->assertEquals(1000, $result->getWidth());
$this->assertEquals(750, $result->height()); $this->assertEquals(750, $result->getHeight());
$size = new Rectangle(12000, 12); $size = new Rectangle(12000, 12);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(4000); $resizer->toWidth(4000);
$resizer->toHeight(3000); $resizer->toHeight(3000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(4000, $result->width()); $this->assertEquals(4000, $result->getWidth());
$this->assertEquals(4, $result->height()); $this->assertEquals(4, $result->getHeight());
$size = new Rectangle(12, 12000); $size = new Rectangle(12, 12000);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(4000); $resizer->toWidth(4000);
$resizer->toHeight(3000); $resizer->toHeight(3000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(3, $result->width()); $this->assertEquals(3, $result->getWidth());
$this->assertEquals(3000, $result->height()); $this->assertEquals(3000, $result->getHeight());
$size = new Rectangle(12000, 6000); $size = new Rectangle(12000, 6000);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(4000); $resizer->toWidth(4000);
$resizer->toHeight(3000); $resizer->toHeight(3000);
$result = $resizer->scale($size); $result = $resizer->scale($size);
$this->assertEquals(4000, $result->width()); $this->assertEquals(4000, $result->getWidth());
$this->assertEquals(2000, $result->height()); $this->assertEquals(2000, $result->getHeight());
} }
public function testScaleDown() public function testScaleDown()
@@ -278,91 +278,91 @@ class RectangleRectangleResizerTest extends TestCase
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(2000); $resizer->toHeight(2000);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(600); $resizer->toHeight(600);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(1000); $resizer->toWidth(1000);
$resizer->toHeight(300); $resizer->toHeight(300);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(400); $resizer->toWidth(400);
$resizer->toHeight(1000); $resizer->toHeight(1000);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(400); $resizer->toWidth(400);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toHeight(300); $resizer->toHeight(300);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(400, $result->width()); $this->assertEquals(400, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(1000); $resizer->toWidth(1000);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toHeight(1000); $resizer->toHeight(1000);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(800, $result->width()); $this->assertEquals(800, $result->getWidth());
$this->assertEquals(600, $result->height()); $this->assertEquals(600, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(100); $resizer->toWidth(100);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(100, $result->width()); $this->assertEquals(100, $result->getWidth());
$this->assertEquals(75, $result->height()); $this->assertEquals(75, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(300); $resizer->toWidth(300);
$resizer->toHeight(200); $resizer->toHeight(200);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(267, $result->width()); $this->assertEquals(267, $result->getWidth());
$this->assertEquals(200, $result->height()); $this->assertEquals(200, $result->getHeight());
$size = new Rectangle(600, 800); $size = new Rectangle(600, 800);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(300); $resizer->toWidth(300);
$resizer->toHeight(300); $resizer->toHeight(300);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(225, $result->width()); $this->assertEquals(225, $result->getWidth());
$this->assertEquals(300, $result->height()); $this->assertEquals(300, $result->getHeight());
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toWidth(400); $resizer->toWidth(400);
$resizer->toHeight(10); $resizer->toHeight(10);
$result = $resizer->scaleDown($size); $result = $resizer->scaleDown($size);
$this->assertEquals(13, $result->width()); $this->assertEquals(13, $result->getWidth());
$this->assertEquals(10, $result->height()); $this->assertEquals(10, $result->getHeight());
} }
/** /**
@@ -373,8 +373,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toSize($target); $resizer->toSize($target);
$resized = $resizer->cover($origin); $resized = $resizer->cover($origin);
$this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->getWidth(), $resized->getWidth());
$this->assertEquals($result->height(), $resized->height()); $this->assertEquals($result->getHeight(), $resized->getHeight());
} }
public function coverDataProvider(): array public function coverDataProvider(): array
@@ -400,8 +400,8 @@ class RectangleRectangleResizerTest extends TestCase
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toSize($target); $resizer->toSize($target);
$resized = $resizer->contain($origin); $resized = $resizer->contain($origin);
$this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->getWidth(), $resized->getWidth());
$this->assertEquals($result->height(), $resized->height()); $this->assertEquals($result->getHeight(), $resized->getHeight());
} }
public function containDataProvider(): array public function containDataProvider(): array
@@ -427,10 +427,10 @@ class RectangleRectangleResizerTest extends TestCase
$resizer = new RectangleResizer(); $resizer = new RectangleResizer();
$resizer->toSize($target); $resizer->toSize($target);
$resized = $resizer->crop($origin, $position); $resized = $resizer->crop($origin, $position);
$this->assertEquals($result->width(), $resized->width()); $this->assertEquals($result->getWidth(), $resized->getWidth());
$this->assertEquals($result->height(), $resized->height()); $this->assertEquals($result->getHeight(), $resized->getHeight());
$this->assertEquals($result->pivot()->getX(), $resized->pivot()->getX()); $this->assertEquals($result->getPivot()->getX(), $resized->getPivot()->getX());
$this->assertEquals($result->pivot()->getY(), $resized->pivot()->getY()); $this->assertEquals($result->getPivot()->getY(), $resized->getPivot()->getY());
} }
public function cropDataProvider(): array public function cropDataProvider(): array

View File

@@ -19,24 +19,24 @@ class RectangleTest extends TestCase
$this->assertEquals(-200, $rectangle[2]->getY()); $this->assertEquals(-200, $rectangle[2]->getY());
$this->assertEquals(0, $rectangle[3]->getX()); $this->assertEquals(0, $rectangle[3]->getX());
$this->assertEquals(-200, $rectangle[3]->getY()); $this->assertEquals(-200, $rectangle[3]->getY());
$this->assertEquals(300, $rectangle->width()); $this->assertEquals(300, $rectangle->getWidth());
$this->assertEquals(200, $rectangle->height()); $this->assertEquals(200, $rectangle->getHeight());
} }
public function testWithWidth(): void public function testWithWidth(): void
{ {
$rectangle = new Rectangle(300, 200); $rectangle = new Rectangle(300, 200);
$this->assertEquals(300, $rectangle->width()); $this->assertEquals(300, $rectangle->getWidth());
$rectangle->withWidth(400); $rectangle->setWidth(400);
$this->assertEquals(400, $rectangle->width()); $this->assertEquals(400, $rectangle->getWidth());
} }
public function testWithHeight(): void public function testWithHeight(): void
{ {
$rectangle = new Rectangle(300, 200); $rectangle = new Rectangle(300, 200);
$this->assertEquals(200, $rectangle->height()); $this->assertEquals(200, $rectangle->getHeight());
$rectangle->withHeight(800); $rectangle->setHeight(800);
$this->assertEquals(800, $rectangle->height()); $this->assertEquals(800, $rectangle->getHeight());
} }
public function testGetAspectRatio() public function testGetAspectRatio()
@@ -109,55 +109,55 @@ class RectangleTest extends TestCase
public function testSetGetPivot(): void public function testSetGetPivot(): void
{ {
$box = new Rectangle(800, 600); $box = new Rectangle(800, 600);
$pivot = $box->pivot(); $pivot = $box->getPivot();
$this->assertInstanceOf(Point::class, $pivot); $this->assertInstanceOf(Point::class, $pivot);
$this->assertEquals(0, $pivot->getX()); $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->assertInstanceOf(Rectangle::class, $result);
$this->assertEquals(10, $box->pivot()->getX()); $this->assertEquals(10, $box->getPivot()->getX());
} }
public function testAlignPivot(): void public function testAlignPivot(): void
{ {
$box = new Rectangle(640, 480); $box = new Rectangle(640, 480);
$this->assertEquals(0, $box->pivot()->getX()); $this->assertEquals(0, $box->getPivot()->getX());
$this->assertEquals(0, $box->pivot()->getY()); $this->assertEquals(0, $box->getPivot()->getY());
$box->movePivot('top-left', 3, 3); $box->movePivot('top-left', 3, 3);
$this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(3, $box->getPivot()->getX());
$this->assertEquals(3, $box->pivot()->getY()); $this->assertEquals(3, $box->getPivot()->getY());
$box->movePivot('top', 3, 3); $box->movePivot('top', 3, 3);
$this->assertEquals(320, $box->pivot()->getX()); $this->assertEquals(320, $box->getPivot()->getX());
$this->assertEquals(3, $box->pivot()->getY()); $this->assertEquals(3, $box->getPivot()->getY());
$box->movePivot('top-right', 3, 3); $box->movePivot('top-right', 3, 3);
$this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(637, $box->getPivot()->getX());
$this->assertEquals(3, $box->pivot()->getY()); $this->assertEquals(3, $box->getPivot()->getY());
$box->movePivot('left', 3, 3); $box->movePivot('left', 3, 3);
$this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(3, $box->getPivot()->getX());
$this->assertEquals(240, $box->pivot()->getY()); $this->assertEquals(240, $box->getPivot()->getY());
$box->movePivot('center', 3, 3); $box->movePivot('center', 3, 3);
$this->assertEquals(323, $box->pivot()->getX()); $this->assertEquals(323, $box->getPivot()->getX());
$this->assertEquals(243, $box->pivot()->getY()); $this->assertEquals(243, $box->getPivot()->getY());
$box->movePivot('right', 3, 3); $box->movePivot('right', 3, 3);
$this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(637, $box->getPivot()->getX());
$this->assertEquals(240, $box->pivot()->getY()); $this->assertEquals(240, $box->getPivot()->getY());
$box->movePivot('bottom-left', 3, 3); $box->movePivot('bottom-left', 3, 3);
$this->assertEquals(3, $box->pivot()->getX()); $this->assertEquals(3, $box->getPivot()->getX());
$this->assertEquals(477, $box->pivot()->getY()); $this->assertEquals(477, $box->getPivot()->getY());
$box->movePivot('bottom', 3, 3); $box->movePivot('bottom', 3, 3);
$this->assertEquals(320, $box->pivot()->getX()); $this->assertEquals(320, $box->getPivot()->getX());
$this->assertEquals(477, $box->pivot()->getY()); $this->assertEquals(477, $box->getPivot()->getY());
$result = $box->movePivot('bottom-right', 3, 3); $result = $box->movePivot('bottom-right', 3, 3);
$this->assertEquals(637, $box->pivot()->getX()); $this->assertEquals(637, $box->getPivot()->getX());
$this->assertEquals(477, $box->pivot()->getY()); $this->assertEquals(477, $box->getPivot()->getY());
$this->assertInstanceOf(Rectangle::class, $result); $this->assertInstanceOf(Rectangle::class, $result);
} }
@@ -167,32 +167,32 @@ class RectangleTest extends TestCase
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$size = new Rectangle(200, 100); $size = new Rectangle(200, 100);
$size->alignPivotTo($container, 'center'); $size->alignPivotTo($container, 'center');
$this->assertEquals(300, $size->pivot()->getX()); $this->assertEquals(300, $size->getPivot()->getX());
$this->assertEquals(250, $size->pivot()->getY()); $this->assertEquals(250, $size->getPivot()->getY());
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$size = new Rectangle(100, 100); $size = new Rectangle(100, 100);
$size->alignPivotTo($container, 'center'); $size->alignPivotTo($container, 'center');
$this->assertEquals(350, $size->pivot()->getX()); $this->assertEquals(350, $size->getPivot()->getX());
$this->assertEquals(250, $size->pivot()->getY()); $this->assertEquals(250, $size->getPivot()->getY());
$container = new Rectangle(800, 600); $container = new Rectangle(800, 600);
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$size->alignPivotTo($container, 'center'); $size->alignPivotTo($container, 'center');
$this->assertEquals(0, $size->pivot()->getX()); $this->assertEquals(0, $size->getPivot()->getX());
$this->assertEquals(0, $size->pivot()->getY()); $this->assertEquals(0, $size->getPivot()->getY());
$container = new Rectangle(100, 100); $container = new Rectangle(100, 100);
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$size->alignPivotTo($container, 'center'); $size->alignPivotTo($container, 'center');
$this->assertEquals(-350, $size->pivot()->getX()); $this->assertEquals(-350, $size->getPivot()->getX());
$this->assertEquals(-250, $size->pivot()->getY()); $this->assertEquals(-250, $size->getPivot()->getY());
$container = new Rectangle(100, 100); $container = new Rectangle(100, 100);
$size = new Rectangle(800, 600); $size = new Rectangle(800, 600);
$size->alignPivotTo($container, 'bottom-right'); $size->alignPivotTo($container, 'bottom-right');
$this->assertEquals(-700, $size->pivot()->getX()); $this->assertEquals(-700, $size->getPivot()->getX());
$this->assertEquals(-500, $size->pivot()->getY()); $this->assertEquals(-500, $size->getPivot()->getY());
} }
public function testgetRelativePositionTo(): void public function testgetRelativePositionTo(): void

View File

@@ -71,9 +71,9 @@ class TextBlockTest extends TestCase
$font->shouldReceive('capHeight')->andReturn(22); $font->shouldReceive('capHeight')->andReturn(22);
$box = $block->getBoundingBox($font, new Point(10, 15)); $box = $block->getBoundingBox($font, new Point(10, 15));
$this->assertEquals(300, $box->width()); $this->assertEquals(300, $box->getWidth());
$this->assertEquals(82, $box->height()); $this->assertEquals(82, $box->getHeight());
$this->assertEquals(10, $box->getPivotPoint()->getX()); $this->assertEquals(10, $box->getPivot()->getX());
$this->assertEquals(15, $box->getPivotPoint()->getY()); $this->assertEquals(15, $box->getPivot()->getY());
} }
} }