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:
Tim Schaub
2008-01-07 19:54:44 +00:00
parent ef3ad090c1
commit 580a44a1b3
2 changed files with 14 additions and 9 deletions

View File

@@ -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;
}