From 0fcdbb1904c2f1c32c80ebe4da367742ef6e00bc Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 5 May 2012 19:02:53 +0200 Subject: digital/avr/modules/math/geometry: slightly change intersection meaning When a segment end is exactly on the other segment, consider there is no intersection. --- digital/avr/modules/math/geometry/intersection.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'digital/avr/modules/math/geometry/intersection.c') diff --git a/digital/avr/modules/math/geometry/intersection.c b/digital/avr/modules/math/geometry/intersection.c index 1f8a9278..a1daf72d 100644 --- a/digital/avr/modules/math/geometry/intersection.c +++ b/digital/avr/modules/math/geometry/intersection.c @@ -25,18 +25,21 @@ #include "common.h" #include "intersection.h" -/** Compare a and b to determine if a / b is in [0:1]. Return non zero if +/** Compare a and b to determine if a / b is in ]0:1[. Return non zero if * true. */ static uint8_t intersection_div_is_in_0_1 (int32_t a, int32_t b) { + assert (b != 0); /* Test sign, a / b < 0 if different. */ - if ((a >> 31) ^ (b >> 31)) + if ((a ^ b) & 0x80000000) + return 0; + else if (a == 0) return 0; else if (a > 0) - return a <= b; + return a < b; else - return a >= b; + return a > b; } uint8_t -- cgit v1.2.3