[OpenLayers-Commits] r5673 - in trunk/openlayers: lib/OpenLayers/Geometry tests/data

commits at openlayers.org commits at openlayers.org
Mon Jan 7 14:54:44 EST 2008


Author: tschaub
Date: 2008-01-07 14:54:44 -0500 (Mon, 07 Jan 2008)
New Revision: 5673

Modified:
   trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js
   trunk/openlayers/tests/data/geos_wkt_intersects.js
Log:
Getting explicit about precision.  We now support thirteen significant digits in coordinates when testing for geometry intersections. r=pspencer (closes #1245)

Modified: trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js	2008-01-07 18:57:38 UTC (rev 5672)
+++ trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js	2008-01-07 19:54:44 UTC (rev 5673)
@@ -212,8 +212,10 @@
      *     the point is coincident with an edge.  Returns boolean otherwise.
      */
     containsPoint: function(point) {
-        var px = point.x;
-        var py = point.y;
+        var approx = OpenLayers.Number.limitSigDigs;
+        var digs = 14;
+        var px = approx(point.x, digs);
+        var py = approx(point.y, digs);
         function getX(y, x1, y1, x2, y2) {
             return (((x1 - x2) * y) + ((x2 * y1) - (x1 * y2))) / (y1 - y2);
         }
@@ -222,11 +224,11 @@
         var crosses = 0;
         for(var i=0; i<numSeg; ++i) {
             start = this.components[i];
-            x1 = start.x;
-            y1 = start.y;
+            x1 = approx(start.x, digs);
+            y1 = approx(start.y, digs);
             end = this.components[i + 1];
-            x2 = end.x;
-            y2 = end.y;
+            x2 = approx(end.x, digs);
+            y2 = approx(end.y, digs);
             
             /**
              * The following conditions enforce five edge-crossing rules:
@@ -253,7 +255,7 @@
                 // ignore other horizontal edges
                 continue;
             }
-            cx = getX(py, x1, y1, x2, y2);
+            cx = approx(getX(py, x1, y1, x2, y2), digs);
             if(cx == px) {
                 // point on line
                 if(y1 < y2 && (py >= y1 && py <= y2) || // upward
@@ -267,7 +269,7 @@
                 // no crossing to the right
                 continue;
             }
-            if(cx < Math.min(x1, x2) || cx > Math.max(x1, x2)) {
+            if(x1 != x2 && (cx < Math.min(x1, x2) || cx > Math.max(x1, x2))) {
                 // no crossing
                 continue;
             }

Modified: trunk/openlayers/tests/data/geos_wkt_intersects.js
===================================================================
--- trunk/openlayers/tests/data/geos_wkt_intersects.js	2008-01-07 18:57:38 UTC (rev 5672)
+++ trunk/openlayers/tests/data/geos_wkt_intersects.js	2008-01-07 19:54:44 UTC (rev 5673)
@@ -488,5 +488,8 @@
 {'wkt1':'MULTIPOINT (20 20,80 70,140 120,200 170)', 'wkt2':'MULTIPOINT (80 70,140 120)', result:true},
 {'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (140 120,80 70)', result:true},
 {'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (80 170,140 120,200 80)', result:true},
-{'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (80 170,140 120,200 80,80 70)', result:true}
+{'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (80 170,140 120,200 80,80 70)', result:true},
+{'wkt1':'POLYGON((-8239529.462853361 4980952.065110421,-8224242.057199065 4980952.065110421,-8224242.057199064 4988844.188279452,-8239529.462853361 4988844.188279452,-8239529.462853361 4980952.065110421))', 'wkt2':'POINT(-8225445.94039435  4982695.78481786)', result:true},
+{'wkt1':'POLYGON((-8239529.462853361 4980952.065110421,-8224242.057199065 4980952.065110421,-8224242.057199064 4988844.188279452,-8239529.462853361 4988844.188279452,-8239529.462853361 4980952.065110421))', 'wkt2':'POINT(-8224242.0571985  4982695.78481786)', result:false},
+{'wkt1':'POLYGON((-8239529.462853361 4980952.065110421,-8224242.057199065 4980952.065110421,-8224242.057199064 4988844.188279452,-8239529.462853361 4988844.188279452,-8239529.462853361 4980952.065110421))', 'wkt2':'POINT(-8224242.0571995  4982695.78481786)', result:true}
 ];



More information about the Commits mailing list