OpenLayers OpenLayers

Changeset 5673

Show
Ignore:
Timestamp:
01/07/08 14:54:44 (1 year ago)
Author:
tschaub
Message:

Getting explicit about precision. We now support thirteen significant digits in coordinates when testing for geometry intersections. r=pspencer (closes #1245)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Geometry/LinearRing.js

    r5614 r5673  
    213213     */ 
    214214    containsPoint: function(point) { 
    215         var px = point.x; 
    216         var py = point.y; 
     215        var approx = OpenLayers.Number.limitSigDigs; 
     216        var digs = 14; 
     217        var px = approx(point.x, digs); 
     218        var py = approx(point.y, digs); 
    217219        function getX(y, x1, y1, x2, y2) { 
    218220            return (((x1 - x2) * y) + ((x2 * y1) - (x1 * y2))) / (y1 - y2); 
     
    223225        for(var i=0; i<numSeg; ++i) { 
    224226            start = this.components[i]; 
    225             x1 = start.x
    226             y1 = start.y
     227            x1 = approx(start.x, digs)
     228            y1 = approx(start.y, digs)
    227229            end = this.components[i + 1]; 
    228             x2 = end.x
    229             y2 = end.y
     230            x2 = approx(end.x, digs)
     231            y2 = approx(end.y, digs)
    230232             
    231233            /** 
     
    254256                continue; 
    255257            } 
    256             cx = getX(py, x1, y1, x2, y2); 
     258            cx = approx(getX(py, x1, y1, x2, y2), digs); 
    257259            if(cx == px) { 
    258260                // point on line 
     
    268270                continue; 
    269271            } 
    270             if(cx < Math.min(x1, x2) || cx > Math.max(x1, x2)) { 
     272            if(x1 != x2 && (cx < Math.min(x1, x2) || cx > Math.max(x1, x2))) { 
    271273                // no crossing 
    272274                continue; 
  • trunk/openlayers/tests/data/geos_wkt_intersects.js

    r5458 r5673  
    489489{'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (140 120,80 70)', result:true}, 
    490490{'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (80 170,140 120,200 80)', result:true}, 
    491 {'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (80 170,140 120,200 80,80 70)', result:true} 
     491{'wkt1':'MULTIPOINT (80 70,20 20,200 170,140 120)', 'wkt2':'MULTIPOINT (80 170,140 120,200 80,80 70)', result:true}, 
     492{'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}, 
     493{'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}, 
     494{'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} 
    492495];