diff --git a/src/Geometry/Rectangle.php b/src/Geometry/Rectangle.php index 3e6e68fc..1a9cc547 100644 --- a/src/Geometry/Rectangle.php +++ b/src/Geometry/Rectangle.php @@ -20,6 +20,11 @@ class Rectangle extends Polygon implements SizeInterface $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 { $this[1]->setX($this[0]->getX() + $width); diff --git a/tests/Geometry/RectangleTest.php b/tests/Geometry/RectangleTest.php index 87befb70..858238e2 100644 --- a/tests/Geometry/RectangleTest.php +++ b/tests/Geometry/RectangleTest.php @@ -23,6 +23,14 @@ class RectangleTest extends TestCase $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 { $rectangle = new Rectangle(300, 200);