chore(Query): $withinPolygon: 3 point minimum and boundary testing. (#3889)

* added 3 point minimum constraint to within-polygon

* test nit

* test for open and closed paths
This commit is contained in:
Diamond Lewis
2017-05-31 17:08:37 -05:00
committed by Florent Vilmart
parent 9ad8697c7a
commit e8be98ded2
3 changed files with 107 additions and 21 deletions

View File

@@ -348,7 +348,16 @@ const buildWhereClause = ({ schema, query, index }) => {
if (fieldValue.$geoWithin && fieldValue.$geoWithin.$polygon) {
const polygon = fieldValue.$geoWithin.$polygon;
if (!(polygon instanceof Array)) {
throw new Parse.Error(Parse.Error.INVALID_JSON, 'bad $geoWithin value');
throw new Parse.Error(
Parse.Error.INVALID_JSON,
'bad $geoWithin value; $polygon should contain at least 3 GeoPoints'
);
}
if (polygon.length < 3) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
'bad $geoWithin value; $polygon should contain at least 3 GeoPoints'
);
}
const points = polygon.map((point) => {
if (typeof point !== 'object' || point.__type !== 'GeoPoint') {