From 66b28952384a7e6e5918fbd2238689fcd4677574 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Tue, 2 Jan 2024 12:51:33 +0100 Subject: [PATCH 1/3] Limit proportional sclaing values to a min. of 1 --- src/Geometry/Tools/RectangleResizer.php | 4 ++-- tests/Geometry/RectangleResizerTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Geometry/Tools/RectangleResizer.php b/src/Geometry/Tools/RectangleResizer.php index 38292da1..935e1af4 100644 --- a/src/Geometry/Tools/RectangleResizer.php +++ b/src/Geometry/Tools/RectangleResizer.php @@ -77,7 +77,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 +86,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()); } /** From ec1fead71fecbdcc2117194a72ea9d85b4051b55 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Tue, 2 Jan 2024 13:03:44 +0100 Subject: [PATCH 2/3] Throw exceptions if resizer receives unvalid values --- src/Geometry/Tools/RectangleResizer.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Geometry/Tools/RectangleResizer.php b/src/Geometry/Tools/RectangleResizer.php index 935e1af4..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 From ceacb64949c7989f271fc07d4409caaa67ce10fe Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 4 Jan 2024 09:52:00 +0100 Subject: [PATCH 3/3] Change feature request template --- .github/ISSUE_TEMPLATE/feature_request.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) 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 [...]