@@ -160,6 +160,64 @@ describe('Parse.Polygon testing', () => {
160160 } , done . fail ) ;
161161 } ) ;
162162
163+ it ( 'polygonContain query no reverse input (Regression test for #4608)' , ( done ) => {
164+ const points1 = [ [ .25 , 0 ] , [ .25 , 1.25 ] , [ .75 , 1.25 ] , [ .75 , 0 ] ] ;
165+ const points2 = [ [ 0 , 0 ] , [ 0 , 2 ] , [ 2 , 2 ] , [ 2 , 0 ] ] ;
166+ const points3 = [ [ 10 , 10 ] , [ 10 , 15 ] , [ 15 , 15 ] , [ 15 , 10 ] , [ 10 , 10 ] ] ;
167+ const polygon1 = new Parse . Polygon ( points1 ) ;
168+ const polygon2 = new Parse . Polygon ( points2 ) ;
169+ const polygon3 = new Parse . Polygon ( points3 ) ;
170+ const obj1 = new TestObject ( { location : polygon1 } ) ;
171+ const obj2 = new TestObject ( { location : polygon2 } ) ;
172+ const obj3 = new TestObject ( { location : polygon3 } ) ;
173+ Parse . Object . saveAll ( [ obj1 , obj2 , obj3 ] ) . then ( ( ) => {
174+ const where = {
175+ location : {
176+ $geoIntersects : {
177+ $point : { __type : 'GeoPoint' , latitude : 0.5 , longitude :1.0 }
178+ }
179+ }
180+ } ;
181+ return rp . post ( {
182+ url : Parse . serverURL + '/classes/TestObject' ,
183+ json : { where, '_method' : 'GET' } ,
184+ headers : {
185+ 'X-Parse-Application-Id' : Parse . applicationId ,
186+ 'X-Parse-Javascript-Key' : Parse . javaScriptKey
187+ }
188+ } ) ;
189+ } ) . then ( ( resp ) => {
190+ expect ( resp . results . length ) . toBe ( 2 ) ;
191+ done ( ) ;
192+ } , done . fail ) ;
193+ } ) ;
194+
195+ it ( 'polygonContain query real data (Regression test for #4608)' , ( done ) => {
196+ const detroit = [ [ 42.631655189280224 , - 83.78406753121705 ] , [ 42.633047793854814 , - 83.75333640366955 ] , [ 42.61625254348911 , - 83.75149921669944 ] , [ 42.61526926650296 , - 83.78161794858735 ] , [ 42.631655189280224 , - 83.78406753121705 ] ] ;
197+ const polygon = new Parse . Polygon ( detroit ) ;
198+ const obj = new TestObject ( { location : polygon } ) ;
199+ obj . save ( ) . then ( ( ) => {
200+ const where = {
201+ location : {
202+ $geoIntersects : {
203+ $point : { __type : 'GeoPoint' , latitude : 42.624599 , longitude :- 83.770162 }
204+ }
205+ }
206+ } ;
207+ return rp . post ( {
208+ url : Parse . serverURL + '/classes/TestObject' ,
209+ json : { where, '_method' : 'GET' } ,
210+ headers : {
211+ 'X-Parse-Application-Id' : Parse . applicationId ,
212+ 'X-Parse-Javascript-Key' : Parse . javaScriptKey
213+ }
214+ } ) ;
215+ } ) . then ( ( resp ) => {
216+ expect ( resp . results . length ) . toBe ( 1 ) ;
217+ done ( ) ;
218+ } , done . fail ) ;
219+ } ) ;
220+
163221 it ( 'polygonContain invalid input' , ( done ) => {
164222 const points = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] ] ;
165223 const polygon = new Parse . Polygon ( points ) ;
@@ -255,6 +313,24 @@ describe_only_db('mongo')('Parse.Polygon testing', () => {
255313 } , done . fail ) ;
256314 } ) ;
257315
316+ it ( 'polygon coordinates reverse input' , ( done ) => {
317+ const Config = require ( '../src/Config' ) ;
318+ const config = Config . get ( 'test' ) ;
319+
320+ // When stored the first point should be the last point
321+ const input = [ [ 12 , 11 ] , [ 14 , 13 ] , [ 16 , 15 ] , [ 18 , 17 ] ] ;
322+ const output = [ [ [ 11 , 12 ] , [ 13 , 14 ] , [ 15 , 16 ] , [ 17 , 18 ] , [ 11 , 12 ] ] ] ;
323+ const obj = new TestObject ( ) ;
324+ obj . set ( 'polygon' , new Parse . Polygon ( input ) ) ;
325+ obj . save ( ) . then ( ( ) => {
326+ return config . database . adapter . _rawFind ( 'TestObject' , { _id : obj . id } ) ;
327+ } ) . then ( ( results ) => {
328+ expect ( results . length ) . toBe ( 1 ) ;
329+ expect ( results [ 0 ] . polygon . coordinates ) . toEqual ( output ) ;
330+ done ( ) ;
331+ } ) ;
332+ } ) ;
333+
258334 it ( 'polygon loop is not valid' , ( done ) => {
259335 const coords = [ [ 0 , 0 ] , [ 0 , 1 ] , [ 1 , 0 ] , [ 1 , 1 ] ] ;
260336 const obj = new TestObject ( ) ;
0 commit comments