~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to jstests/geo_s2overlappingpolys.js

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var t = db.geo_s2overlappingpolys
2
 
t.drop()
3
 
 
4
 
t.ensureIndex( { geo : "2dsphere" } );
5
 
 
6
 
var minError = 0.8e-13;
7
 
 
8
 
var canonPoly = {type: "Polygon",
9
 
    coordinates: [
10
 
        [[-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0]]
11
 
    ]};
12
 
t.insert({geo: canonPoly});
13
 
 
14
 
// Test 1: If a poly completely encloses the canonPoly, we expect the canonPoly 
15
 
// to be returned for both $within and $geoIntersect 
16
 
 
17
 
var outerPoly = {type: "Polygon",
18
 
    coordinates: [
19
 
        [[-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0]]
20
 
    ]};
21
 
var result = t.find({geo: {$within: {$geometry: outerPoly}}});
22
 
assert.eq(result.count(), 1);
23
 
result = t.find({geo: {$geoIntersects: {$geometry: outerPoly}}});
24
 
assert.eq(result.count(), 1);
25
 
 
26
 
 
27
 
// Test 2: If a poly that covers half of the canonPoly, we expect that it should
28
 
// geoIntersect, but should not be within.
29
 
 
30
 
var partialPoly = {type: "Polygon",
31
 
    coordinates: [
32
 
        [[-2.0, -2.0], [2.0, -2.0], [2.0, 0.0], [-2.0, 0.0], [-2.0, -2.0]]
33
 
    ]};
34
 
 
35
 
//Should not be within
36
 
result = t.find({geo: {$within: {$geometry: partialPoly}}});
37
 
assert.eq(result.count(), 0);
38
 
 
39
 
//This should however count as a geoIntersect
40
 
result = t.find({geo: {$geoIntersects: {$geometry: partialPoly}}});
41
 
assert.eq(result.count(), 1);
42
 
 
43
 
 
44
 
// Test 3: Polygons that intersect at a point or an edge have undefined 
45
 
// behaviour in s2 The s2 library we're using appears to have 
46
 
// the following behaviour.
47
 
 
48
 
// Case (a): Polygons that intersect at one point (not a vertex).
49
 
// behaviour: geoIntersects.
50
 
 
51
 
var sharedPointPoly = {type: "Polygon",
52
 
    coordinates: [
53
 
        [[0.0, -2.0], [0.0, -1.0], [1.0, -2.0], [0.0, -2.0]]
54
 
    ]};
55
 
 
56
 
result = t.find({geo: {$geoIntersects: {$geometry: sharedPointPoly}}});
57
 
assert.eq(result.count(), 1);
58
 
 
59
 
// Case (b): Polygons that intersect at one point (a vertex).
60
 
// behaviour: not geoIntersect
61
 
 
62
 
var sharedVertexPoly = {type: "Polygon",
63
 
    coordinates: [
64
 
        [[0.0, -2.0], [1.0, -1.0], [1.0, -2.0], [0.0, -2.0]]
65
 
    ]};
66
 
 
67
 
result = t.find({geo: {$geoIntersects: {$geometry: sharedVertexPoly}}});
68
 
assert.eq(result.count(), 0);
69
 
 
70
 
// Case (c): Polygons that intesersect at one point that is very close to a 
71
 
// vertex should have the same behaviour as Case (b).
72
 
 
73
 
var almostSharedVertexPoly = {type: "Polygon",
74
 
    coordinates: [
75
 
        [[0.0, -2.0], [1.0 - minError, -1.0], [1.0, -2.0], [0.0, -2.0]]
76
 
    ]};
77
 
 
78
 
result = t.find({geo: {$geoIntersects: {$geometry: almostSharedVertexPoly}}});
79
 
assert.eq(result.count(), 0);
80
 
 
81
 
 
82
 
// Case (d): Polygons that intesersect at one point that is not quite as close 
83
 
// to a vertex should behave as though it were not a vertex, and should 
84
 
// geoIntersect
85
 
 
86
 
var notCloseEnoughSharedVertexPoly = {type: "Polygon",
87
 
    coordinates: [
88
 
        [[0.0, -2.0], [1.0 - (10 * minError), -1.0], [1.0, -2.0], [0.0, -2.0]]
89
 
    ]};
90
 
 
91
 
result = t.find({geo: {$geoIntersects: {$geometry: notCloseEnoughSharedVertexPoly}}});
92
 
assert.eq(result.count(), 1);
93
 
 
94
 
// Case (e): Polygons that come very close to having a point intersection
95
 
// on a non-vertex coordinate should intersect.
96
 
 
97
 
var almostSharedPointPoly = {type: "Polygon",
98
 
    coordinates: [
99
 
        [[0.0, -2.0], [0.0, (-1.0 - minError)], [1.0, -2.0], [0.0, -2.0]]
100
 
    ]};
101
 
 
102
 
result = t.find({geo: {$geoIntersects: {$geometry: almostSharedPointPoly}}});
103
 
assert.eq(result.count(), 1);
104
 
 
105
 
 
106
 
// Case (f): If we increase the error a little, it should no longer act
107
 
// as though it's intersecting.
108
 
// NOTE: I think this error bound seems odd. Going to 0.000152297 will break this test.
109
 
// I've confirmed there is an error bound, but it's a lot larger than we experienced above.
110
 
var errorBound = 0.000152298
111
 
var notCloseEnoughSharedPointPoly = {type: "Polygon",
112
 
    coordinates: [
113
 
        [[0.0, -2.0], [0.0, -1.0 - errorBound], [1.0, -2.0], [0.0, -2.0]]
114
 
    ]};
115
 
 
116
 
result = t.find({geo: {$geoIntersects: {$geometry: notCloseEnoughSharedPointPoly}}});
117
 
