[postgis-commits] svn - r3372 - trunk/liblwgeom

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Tue Dec 9 15:29:31 PST 2008


Author: mleslie
Date: 2008-12-09 15:29:31 -0800 (Tue, 09 Dec 2008)
New Revision: 3372

Modified:
   trunk/liblwgeom/liblwgeom.h
   trunk/liblwgeom/lwcurve.c
Log:
Porting the floating point comparison operator upgrade from the 1.3 branch.

Modified: trunk/liblwgeom/liblwgeom.h
===================================================================
--- trunk/liblwgeom/liblwgeom.h	2008-12-07 04:05:51 UTC (rev 3371)
+++ trunk/liblwgeom/liblwgeom.h	2008-12-09 23:29:31 UTC (rev 3372)
@@ -15,6 +15,8 @@
 #define FP_MIN(A, B) ((A < B) ? A : B)
 #define FP_LT(A, B) ((A + PGIS_EPSILON) < B)
 #define FP_LTEQ(A, B) ((A - PGIS_EPSILON) <= B)
+#define FP_GT(A, B) ((A - PGIS_EPSILON) > B)
+#define FP_GTEQ(A, B) ((A + PGIS_EPSILON) >= B)
 #define FP_CONTAINS_TOP(A, X, B) (FP_LT(A, X) && FP_LTEQ(X, B))
 #define FP_CONTAINS_BOTTOM(A, X, B) (FP_LTEQ(A, X) && FP_LT(X, B))
 #define FP_CONTAINS_INCL(A, X, B) (FP_LTEQ(A, X) && FP_LTEQ(X, B))

Modified: trunk/liblwgeom/lwcurve.c
===================================================================
--- trunk/liblwgeom/lwcurve.c	2008-12-07 04:05:51 UTC (rev 3371)
+++ trunk/liblwgeom/lwcurve.c	2008-12-09 23:29:31 UTC (rev 3372)
@@ -309,34 +309,34 @@
          */
 
         // clockwise 1
-        if(r2 < 0 && (r3 > 0 || r3 < r2))
+        if(FP_LT(r2, 0) && (FP_GT(r3, 0) || FP_LT(r3, r2)))
         {
-            sweep = (r3 > 0) ? (r3 - 2 * M_PI) : r3;
+            sweep = (FP_GT(r3, 0)) ? (r3 - 2 * M_PI) : r3;
         }
         // clockwise 2
-        else if(r2 > 0 && r3 > 0 && r3 < r2)
+        else if(FP_GT(r2, 0) && FP_GT(r3, 0) && FP_LT(r3, r2))
         {
-            sweep = (r3 > 0) ? (r3 - 2 * M_PI) : r3;
+            sweep = (FP_GT(r3, 0)) ? (r3 - 2 * M_PI) : r3;
         }
         // counter-clockwise 4
-        else if(r2 > 0 && (r3 < 0 || r3 > r2))
+        else if(FP_GT(r2, 0) && (FP_LT(r3, 0) || FP_GT(r3, r2)))
         {
-            sweep = (r3 < 0) ? (r3 + 2 * M_PI) : r3;
+            sweep = (FP_LT(r3, 0)) ? (r3 + 2 * M_PI) : r3;
         }
         // counter-clockwisk 5
-        else if(r2 < 0 && r3 < 0 && r3 > r2)
+        else if(FP_LT(r2, 0) && FP_LT(r3, 0) && FP_GT(r3, r2))
         {
-            sweep = (r3 < 0) ? (r3 + 2 * M_PI) : r3;
+            sweep = (FP_LT(r3, 0)) ? (r3 + 2 * M_PI) : r3;
         }
         // clockwise invalid 3
-        else if(r2 > 0 && (r3 > r2 || r3 < 0))
+        else if(FP_GT(r2, 0) && (FP_GT(r3, r2) || FP_LT(r3, 0)))
         {
-            sweep = (r2 > 0) ? (r2 - 2 * M_PI) : r2;
+            sweep = (FP_GT(r2, 0)) ? (r2 - 2 * M_PI) : r2;
         }
         // clockwise invalid 6
         else
         {
-            sweep = (r2 < 0) ? (r2 + 2 * M_PI) : r2;
+            sweep = (FP_LT(r2, 0)) ? (r2 + 2 * M_PI) : r2;
         }
 
         LWDEBUGF(3, "a1 %.16f, a2 %.16f, a3 %.16f, sweep %.16f", a1, a2, a3, sweep);
@@ -385,36 +385,36 @@
 		// determine if the extents are outside the arc
                 if(i < 4) 
                 {
-		    if(sweep > 0.0)
+		    if(FP_GT(sweep, 0.0))
 		    {
-		        if(a3 < a1)
+		        if(FP_LT(a3, a1))
 		        {
-			    if(angle > (a3 + 2 * M_PI) || angle < a1) continue;
+			    if(FP_GT(angle, (a3 + 2 * M_PI)) || FP_LT(angle, a1)) continue;
 		        }
 		        else
 		        {
-			    if(angle > a3 || angle < a1) continue;
+			    if(FP_GT(angle, a3) || FP_LT(angle, a1)) continue;
 		        }
                     }
 		    else
 		    {
-		        if(a3 > a1)
+		        if(FP_GT(a3, a1))
 		        {
-			    if(angle < (a3 - 2 * M_PI) || angle > a1) continue;
+			    if(FP_LT(angle, (a3 - 2 * M_PI)) || FP_GT(angle, a1)) continue;
 		        }
 		        else
 		        {
-			    if(angle < a3 || angle > a1) continue;
+			    if(FP_LT(angle, a3) || FP_GT(angle, a1)) continue;
 		        }
 		    }
 		}
 
                 LWDEBUGF(3, "lwcircle_compute_box3d: potential extreame %d (%.16f, %.16f)", i, xe, ye);
 
-                x1 = (x1 < xe) ? x1 : xe;
-                y1 = (y1 < ye) ? y1 : ye;
-                x2 = (x2 > xe) ? x2 : xe;
-                y2 = (y2 > ye) ? y2 : ye;
+                x1 = (FP_LT(x1, xe)) ? x1 : xe;
+                y1 = (FP_LT(y1, ye)) ? y1 : ye;
+                x2 = (FP_GT(x2, xe)) ? x2 : xe;
+                y2 = (FP_GT(y2, ye)) ? y2 : ye;
         }
 
         LWDEBUGF(3, "lwcircle_compute_box3d: extreames found (%.16f %.16f, %.16f %.16f)", x1, y1, x2, y2);
@@ -425,10 +425,10 @@
         y1 = center->y + y1 * radius;
         y2 = center->y + y2 * radius;
         */
-        z1 = (p1->z < p2->z) ? p1->z : p2->z;
-        z1 = (z1 < p3->z) ? z1 : p3->z;
-        z2 = (p1->z > p2->z) ? p1->z : p2->z;
-        z2 = (z2 > p3->z) ? z2 : p3->z;
+        z1 = (FP_LT(p1->z, p2->z)) ? p1->z : p2->z;
+        z1 = (FP_LT(z1, p3->z)) ? z1 : p3->z;
+        z2 = (FP_GT(p1->z, p2->z)) ? p1->z : p2->z;
+        z2 = (FP_GT(z2, p3->z)) ? z2 : p3->z;
 
         box = lwalloc(sizeof(BOX3D));
         box->xmin = x1; box->xmax = x2;



More information about the postgis-commits mailing list