From 8739613cfb3731a1411de09c71161ef217ea2ca1 Mon Sep 17 00:00:00 2001 From: Terseus Date: Tue, 1 Apr 2014 13:08:15 +0200 Subject: [PATCH] Implementation of rounds around zero The rounds used in the library are towards positive/negative infinity. Since we're in a cartesian plane, rounds around zero are much more convenient, so we can use positive and negative values with consistent results. --- libImaging/Draw.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libImaging/Draw.c b/libImaging/Draw.c index 1241c8d3b..c29132112 100644 --- a/libImaging/Draw.c +++ b/libImaging/Draw.c @@ -49,6 +49,13 @@ #define BLEND(mask, in1, in2, tmp1, tmp2)\ (MULDIV255(in1, 255 - mask, tmp1) + MULDIV255(in2, mask, tmp2)) +/* + * Rounds around zero (up=torwards zero, down=away from zero) + * This guarantees that ROUND_UP|DOWN(f) == -ROUND_UP|DOWN(-f) + */ +#define ROUND_UP(f) ((int) ((f) >= 0.0 ? floor((f) + 0.5F) : -floor(fabs(f) + 0.5F))) +#define ROUND_DOWN(f) ((int) ((f) >= 0.0 ? ceil((f) - 0.5F) : -ceil(fabs(f) - 0.5F))) + /* -------------------------------------------------------------------- */ /* Primitives */ /* -------------------------------------------------------------------- */