]> granicus.if.org Git - poly2tri-c/commitdiff
Fix the TolerantIsPowerOfTwoLength function
authorBarak Itkin <lightningismyname@gmail.com>
Fri, 18 May 2012 13:36:03 +0000 (16:36 +0300)
committerBarak Itkin <lightningismyname@gmail.com>
Fri, 18 May 2012 13:36:03 +0000 (16:36 +0300)
refine/delaunay-terminator.c

index e7a9df2eb9bb9670bf310fc6aca1c05424396bea..41bf550d0f29e5cae8e82a07db80aaaced5208b2 100644 (file)
@@ -397,10 +397,18 @@ LOG2 (gdouble v)
 static gboolean
 TolerantIsPowerOfTwoLength (gdouble length)
 {
-    gdouble exp = LOG2 (length);
-    gdouble intpart, frac = modf (exp, &intpart);
-    
-    return ABS(frac) < 0.05;
+  gdouble exp = LOG2 (length);
+  gdouble intpart, frac = modf (exp, &intpart);
+  gdouble distance;
+
+  /* If the length is a negative power of 2, the returned fraction will be
+   * negative */
+  frac = ABS(frac);
+
+  /* Find how close is exp to the closest integer */
+  distance = MIN(frac, 1-frac);
+
+  return distance < 0.05;
 }
 
 static void