summaryrefslogtreecommitdiff
path: root/jstests/core/geo_s2holesameasshell.js
blob: 91c05ca49797bcfdd166cf9f202f7c4e1681cebb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// If polygons have holes, the holes cannot be equal to the entire geometry.
var t = db.geo_s2holessameasshell;
t.drop();
t.ensureIndex({geo: "2dsphere"});

var centerPoint = {"type": "Point", "coordinates": [0.5, 0.5]};
var edgePoint = {"type": "Point", "coordinates": [0, 0.5]};
var cornerPoint = {"type": "Point", "coordinates": [0, 0]};

// Various "edge" cases.  None of them should be returned by the non-polygon
// polygon below.
t.insert({geo : centerPoint});
t.insert({geo : edgePoint});
t.insert({geo : cornerPoint});

// This generates an empty covering.
var polygonWithFullHole = { "type" : "Polygon", "coordinates": [
        [[0,0], [0,1], [1, 1], [1, 0], [0, 0]],
        [[0,0], [0,1], [1, 1], [1, 0], [0, 0]]
    ]
};

// No keys for insert should error.
assert.writeError(t.insert({geo: polygonWithFullHole}));

// No covering to search over should give an empty result set.
assert.throws(function() {
    return t.find({geo: {$geoWithin: {$geometry: polygonWithFullHole}}}).count();});

// Similar polygon to the one above, but is covered by two holes instead of
// one.
var polygonWithTwoHolesCoveringWholeArea = {"type" : "Polygon", "coordinates": [
        [[0,0], [0,1], [1, 1], [1, 0], [0, 0]],
        [[0,0], [0,0.5], [1, 0.5], [1, 0], [0, 0]],
        [[0,0.5], [0,1], [1, 1], [1, 0.5], [0, 0.5]]
    ]
};

// No keys for insert should error.
assert.writeError(t.insert({geo: polygonWithTwoHolesCoveringWholeArea}));

// No covering to search over should give an empty result set.
assert.throws(function() {
    return t.find({geo: {$geoWithin: {$geometry: polygonWithTwoHolesCoveringWholeArea}}}).count();});