Skip to content

Commit 4298850

Browse files
author
idbentley
committed
QA-173: Odd Holes, Intersection, Near testing, Large & small polys, overlapping polys, etc.
Signed-off-by: idbentley <[email protected]>
1 parent 9867870 commit 4298850

File tree

7 files changed

+809
-0
lines changed

7 files changed

+809
-0
lines changed

jstests/geo_s2holesameasshell.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,22 @@ assert(db.getLastError())
2626
// No covering to search over should give an empty result set.
2727
res = t.find({geo: {$within: {$geometry: polygonWithFullHole}}});
2828
assert.eq(res.count(), 0)
29+
30+
31+
// Similar polygon to the one above, but is covered by two holes instead of
32+
// one.
33+
polygonWithTwoHolesCoveringWholeArea = {"type" : "Polygon", "coordinates": [
34+
[[0,0], [0,1], [1, 1], [1, 0], [0, 0]],
35+
[[0,0], [0,0.5], [1, 0.5], [1, 0], [0, 0]],
36+
[[0,0.5], [0,1], [1, 1], [1, 0.5], [0, 0.5]]
37+
]
38+
};
39+
40+
// No keys for insert should error.
41+
t.insert({geo: polygonWithTwoHolesCoveringWholeArea});
42+
assert(db.getLastError());
43+
44+
// No covering to search over should give an empty result set.
45+
res = t.find({geo: {$within: {$geometry: ppolygonWithTwoHolesCoveringWholeArea}}});
46+
assert.eq(res.count(), 0);
47+

jstests/geo_s2intersection.js

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
t = db.geo_s2intersectinglines
2+
t.drop()
3+
t.ensureIndex( { geo : "2dsphere" } );
4+
5+
/* All the tests in this file are generally confirming intersections based upon
6+
* these three geo objects.
7+
*/
8+
canonLine = {
9+
name: 'canonLine',
10+
geo: {
11+
type: "LineString",
12+
coordinates: [[0.0, 0.0], [1.0, 0.0]]
13+
}
14+
};
15+
16+
canonPoint = {
17+
name: 'canonPoint',
18+
geo: {
19+
type: "Point",
20+
coordinates: [10.0, 10.0]
21+
}
22+
};
23+
24+
canonPoly = {
25+
name: 'canonPoly',
26+
geo: {
27+
type: "Polygon",
28+
coordinates: [
29+
[[50.0, 50.0], [51.0, 50.0], [51.0, 51.0], [50.0, 51.0], [50.0, 50.0]]
30+
]
31+
}
32+
}
33+
34+
t.insert(canonLine);
35+
t.insert(canonPoint);
36+
t.insert(canonPoly);
37+
38+
39+
//Case 1: Basic sanity intersection.
40+
testLine = {type: "LineString",
41+
coordinates: [[0.5, 0.5], [0.5, -0.5]]};
42+
43+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
44+
assert.eq(result.count(), 1);
45+
assert.eq(result[0]['name'], 'canonLine');
46+
47+
48+
//Case 2: Basic Polygon intersection.
49+
// we expect that the canonLine should intersect with this polygon.
50+
testPoly = {type: "Polygon",
51+
coordinates: [
52+
[[0.4, -0.1],[0.4, 0.1], [0.6, 0.1], [0.6, -0.1], [0.4, -0.1]]
53+
]}
54+
55+
result = t.find({geo: {$geoIntersects: {$geometry: testPoly}}});
56+
assert.eq(result.count(), 1);
57+
assert.eq(result[0]['name'], 'canonLine');
58+
59+
60+
//Case 3: Intersects the vertex of a line.
61+
// When a line intersects the vertex of a line, we expect this to
62+
// count as a geoIntersection.
63+
testLine = {type: "LineString",
64+
coordinates: [[0.0, 0.5], [0.0, -0.5]]};
65+
66+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
67+
assert.eq(result.count(), 1);
68+
assert.eq(result[0]['name'], 'canonLine');
69+
70+
// Case 4: Sanity no intersection.
71+
// This line just misses the canonLine in the negative direction. This
72+
// should not count as a geoIntersection.
73+
testLine = {type: "LineString",
74+
coordinates: [[-0.1, 0.5], [-0.1, -0.5]]};
75+
76+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
77+
assert.eq(result.count(), 0);
78+
79+
80+
// Case 5: Overlapping line - only partially overlaps.
81+
// Undefined behaviour: does intersect
82+
testLine = {type: "LineString",
83+
coordinates: [[-0.5, 0.0], [0.5, 0.0]]};
84+
85+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
86+
assert.eq(result.count(), 1);
87+
assert.eq(result[0]['name'], 'canonLine');
88+
89+
90+
// Case 6: Contained line - this line is fully contained by the canonLine
91+
// Undefined behaviour: doesn't intersect.
92+
testLine = {type: "LineString",
93+
coordinates: [[0.1, 0.0], [0.9, 0.0]]};
94+
95+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
96+
assert.eq(result.count(), 0);
97+
98+
// Case 7: Identical line in the identical position.
99+
// Undefined behaviour: does intersect.
100+
testLine = {type: "LineString",
101+
coordinates: [[0.0, 0.0], [1.0, 0.0]]};
102+
103+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
104+
assert.eq(result.count(), 1);
105+
assert.eq(result[0]['name'], 'canonLine');
106+
107+
// Case 8: Point intersection - we search with a line that intersects
108+
// with the canonPoint.
109+
testLine = {type: "LineString",
110+
coordinates: [[10.0, 11.0], [10.0, 9.0]]};
111+
112+
result = t.find({geo: {$geoIntersects: {$geometry: testLine}}});
113+
assert.eq(result.count(), 1);
114+
assert.eq(result[0]['name'], 'canonPoint');
115+
116+
// Case 9: Point point intersection
117+
// as above but with an identical point to the canonPoint. We expect an
118+
// intersection here.
119+
testPoint = {type: "Point",
120+
coordinates: [10.0, 10.0]}
121+
122+
result = t.find({geo: {$geoIntersects: {$geometry: testPoint}}});
123+
assert.eq(result.count(), 1);
124+
assert.eq(result[0]['name'], 'canonPoint');
125+
126+
127+
//Case 10: Sanity point non-intersection.
128+
testPoint = {type: "Point",
129+
coordinates: [12.0, 12.0]}
130+
131+
result = t.find({geo: {$geoIntersects: {$geometry: testPoint}}});
132+
assert.eq(result.count(), 0);
133+
134+
// Case 11: Point polygon intersection
135+
// verify that a point inside a polygon $geoIntersects.
136+
testPoint = {type: "Point",
137+
coordinates: [50.5, 50.5]}
138+
139+
result = t.find({geo: {$geoIntersects: {$geometry: testPoint}}});
140+
assert.eq(result.count(), 1);
141+
assert.eq(result[0]['name'], 'canonPoly');

0 commit comments

Comments
 (0)