From c4a1ac631081cb8d775bbe594a9c903cac2da8b4 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 20 Aug 2016 13:18:25 +0100 Subject: [PATCH] fix ROUND_UP, add a test for felix's corner case --- libvips/include/vips/util.h | 2 +- test/test_resample.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index a6cc888e..5a8ecc77 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -97,7 +97,7 @@ extern "C" { /* Round N down and up to the nearest multiple of P. */ #define VIPS_ROUND_DOWN( N, P ) ((N) - ((N) % (P))) -#define VIPS_ROUND_UP( N, P ) (VIPS_ROUND_DOWN( N, P ) + (P)) +#define VIPS_ROUND_UP( N, P ) (VIPS_ROUND_DOWN( (N) + (P) - 1, (P) )) #define VIPS_SWAP( TYPE, A, B ) \ G_STMT_START { \ diff --git a/test/test_resample.py b/test/test_resample.py index ce9fb5ed..02941666 100755 --- a/test/test_resample.py +++ b/test/test_resample.py @@ -170,6 +170,12 @@ class TestResample(unittest.TestCase): self.assertEqual(im2.width, round(im.width / 4.0)) self.assertEqual(im2.height, round(im.height / 4.0)) + # test geometry rounding corner case + im = Vips.Image.black(100, 1); + x = im.resize(0.5) + self.assertEqual(x.width, 50) + self.assertEqual(x.height, 1) + def test_shrink(self): im = Vips.Image.new_from_file("images/IMG_4618.jpg") im2 = im.shrink(4, 4)