diff options
Diffstat (limited to 'jstests/core/geo_s2oddshapes.js')
-rw-r--r-- | jstests/core/geo_s2oddshapes.js | 94 |
1 files changed, 35 insertions, 59 deletions
diff --git a/jstests/core/geo_s2oddshapes.js b/jstests/core/geo_s2oddshapes.js index aa284bbe20e..6f14533c928 100644 --- a/jstests/core/geo_s2oddshapes.js +++ b/jstests/core/geo_s2oddshapes.js @@ -3,60 +3,51 @@ // rather wide if their latitude (or longitude) range is large. var t = db.geo_s2oddshapes; t.drop(); -t.ensureIndex( { geo : "2dsphere" } ); +t.ensureIndex({geo: "2dsphere"}); var testPoint = { name: "origin", - geo: { - type: "Point", - coordinates: [0.0, 0.0] - } + geo: {type: "Point", coordinates: [0.0, 0.0]} }; var testHorizLine = { name: "horiz", - geo: { - type: "LineString", - coordinates: [[-2.0, 10.0], [2.0, 10.0]] - } + geo: {type: "LineString", coordinates: [[-2.0, 10.0], [2.0, 10.0]]} }; var testVertLine = { name: "vert", - geo: { - type: "LineString", - coordinates: [[10.0, -2.0], [10.0, 2.0]] - } + geo: {type: "LineString", coordinates: [[10.0, -2.0], [10.0, 2.0]]} }; t.insert(testPoint); t.insert(testHorizLine); t.insert(testVertLine); -//Test a poly that runs vertically all the way along the meridian. +// Test a poly that runs vertically all the way along the meridian. -var tallPoly = {type: "Polygon", - coordinates: [ - [[1.0, 89.0], [-1.0, 89.0], [-1.0, -89.0], [1.0, -89.0], [1.0, 89.0]] - ]}; -//We expect that the testPoint (at the origin) will be within this poly. +var tallPoly = { + type: "Polygon", + coordinates: [[[1.0, 89.0], [-1.0, 89.0], [-1.0, -89.0], [1.0, -89.0], [1.0, 89.0]]] +}; +// We expect that the testPoint (at the origin) will be within this poly. var result = t.find({geo: {$within: {$geometry: tallPoly}}}); assert.eq(result.itcount(), 1); var result = t.find({geo: {$within: {$geometry: tallPoly}}}); assert.eq(result[0].name, 'origin'); -//We expect that the testPoint, and the testHorizLine should geoIntersect -//with this poly. +// We expect that the testPoint, and the testHorizLine should geoIntersect +// with this poly. result = t.find({geo: {$geoIntersects: {$geometry: tallPoly}}}); assert.eq(result.itcount(), 2); result = t.find({geo: {$geoIntersects: {$geometry: tallPoly}}}); -//Test a poly that runs horizontally along the equator. +// Test a poly that runs horizontally along the equator. -var longPoly = {type: "Polygon", - coordinates: [ - [[89.0, 1.0], [-89.0, 1.0], [-89.0, -1.0], [89.0, -1.0], [89.0, 1.0]] - ]}; +var longPoly = { + type: "Polygon", + coordinates: [[[89.0, 1.0], [-89.0, 1.0], [-89.0, -1.0], [89.0, -1.0], [89.0, 1.0]]] +}; // Thanks to spherical geometry, this poly contains most of the hemisphere. result = t.find({geo: {$within: {$geometry: longPoly}}}); @@ -64,36 +55,28 @@ assert.eq(result.itcount(), 3); result = t.find({geo: {$geoIntersects: {$geometry: longPoly}}}); assert.eq(result.itcount(), 3); -//Test a poly that is the size of half the earth. +// Test a poly that is the size of half the earth. t.drop(); -t.ensureIndex( { geo : "2dsphere" } ); +t.ensureIndex({geo: "2dsphere"}); var insidePoint = { name: "inside", - geo: { - type: "Point", - name: "inside", - coordinates: [100.0, 0.0] - } + geo: {type: "Point", name: "inside", coordinates: [100.0, 0.0]} }; var outsidePoint = { name: "inside", - geo: { - type: "Point", - name: "inside", - coordinates: [-100.0, 0.0] - } + geo: {type: "Point", name: "inside", coordinates: [-100.0, 0.0]} }; t.insert(insidePoint); t.insert(outsidePoint); -var largePoly = {type: "Polygon", - coordinates: [ - [[0.0, -90.0], [0.0, 90.0], [180.0, 0], [0.0, -90.0]] - ]}; +var largePoly = { + type: "Polygon", + coordinates: [[[0.0, -90.0], [0.0, 90.0], [180.0, 0], [0.0, -90.0]]] +}; result = t.find({geo: {$within: {$geometry: largePoly}}}); assert.eq(result.itcount(), 1); @@ -101,38 +84,31 @@ result = t.find({geo: {$within: {$geometry: largePoly}}}); var point = result[0]; assert.eq(point.name, 'inside'); -//Test a poly that is very small. A couple meters around. +// Test a poly that is very small. A couple meters around. t.drop(); -t.ensureIndex( { geo : "2dsphere" } ); +t.ensureIndex({geo: "2dsphere"}); insidePoint = { name: "inside", - geo: { - type: "Point", - name: "inside", - coordinates: [0.01, 0.0] - }}; + geo: {type: "Point", name: "inside", coordinates: [0.01, 0.0]} +}; outsidePoint = { name: "inside", - geo: { - type: "Point", - name: "inside", - coordinates: [0.2, 0.0] - }}; + geo: {type: "Point", name: "inside", coordinates: [0.2, 0.0]} +}; t.insert(insidePoint); t.insert(outsidePoint); -smallPoly = {type: "Polygon", - coordinates: [ - [[0.0, -0.01], [0.015, -0.01], [0.015, 0.01], [0.0, 0.01], [0.0, -0.01]] - ]}; +smallPoly = { + type: "Polygon", + coordinates: [[[0.0, -0.01], [0.015, -0.01], [0.015, 0.01], [0.0, 0.01], [0.0, -0.01]]] +}; result = t.find({geo: {$within: {$geometry: smallPoly}}}); assert.eq(result.itcount(), 1); result = t.find({geo: {$within: {$geometry: smallPoly}}}); point = result[0]; assert.eq(point.name, 'inside'); - |