summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo/r2_region_coverer_test.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2014-06-09 16:08:42 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2014-06-13 16:44:06 -0400
commit83f2b119dfbd527c73ce0f63d3c6dcb586edb33f (patch)
tree307ea66c7af727704df7d9624c7f4d635649a84f /src/mongo/db/geo/r2_region_coverer_test.cpp
parent8a47cfef3d41decde32b1a425229f1dc1c810f65 (diff)
downloadmongo-83f2b119dfbd527c73ce0f63d3c6dcb586edb33f.tar.gz
SERVER-14192 Add covering for annulus
Diffstat (limited to 'src/mongo/db/geo/r2_region_coverer_test.cpp')
-rw-r--r--src/mongo/db/geo/r2_region_coverer_test.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/mongo/db/geo/r2_region_coverer_test.cpp b/src/mongo/db/geo/r2_region_coverer_test.cpp
index 07bd6aa5285..b58b7246df6 100644
--- a/src/mongo/db/geo/r2_region_coverer_test.cpp
+++ b/src/mongo/db/geo/r2_region_coverer_test.cpp
@@ -543,4 +543,76 @@ namespace {
ASSERT_FALSE(polygonContainsBox(concave, box));
}
+ TEST(ShapeIntersection, Annulus) {
+ R2Annulus annulus(Point(0.0, 0.0), 1, 5);
+ Box box;
+
+ // Disjoint, out of outer circle
+ box = Box(4, 4, 1);
+ ASSERT_TRUE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box contains outer circle
+ box = Box(-6, -5.5, 12);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box intersects with the outer circle, but not the inner circle
+ box = Box(3, 3, 4);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box is contained by the annulus
+ box = Box(2, 2, 1);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_TRUE(annulus.fastContains(box));
+
+ // Box is contained by the outer circle and intersects with the inner circle
+ box = Box(0.4, 0.5, 3);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box intersects with both outer and inner circle
+ box = Box(-4, -4, 4.5);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box is inside the inner circle
+ box = Box(-0.1, -0.2, 0.5);
+ ASSERT_TRUE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box contains the inner circle, but intersects with the outer circle
+ box = Box(-2, -2, 7);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ //
+ // Annulus contains both inner and outer circles as boundaries.
+ //
+
+ // Box only touches the outer boundary
+ box = Box(3, 4, 1); // Lower left touches boundary
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+ box = Box(-4, -5, 1); // Upper right touches boundary
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+
+ // Box is contained by the annulus touching the outer boundary
+ box = Box(-4, -3, 0.1);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_TRUE(annulus.fastContains(box));
+
+ // Box is contained by the annulus touching the inner boundary
+ box = Box(0, 1, 1);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_TRUE(annulus.fastContains(box));
+
+ // Box only touches the inner boundary at (-0.6, 0.8)
+ box = Box(-0.6, 0.3, 0.5);
+ ASSERT_FALSE(annulus.fastDisjoint(box));
+ ASSERT_FALSE(annulus.fastContains(box));
+ }
+
} // namespace