2019-04-10 17:41:34 +02:00
|
|
|
//
|
|
|
|
// @tags: [SERVER-40561]
|
|
|
|
//
|
|
|
|
|
2011-08-30 21:54:10 +02:00
|
|
|
t = db.geo_polygon4;
|
|
|
|
t.drop();
|
|
|
|
|
2015-04-30 15:47:35 +02:00
|
|
|
num = 0;
|
|
|
|
var bulk = t.initializeUnorderedBulkOp();
|
2016-03-09 18:17:50 +01:00
|
|
|
for (x = -180; x < 180; x += .5) {
|
|
|
|
for (y = -180; y < 180; y += .5) {
|
2016-05-28 23:55:12 +02:00
|
|
|
o = {_id: num++, loc: [x, y]};
|
2016-03-09 18:17:50 +01:00
|
|
|
bulk.insert(o);
|
2015-04-30 15:47:35 +02:00
|
|
|
}
|
2011-08-30 21:54:10 +02:00
|
|
|
}
|
2019-08-14 15:52:59 +02:00
|
|
|
assert.commandWorked(bulk.execute());
|
2015-04-30 15:47:35 +02:00
|
|
|
|
|
|
|
var numTests = 31;
|
2016-03-09 18:17:50 +01:00
|
|
|
for (var n = 0; n < numTests; n++) {
|
2016-02-04 18:30:06 +01:00
|
|
|
t.dropIndexes();
|
2016-03-09 18:17:50 +01:00
|
|
|
t.ensureIndex({loc: "2d"}, {bits: 2 + n});
|
2015-04-30 15:47:35 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.between(9 - 2,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 0], [1, 1], [0, 2]]}}}).count(),
|
|
|
|
9,
|
|
|
|
"Triangle Test",
|
|
|
|
true);
|
|
|
|
assert.eq(
|
|
|
|
num,
|
|
|
|
t.find({
|
2016-05-28 23:55:12 +02:00
|
|
|
loc: {"$within": {"$polygon": [[-180, -180], [-180, 180], [180, 180], [180, -180]]}}
|
|
|
|
}).count(),
|
2016-03-09 18:17:50 +01:00
|
|
|
"Bounding Box Test");
|
2011-08-30 21:54:10 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(
|
|
|
|
441,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 0], [0, 10], [10, 10], [10, 0]]}}}).count(),
|
|
|
|
"Square Test");
|
|
|
|
assert.eq(25,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 0], [0, 2], [2, 2], [2, 0]]}}}).count(),
|
|
|
|
"Square Test 2");
|
2011-09-06 18:22:31 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
if (1) { // SERVER-3726
|
|
|
|
// Points exactly on diagonals may be in or out, depending on how the error calculating the
|
|
|
|
// slope falls.
|
|
|
|
assert.between(
|
|
|
|
341 - 18,
|
2016-05-28 23:55:12 +02:00
|
|
|
t.find({
|
|
|
|
loc: {"$within": {"$polygon": [[0, 0], [0, 10], [10, 10], [10, 0], [5, 5]]}}
|
|
|
|
}).count(),
|
2016-03-09 18:17:50 +01:00
|
|
|
341,
|
|
|
|
"Square Missing Chunk Test",
|
|
|
|
true);
|
2019-07-27 00:20:35 +02:00
|
|
|
assert.between(21 - 2,
|
|
|
|
t.find({
|
|
|
|
loc: {"$within": {"$polygon": [[0, 0], [0, 2], [2, 2], [2, 0], [1, 1]]}}
|
|
|
|
}).count(),
|
|
|
|
21,
|
|
|
|
"Square Missing Chunk Test 2",
|
|
|
|
true);
|
2011-09-06 18:22:31 +02:00
|
|
|
}
|
2015-04-30 15:47:35 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(1,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 0], [0, 0], [0, 0]]}}}).count(),
|
|
|
|
"Point Test");
|
2015-04-30 15:47:35 +02:00
|
|
|
|
|
|
|
// SERVER-3725
|
|
|
|
{
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(5,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 0], [1, 0], [2, 0]]}}}).count(),
|
|
|
|
"Line Test 1");
|
|
|
|
assert.eq(3,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 0], [0, 0], [1, 0]]}}}).count(),
|
|
|
|
"Line Test 2");
|
|
|
|
assert.eq(5,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 2], [0, 1], [0, 0]]}}}).count(),
|
|
|
|
"Line Test 3");
|
2011-08-30 21:54:10 +02:00
|
|
|
}
|
2015-04-30 15:47:35 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(3,
|
|
|
|
t.find({loc: {"$within": {"$polygon": [[0, 1], [0, 0], [0, 0]]}}}).count(),
|
|
|
|
"Line Test 4");
|
2011-08-30 21:54:10 +02:00
|
|
|
}
|