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

Add method Rectangle::setSize()

This commit is contained in:
Oliver Vogel
2022-07-20 17:24:41 +02:00
parent 50445d78e3
commit f3dd7c6090
2 changed files with 13 additions and 0 deletions

View File

@@ -20,6 +20,11 @@ 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 setSize(int $width, int $height): self
{
return $this->setWidth($width)->setHeight($height);
}
public function setWidth(int $width): self public function setWidth(int $width): self
{ {
$this[1]->setX($this[0]->getX() + $width); $this[1]->setX($this[0]->getX() + $width);

View File

@@ -23,6 +23,14 @@ class RectangleTest extends TestCase
$this->assertEquals(200, $rectangle->getHeight()); $this->assertEquals(200, $rectangle->getHeight());
} }
public function testSetSize(): void
{
$rectangle = new Rectangle(300, 200);
$rectangle->setSize(12, 34);
$this->assertEquals(12, $rectangle->getWidth());
$this->assertEquals(34, $rectangle->getHeight());
}
public function testWithWidth(): void public function testWithWidth(): void
{ {
$rectangle = new Rectangle(300, 200); $rectangle = new Rectangle(300, 200);