assert.eq(result.count(), 0);
118
 
 
119
 
/* Test 3: Importantly, polygons with shared edges have undefined intersection 
120
 
 * under s2. Therefore these test serve more to make sure nothing changes than 
121
 
 * to confirm an expected behaviour.
122
 
 */
123
 
 
124
 
// Case 1: A polygon who shares an edge with another polygon, where the searching
125
 
//         polygon's edge is fully covered by the canon polygon's edge.
126
 
// Result: No intersection.
127
 
var fullyCoveredEdgePoly = {type: "Polygon",
128
 
    coordinates: [
129
 
        [[-2.0, -0.5], [-1.0, -0.5], [-1.0, 0.5], [-2.0, 0.5], [-2.0, -0.5]]
130
 
    ]};
131
 
 
132
 
result = t.find({geo: {$geoIntersects: {$geometry: fullyCoveredEdgePoly}}});
133
 
assert.eq(result.count(), 0);
134
 
 
135
 
// Case 2: A polygon who shares an edge with another polygon, where the searching
136
 
//         polygon's edge fully covers the canon polygon's edge.
137
 
// Result: Intersection.
138
 
var coveringEdgePoly = {type: "Polygon",
139
 
    coordinates: [
140
 
        [[-2.0, -1.5], [-1.0, -1.5], [-1.0, 1.5], [-2.0, 1.5], [-2.0, -1.5]]
141
 
    ]};
142
 
 
143
 
result = t.find({geo: {$geoIntersects: {$geometry: coveringEdgePoly}}});
144
 
assert.eq(result.count(), 1);
145
 
 
146
 
// Case 2a: same as Case 2, except pulled slightly away from the polygon.
147
 
// Result: Intersection.
148
 
// NOTE: Scales of errors?
149
 
var closebyCoveringEdgePoly = {type: "Polygon",
150
 
    coordinates: [
151
 
        [[-2.0, -1.5], [-1.0 - (minError / 1000), -1.5], [-1.0 - (minError / 1000), 1.5], [-2.0, 1.5], [-2.0, -1.5]]
152
 
    ]};
153
 
 
154
 
result = t.find({geo: {$geoIntersects: {$geometry: closebyCoveringEdgePoly}}});
155
 
assert.eq(result.count(), 1);
156
 
 
157
 
// Case 2b: same as Case 4, except pulled slightly away from the polygon, so that it's not intersecting.
158
 
// Result: No Intersection.
159
 
// NOTE: Scales of errors?
160
 
var notCloseEnoughCoveringEdgePoly = {type: "Polygon",
161
 
    coordinates: [
162
 
        [[-2.0, -1.5], [-1.0 - (minError / 100), -1.5], [-1.0 - (minError / 100), 1.5], [-2.0, 1.5], [-2.0, -1.5]]
163
 
    ]};
164
 
 
165
 
result = t.find({geo: {$geoIntersects: {$geometry: notCloseEnoughCoveringEdgePoly}}});
166
 
assert.eq(result.count(), 0);
167
 
 
168
 
// Case 3: A polygon who shares an edge with another polygon, where the searching
169
 
//         polygon's edge partially covers by the canon polygon's edge.
170
 
// Result: No intersection.
171
 
var partiallyCoveringEdgePoly = {type: "Polygon",
172
 
    coordinates: [
173
 
        [[-2.0, -1.5], [-1.0, -1.5], [-1.0, 0.5], [-2.0, 0.5], [-2.0, -1.5]]
174
 
    ]};
175
 
 
176
 
result = t.find({geo: {$geoIntersects: {$geometry: partiallyCoveringEdgePoly}}});
177
 
assert.eq(result.count(), 0);
178
 
 
179
 
 
180
 
//Polygons that intersect at three non-co-linear points should geoIntersect
181
 
var sharedPointsPoly = {type: "Polygon",
182
 
    coordinates: [
183
 
        [[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]]
184
 
    ]};
185
 
 
186
 
result = t.find({geo: {$geoIntersects: {$geometry: sharedPointsPoly}}});
187
 
assert.eq(result.count(), 1);
188
 
 
189
 
//If a polygon contains a hole, and another polygon is within that hole, it should not be within or intersect.
190
 
 
191
 
var bigHolePoly = {type: "Polygon",
192
 
    coordinates: [
193
 
        [[-3.0, -3.0], [3.0, -3.0], [3.0, 3.0], [-3.0, 3.0], [-3.0, -3.0]],
194
 
        [[-2.0, -2.0], [2.0, -2.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, -2.0]]
195
 
    ]};
196
 
result = t.find({geo: {$within: {$geometry: bigHolePoly}}});
197
 
assert.eq(result.count(), 0);
198
 
result = t.find({geo: {$geoIntersects: {$geometry: bigHolePoly}}});
199
 
assert.eq(result.count(), 0);
200
 
 
201
 
// If a polygon has a hole, and another polygon is contained partially by that hole, it should be an intersection
202
 
// but not a within.
203
 
 
204
 
var internalOverlapPoly = {type: "Polygon",
205
 
    coordinates: [
206
 
        [[-3.0, -3.0], [3.0, -3.0], [3.0, 3.0], [-3.0, 3.0], [-3.0, -3.0]],
207
 
        [[-2.0, 0.0], [2.0, 0.0], [2.0, 2.0], [-2.0, 2.0], [-2.0, 0.0]]
208
 
    ]};
209
 
 
210
 
result = t.find({geo: {$geoIntersects: {$geometry: internalOverlapPoly}}});
211
 
assert.eq(result.count(), 1);
212
 
result = t.find({geo: {$within: {$geometry: internalOverlapPoly}}});
213
 
assert.eq(result.count(), 0);