diff options
Diffstat (limited to 'jstests')
-rwxr-xr-x | jstests/geo_s2edgecases.js | 8 | ||||
-rw-r--r-- | jstests/geo_s2nearComplex.js | 18 |
2 files changed, 18 insertions, 8 deletions
diff --git a/jstests/geo_s2edgecases.js b/jstests/geo_s2edgecases.js index 02bd17d8b9f..bf46baba744 100755 --- a/jstests/geo_s2edgecases.js +++ b/jstests/geo_s2edgecases.js @@ -5,20 +5,20 @@ roundworldpoint = { "type" : "Point", "coordinates": [ 180, 0 ] } // Opposite the equator roundworld = { "type" : "Polygon", - "coordinates" : [ [ [179,1], [181,1], [181,-1], [179,-1], [179,1]]]} + "coordinates" : [ [ [179,1], [-179,1], [-179,-1], [179,-1], [179,1]]]} t.insert({geo : roundworld}) roundworld2 = { "type" : "Polygon", - "coordinates" : [ [ [179,1], [179,-1], [181,-1], [181,1], [179,1]]]} + "coordinates" : [ [ [179,1], [179,-1], [-179,-1], [-179,1], [179,1]]]} t.insert({geo : roundworld2}) // North pole santapoint = { "type" : "Point", "coordinates": [ 180, 90 ] } santa = { "type" : "Polygon", - "coordinates" : [ [ [179,89], [179,90], [181,90], [181,89], [179,89]]]} + "coordinates" : [ [ [179,89], [179,90], [-179,90], [-179,89], [179,89]]]} t.insert({geo : santa}) santa2 = { "type" : "Polygon", - "coordinates" : [ [ [179,89], [181,89], [181,90], [179,90], [179,89]]]} + "coordinates" : [ [ [179,89], [-179,89], [-179,90], [179,90], [179,89]]]} t.insert({geo : santa2}) // South pole diff --git a/jstests/geo_s2nearComplex.js b/jstests/geo_s2nearComplex.js index 78a055d719b..87dd034ca24 100644 --- a/jstests/geo_s2nearComplex.js +++ b/jstests/geo_s2nearComplex.js @@ -59,15 +59,25 @@ function uniformPoints(origin, count, minDist, maxDist){ var pointLat = asin((sin(lat) * cos(distance)) + (cos(lat) * sin(distance) * cos(angle))); var pointDLng = atan2(sin(angle) * sin(distance) * cos(lat), cos(distance) - sin(lat) * sin(pointLat)); var pointLng = ((lng - pointDLng + PI) % 2*PI) - PI; + + // Latitude must be [-90, 90] + var newLat = lat + pointLat; + if (newLat > 90) newLat -= 180; + if (newLat < -90) newLat += 180; + + // Longitude must be [-180, 180] + var newLng = lng + pointLng; + if (newLng > 180) newLng -= 360; + if (newLng < -180) newLng += 360; + var newPoint = { geo: { type: "Point", - coordinates: [lng + pointLng, lat + pointLat] + //coordinates: [lng + pointLng, lat + pointLat] + coordinates: [newLng, newLat] } }; - if(lat + pointLat > 90.0){ - continue; - } + points.push(newPoint); } for(i=0; i < points.length; i++){ |