Getting explicit about precision. We now support thirteen significant digits in coordinates when testing for geometry intersections. r=pspencer (closes #1245)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5673 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -212,8 +212,10 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
* 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 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
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 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
// 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 @@ OpenLayers.Geometry.LinearRing = OpenLayers.Class(
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -488,5 +488,8 @@ var geos_test_data = [
|
||||
{'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}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user