diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7d..115c0dde 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -7,14 +7,8 @@ assignees: '' --- -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** +**Describe the feature you'd like** A clear and concise description of what you want to happen. -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] diff --git a/src/Geometry/Tools/RectangleResizer.php b/src/Geometry/Tools/RectangleResizer.php index 38292da1..0f78f11c 100644 --- a/src/Geometry/Tools/RectangleResizer.php +++ b/src/Geometry/Tools/RectangleResizer.php @@ -12,7 +12,17 @@ class RectangleResizer protected ?int $width = null, protected ?int $height = null, ) { - // + if (is_int($width) && $width < 1) { + throw new GeometryException( + 'The width you specify must be greater than or equal to 1.' + ); + } + + if (is_int($height) && $height < 1) { + throw new GeometryException( + 'The height you specify must be greater than or equal to 1.' + ); + } } public static function to(...$arguments): self @@ -77,7 +87,7 @@ class RectangleResizer return $size->width(); } - return (int) round($this->height * $size->aspectRatio()); + return max([1, (int) round($this->height * $size->aspectRatio())]); } protected function getProportionalHeight(SizeInterface $size): int @@ -86,7 +96,7 @@ class RectangleResizer return $size->height(); } - return (int) round($this->width / $size->aspectRatio()); + return max([1, (int) round($this->width / $size->aspectRatio())]); } public function resize(SizeInterface $size): SizeInterface diff --git a/tests/Geometry/RectangleResizerTest.php b/tests/Geometry/RectangleResizerTest.php index bcc569b4..fe7ce1fd 100644 --- a/tests/Geometry/RectangleResizerTest.php +++ b/tests/Geometry/RectangleResizerTest.php @@ -269,6 +269,13 @@ class RectangleResizerTest extends TestCase $result = $resizer->scale($size); $this->assertEquals(4000, $result->width()); $this->assertEquals(2000, $result->height()); + + $size = new Rectangle(3, 3000); + $resizer = new RectangleResizer(); + $resizer->toHeight(300); + $result = $resizer->scale($size); + $this->assertEquals(1, $result->width()); + $this->assertEquals(300, $result->height()); } public function testScaleDown() @@ -363,6 +370,13 @@ class RectangleResizerTest extends TestCase $result = $resizer->scaleDown($size); $this->assertEquals(13, $result->width()); $this->assertEquals(10, $result->height()); + + $size = new Rectangle(3, 3000); + $resizer = new RectangleResizer(); + $resizer->toHeight(300); + $result = $resizer->scale($size); + $this->assertEquals(1, $result->width()); + $this->assertEquals(300, $result->height()); } /**