summaryrefslogtreecommitdiff
path: root/src/mongo/db/geo
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-03-18 16:12:19 -0400
committerGreg Studer <greg@10gen.com>2014-03-19 09:53:49 -0400
commit16be7b9840df1df12421ed7ef009005c7d321ec7 (patch)
tree1eceb57d3bb1ecd011820f4c028715bfde90df76 /src/mongo/db/geo
parent19ad2f402b588887ede8001116c3ce48329987ab (diff)
downloadmongo-16be7b9840df1df12421ed7ef009005c7d321ec7.tar.gz
SERVER-13258 ensure S2 poly loops have 3 points after dedup'ing
Diffstat (limited to 'src/mongo/db/geo')
-rw-r--r--src/mongo/db/geo/geoparser.cpp4
-rw-r--r--src/mongo/db/geo/geoparser_test.cpp10
2 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp
index a4d21ca7a61..e5fe800ea23 100644
--- a/src/mongo/db/geo/geoparser.cpp
+++ b/src/mongo/db/geo/geoparser.cpp
@@ -164,6 +164,8 @@ namespace mongo {
// The last point is duplicated. We drop it, since S2Loop expects no
// duplicate points
exteriorVertices.resize(exteriorVertices.size() - 1);
+ // S2 Polygon loops must have 3 vertices
+ if (exteriorVertices.size() < 3) { return false; }
S2PolygonBuilderOptions polyOptions;
polyOptions.set_validate(true);
@@ -185,6 +187,8 @@ namespace mongo {
eraseDuplicatePoints(&holePoints);
// Drop the duplicated last point.
holePoints.resize(holePoints.size() - 1);
+ // S2 Polygon loops must have 3 vertices
+ if (holePoints.size() < 3) { return false; }
// Interior rings are clockwise.
S2Loop holeLoop(holePoints);
holeLoop.Normalize();
diff --git a/src/mongo/db/geo/geoparser_test.cpp b/src/mongo/db/geo/geoparser_test.cpp
index 5f6c4ffd89b..eeac3725336 100644
--- a/src/mongo/db/geo/geoparser_test.cpp
+++ b/src/mongo/db/geo/geoparser_test.cpp
@@ -168,6 +168,16 @@ namespace {
&polygonD);
// Also removed in the loop.
ASSERT_FALSE(polygonD.polygon.Contains(point.point));
+
+ //
+ // Bad polygon examples
+ //
+
+ // Polygon with not enough points, because some are duplicated
+ PolygonWithCRS polygonBad;
+ ASSERT_FALSE(GeoParser::parsePolygon(
+ fromjson("{'type':'Polygon', 'coordinates':[[ [0,0], [0,0], [5,5], [5,5], [0,0] ]]}"),
+ &polygonBad));
}
TEST(GeoParser, legacyPoint) {