summaryrefslogtreecommitdiff
path: root/jstests/core/geo_s2overlappingpolys.js
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:17:50 -0500
committerJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:18:14 -0500
commit4ae691e8edc87d0e3cfb633bb91c328426be007b (patch)
tree52079a593f54382ca13a2e741633eab1b6271893 /jstests/core/geo_s2overlappingpolys.js
parenta025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff)
downloadmongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/core/geo_s2overlappingpolys.js')
-rw-r--r--jstests/core/geo_s2overlappingpolys.js195
1 files changed, 110 insertions, 85 deletions
diff --git a/jstests/core/geo_s2overlappingpolys.js b/jstests/core/geo_s2overlappingpolys.js
index 819879d960d..485132039d5 100644
--- a/jstests/core/geo_s2overlappingpolys.js
+++ b/jstests/core/geo_s2overlappingpolys.js
@@ -1,57 +1,55 @@
var t = db.geo_s2overlappingpolys;
t.drop();
-t.ensureIndex( { geo : "2dsphere" } );
+t.ensureIndex({geo: "2dsphere"});
var minError = 0.8e-13;
-var canonPoly = {type: "Polygon",
- coordinates: [
- [[-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0]]
- ]};
+var canonPoly = {
+ type: "Polygon",
+ coordinates: [[[-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0]]]
+};
t.insert({geo: canonPoly});
-// Test 1: If a poly completely encloses the canonPoly, we expect the canonPoly
-// to be returned for both $within and $geoIntersect
+// Test 1: If a poly completely encloses the canonPoly, we expect the canonPoly
+// to be returned for both $within and $geoIntersect
-var outerPoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0]]
- ]};
+var outerPoly = {
+ type: "Polygon",
+ coordinates: [[[-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0]]]
+};
var result = t.find({geo: {$within: {$geometry: outerPoly}}});
assert.eq(result.itcount(), 1);
result = t.find({geo: {$geoIntersects: {$geometry: outerPoly}}});
assert.eq(result.itcount(), 1);
-
// Test 2: If a poly that covers half of the canonPoly, we expect that it should
// geoIntersect, but should not be within.
-var partialPoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -2.0], [2.0, -2.0], [2.0, 0.0], [-2.0, 0.0], [-2.0, -2.0]]
- ]};
+var partialPoly = {
+ type: "Polygon",
+ coordinates: [[[-2.0, -2.0], [2.0, -2.0], [2.0, 0.0], [-2.0, 0.0], [-2.0, -2.0]]]
+};
-//Should not be within
+// Should not be within
result = t.find({geo: {$within: {$geometry: partialPoly}}});
assert.eq(result.itcount(), 0);
-//This should however count as a geoIntersect
+// This should however count as a geoIntersect
result = t.find({geo: {$geoIntersects: {$geometry: partialPoly}}});
assert.eq(result.itcount(), 1);
-
-// Test 3: Polygons that intersect at a point or an edge have undefined
-// behaviour in s2 The s2 library we're using appears to have
+// Test 3: Polygons that intersect at a point or an edge have undefined
+// behaviour in s2 The s2 library we're using appears to have
// the following behaviour.
// Case (a): Polygons that intersect at one point (not a vertex).
// behaviour: geoIntersects.
-var sharedPointPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -2.0], [0.0, -1.0], [1.0, -2.0], [0.0, -2.0]]
- ]};
+var sharedPointPoly = {
+ type: "Polygon",
+ coordinates: [[[0.0, -2.0], [0.0, -1.0], [1.0, -2.0], [0.0, -2.0]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: sharedPointPoly}}});
assert.eq(result.itcount(), 1);
@@ -59,34 +57,33 @@ assert.eq(result.itcount(), 1);
// Case (b): Polygons that intersect at one point (a vertex).
// behaviour: not geoIntersect
-var sharedVertexPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -2.0], [1.0, -1.0], [1.0, -2.0], [0.0, -2.0]]
- ]};
+var sharedVertexPoly = {
+ type: "Polygon",
+ coordinates: [[[0.0, -2.0], [1.0, -1.0], [1.0, -2.0], [0.0, -2.0]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: sharedVertexPoly}}});
assert.eq(result.itcount(), 0);
-// Case (c): Polygons that intesersect at one point that is very close to a
+// Case (c): Polygons that intesersect at one point that is very close to a
// vertex should have the same behaviour as Case (b).
-var almostSharedVertexPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -2.0], [1.0 - minError, -1.0], [1.0, -2.0], [0.0, -2.0]]
- ]};
+var almostSharedVertexPoly = {
+ type: "Polygon",
+ coordinates: [[[0.0, -2.0], [1.0 - minError, -1.0], [1.0, -2.0], [0.0, -2.0]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: almostSharedVertexPoly}}});
assert.eq(result.itcount(), 0);
-
-// Case (d): Polygons that intesersect at one point that is not quite as close
-// to a vertex should behave as though it were not a vertex, and should
+// Case (d): Polygons that intesersect at one point that is not quite as close
+// to a vertex should behave as though it were not a vertex, and should
// geoIntersect
-var notCloseEnoughSharedVertexPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -2.0], [1.0 - (10 * minError), -1.0], [1.0, -2.0], [0.0, -2.0]]
- ]};
+var notCloseEnoughSharedVertexPoly = {
+ type: "Polygon",
+ coordinates: [[[0.0, -2.0], [1.0 - (10 * minError), -1.0], [1.0, -2.0], [0.0, -2.0]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: notCloseEnoughSharedVertexPoly}}});
assert.eq(result.itcount(), 1);
@@ -94,40 +91,39 @@ assert.eq(result.itcount(), 1);
// Case (e): Polygons that come very close to having a point intersection
// on a non-vertex coordinate should intersect.
-var almostSharedPointPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -2.0], [0.0, (-1.0 - minError)], [1.0, -2.0], [0.0, -2.0]]
- ]};
+var almostSharedPointPoly = {
+ type: "Polygon",
+ coordinates: [[[0.0, -2.0], [0.0, (-1.0 - minError)], [1.0, -2.0], [0.0, -2.0]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: almostSharedPointPoly}}});
assert.eq(result.itcount(), 1);
-
// Case (f): If we increase the error a little, it should no longer act
// as though it's intersecting.
// NOTE: I think this error bound seems odd. Going to 0.000152297 will break this test.
// I've confirmed there is an error bound, but it's a lot larger than we experienced above.
var errorBound = 0.000152298;
-var notCloseEnoughSharedPointPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -2.0], [0.0, -1.0 - errorBound], [1.0, -2.0], [0.0, -2.0]]
- ]};
+var notCloseEnoughSharedPointPoly = {
+ type: "Polygon",
+ coordinates: [[[0.0, -2.0], [0.0, -1.0 - errorBound], [1.0, -2.0], [0.0, -2.0]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: notCloseEnoughSharedPointPoly}}});
assert.eq(result.itcount(), 0);
-/* Test 3: Importantly, polygons with shared edges have undefined intersection
- * under s2. Therefore these test serve more to make sure nothing changes than
+/* Test 3: Importantly, polygons with shared edges have undefined intersection
+ * under s2. Therefore these test serve more to make sure nothing changes than
* to confirm an expected behaviour.
*/
// Case 1: A polygon who shares an edge with another polygon, where the searching
// polygon's edge is fully covered by the canon polygon's edge.
// Result: No intersection.
-var fullyCoveredEdgePoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -0.5], [-1.0, -0.5], [-1.0, 0.5], [-2.0, 0.5], [-2.0, -0.5]]
- ]};
+var fullyCoveredEdgePoly = {
+ type: "Polygon",
+ coordinates: [[[-2.0, -0.5], [-1.0, -0.5], [-1.0, 0.5], [-2.0, 0.5], [-2.0, -0.5]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: fullyCoveredEdgePoly}}});
assert.eq(result.itcount(), 0);
@@ -135,10 +131,10 @@ assert.eq(result.itcount(), 0);
// Case 2: A polygon who shares an edge with another polygon, where the searching
// polygon's edge fully covers the canon polygon's edge.
// Result: Intersection.
-var coveringEdgePoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -1.5], [-1.0, -1.5], [-1.0, 1.5], [-2.0, 1.5], [-2.0, -1.5]]
- ]};
+var coveringEdgePoly = {
+ type: "Polygon",
+ coordinates: [[[-2.0, -1.5], [-1.0, -1.5], [-1.0, 1.5], [-2.0, 1.5], [-2.0, -1.5]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: coveringEdgePoly}}});
assert.eq(result.itcount(), 1);
@@ -146,21 +142,34 @@ assert.eq(result.itcount(), 1);
// Case 2a: same as Case 2, except pulled slightly away from the polygon.
// Result: Intersection.
// NOTE: Scales of errors?
-var closebyCoveringEdgePoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -1.5], [-1.0 - (minError / 1000), -1.5], [-1.0 - (minError / 1000), 1.5], [-2.0, 1.5], [-2.0, -1.5]]
- ]};
+var closebyCoveringEdgePoly = {
+ type: "Polygon",
+ coordinates: [[
+ [-2.0, -1.5],
+ [-1.0 - (minError / 1000), -1.5],
+ [-1.0 - (minError / 1000), 1.5],
+ [-2.0, 1.5],
+ [-2.0, -1.5]
+ ]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: closebyCoveringEdgePoly}}});
assert.eq(result.itcount(), 1);
-// Case 2b: same as Case 4, except pulled slightly away from the polygon, so that it's not intersecting.
+// Case 2b: same as Case 4, except pulled slightly away from the polygon, so that it's not
+// intersecting.
// Result: No Intersection.
// NOTE: Scales of errors?
-var notCloseEnoughCoveringEdgePoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -1.5], [-1.0 - (minError / 100), -1.5], [-1.0 - (minError / 100), 1.5], [-2.0, 1.5], [-2.0, -1.5]]
- ]};
+var notCloseEnoughCoveringEdgePoly = {
+ type: "Polygon",
+ coordinates: [[
+ [-2.0, -1.5],
+ [-1.0 - (minError / 100), -1.5],
+ [-1.0 - (minError / 100), 1.5],
+ [-2.0, 1.5],
+ [-2.0, -1.5]
+ ]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: notCloseEnoughCoveringEdgePoly}}});
assert.eq(result.itcount(), 0);
@@ -168,44 +177,60 @@ assert.eq(result.itcount(), 0);
// Case 3: A polygon who shares an edge with another polygon, where the searching
// polygon's edge partially covers by the canon polygon's edge.
// Result: No intersection.
-var partiallyCoveringEdgePoly = {type: "Polygon",
- coordinates: [
- [[-2.0, -1.5], [-1.0, -1.5], [-1.0, 0.5], [-2.0, 0.5], [-2.0, -1.5]]
- ]};
+var partiallyCoveringEdgePoly = {
+ type: "Polygon",
+ coordinates: [[[-2.0, -1.5], [-1.0, -1.5], [-1.0, 0.5], [-2.0, 0.5], [-2.0, -1.5]]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: partiallyCoveringEdgePoly}}});
assert.eq(result.itcount(), 0);
-
-//Polygons that intersect at three non-co-linear points should geoIntersect
-var sharedPointsPoly = {type: "Polygon",
- coordinates: [
- [[0.0, -3.0], [0.0, -1.0], [2.0, -2.0], [1.0, 0.0], [2.0, 2.0], [0.0, 1.0], [0.0, 3.0], [3.0, 3.0], [3.0, -3.0], [0.0, -3.0]]
- ]};
+// Polygons that intersect at three non-co-linear points should geoIntersect
+var sharedPointsPoly = {
+ type: "Polygon",
+ coordinates: [[
+ [0.0, -3.0],
+ [0.0, -1.0],
+ [2.0, -2.0],
+ [1.0, 0.0],
+ [2.0, 2.0],
+ [0.0, 1.0],
+ [0.0, 3.0],
+ [3.0, 3.0],
+ [3.0, -3.0],
+ [0.0, -3.0]
+ ]]
+};
result = t.find({geo: {$geoIntersects: {$geometry: sharedPointsPoly}}});
assert.eq(result.itcount(), 1);
-//If a polygon contains a hole, and another polygon is within that hole, it should not be within or intersect.
+// If a polygon contains a hole, and another polygon is within that hole, it should not be within or
+// intersect.
-var bigHolePoly = {type: "Polygon",
+var bigHolePoly = {
+ type: "Polygon",
coordinates: [
[[-3.0, -3.0], [3.0, -3.0], [3.0, 3.0], [-3.0, 3.0], [-3.0, -3.0]],
[[-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0]]
- ]};
+ ]
+};
result = t.find({geo: {$within: {$geometry: bigHolePoly}}});
assert.eq(result.itcount(), 0);
result = t.find({geo: {$geoIntersects: {$geometry: bigHolePoly}}});
assert.eq(result.itcount(), 0);
-// If a polygon has a hole, and another polygon is contained partially by that hole, it should be an intersection
+// If a polygon has a hole, and another polygon is contained partially by that hole, it should be an
+// intersection
// but not a within.
-var internalOverlapPoly = {type: "Polygon",
+var internalOverlapPoly = {
+ type: "Polygon",
coordinates: [
[[-3.0, -3.0], [3.0, -3.0], [3.0, 3.0], [-3.0, 3.0], [-3.0, -3.0]],
[[-2.0, 0.0], [2.0, 0.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, 0.0]]
- ]};
+ ]
+};
result = t.find({geo: {$geoIntersects: {$geometry: internalOverlapPoly}}});
assert.eq(result.itcount(), 1);