Skip to content

Commit 27f71c9

Browse files
committed
geometry utils: haversine distance, geodesics, envelope and point methods
1 parent 71502dc commit 27f71c9

15 files changed

+1065
-98
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ Adheres to [Semantic Versioning](http://semver.org/).
66

77
## 4.1.4 (TBD)
88

9-
* TBD
9+
* Geometry Utils for Haversine distance, geodesic midpoints, geodesic paths, and geodesic envelopes
10+
* Envelope left mid, bottom mid, right mid, and top mid methods
11+
* Envelope min/max x/y/z/m double value methods
12+
* Point x/y/z/m double value methods
1013

1114
## [4.1.3](https://github.com/ngageoint/simple-features-ios/releases/tag/4.1.3) (11-08-2023)
1215

sf-ios/SFGeometryEnvelope.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,55 +323,111 @@
323323
*/
324324
-(instancetype) initWithGeometryEnvelope: (SFGeometryEnvelope *) geometryEnvelope;
325325

326+
/**
327+
* Get the min x value
328+
*
329+
* @return x coordinate
330+
*/
331+
-(double) minXValue;
332+
326333
/**
327334
* Set the min x value
328335
*
329336
* @param x x coordinate
330337
*/
331338
-(void) setMinXValue: (double) x;
332339

340+
/**
341+
* Get the max x value
342+
*
343+
* @return x coordinate
344+
*/
345+
-(double) maxXValue;
346+
333347
/**
334348
* Set the max x value
335349
*
336350
* @param x x coordinate
337351
*/
338352
-(void) setMaxXValue: (double) x;
339353

354+
/**
355+
* Get the min y value
356+
*
357+
* @return y coordinate
358+
*/
359+
-(double) minYValue;
360+
340361
/**
341362
* Set the min y value
342363
*
343364
* @param y y coordinate
344365
*/
345366
-(void) setMinYValue: (double) y;
346367

368+
/**
369+
* Get the max y value
370+
*
371+
* @return y coordinate
372+
*/
373+
-(double) maxYValue;
374+
347375
/**
348376
* Set the max y value
349377
*
350378
* @param y y coordinate
351379
*/
352380
-(void) setMaxYValue: (double) y;
353381

382+
/**
383+
* Get the min z value
384+
*
385+
* @return z coordinate
386+
*/
387+
-(double) minZValue;
388+
354389
/**
355390
* Set the min z value
356391
*
357392
* @param z z coordinate
358393
*/
359394
-(void) setMinZValue: (double) z;
360395

396+
/**
397+
* Get the max z value
398+
*
399+
* @return z coordinate
400+
*/
401+
-(double) maxZValue;
402+
361403
/**
362404
* Set the max z value
363405
*
364406
* @param z z coordinate
365407
*/
366408
-(void) setMaxZValue: (double) z;
367409

410+
/**
411+
* Get the min m value
412+
*
413+
* @return m coordinate
414+
*/
415+
-(double) minMValue;
416+
368417
/**
369418
* Set the min m value
370419
*
371420
* @param m m coordinate
372421
*/
373422
-(void) setMinMValue: (double) m;
374423

424+
/**
425+
* Get the max m value
426+
*
427+
* @return m coordinate
428+
*/
429+
-(double) maxMValue;
430+
375431
/**
376432
* Set the max m value
377433
*
@@ -456,6 +512,34 @@
456512
*/
457513
-(SFPoint *) topRight;
458514

515+
/**
516+
* Get the left mid point
517+
*
518+
* @return left mid point
519+
*/
520+
-(SFPoint *) leftMid;
521+
522+
/**
523+
* Get the bottom mid point
524+
*
525+
* @return bottom mid point
526+
*/
527+
-(SFPoint *) bottomMid;
528+
529+
/**
530+
* Get the right mid point
531+
*
532+
* @return right mid point
533+
*/
534+
-(SFPoint *) rightMid;
535+
536+
/**
537+
* Get the top mid point
538+
*
539+
* @return top mid point
540+
*/
541+
-(SFPoint *) topMid;
542+
459543
/**
460544
* Get the left line
461545
*

sf-ios/SFGeometryEnvelope.m

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -178,34 +178,66 @@ -(instancetype) initWithGeometryEnvelope: (SFGeometryEnvelope *) geometryEnvelop
178178
return self;
179179
}
180180

181+
-(double) minXValue{
182+
return [_minX doubleValue];
183+
}
184+
181185
-(void) setMinXValue: (double) x{
182186
[self setMinX:[[NSDecimalNumber alloc] initWithDouble:x]];
183187
}
184188

189+
-(double) maxXValue{
190+
return [_maxX doubleValue];
191+
}
192+
185193
-(void) setMaxXValue: (double) x{
186194
[self setMaxX:[[NSDecimalNumber alloc] initWithDouble:x]];
187195
}
188196

197+
-(double) minYValue{
198+
return [_minY doubleValue];
199+
}
200+
189201
-(void) setMinYValue: (double) y{
190202
[self setMinY:[[NSDecimalNumber alloc] initWithDouble:y]];
191203
}
192204

205+
-(double) maxYValue{
206+
return [_maxY doubleValue];
207+
}
208+
193209
-(void) setMaxYValue: (double) y{
194210
[self setMaxY:[[NSDecimalNumber alloc] initWithDouble:y]];
195211
}
196212

213+
-(double) minZValue{
214+
return [_minZ doubleValue];
215+
}
216+
197217
-(void) setMinZValue: (double) z{
198218
[self setMinZ:[[NSDecimalNumber alloc] initWithDouble:z]];
199219
}
200220

221+
-(double) maxZValue{
222+
return [_maxZ doubleValue];
223+
}
224+
201225
-(void) setMaxZValue: (double) z{
202226
[self setMaxZ:[[NSDecimalNumber alloc] initWithDouble:z]];
203227
}
204228

229+
-(double) minMValue{
230+
return [_minM doubleValue];
231+
}
232+
205233
-(void) setMinMValue: (double) m{
206234
[self setMinM:[[NSDecimalNumber alloc] initWithDouble:m]];
207235
}
208236

237+
-(double) maxMValue{
238+
return [_maxM doubleValue];
239+
}
240+
209241
-(void) setMaxMValue: (double) m{
210242
[self setMaxM:[[NSDecimalNumber alloc] initWithDouble:m]];
211243
}
@@ -219,11 +251,11 @@ -(BOOL) isMeasured{
219251
}
220252

221253
-(double) xRange{
222-
return [_maxX doubleValue] - [_minX doubleValue];
254+
return [self maxXValue] - [self minXValue];
223255
}
224256

225257
-(double) yRange{
226-
return [_maxY doubleValue] - [_minY doubleValue];
258+
return [self maxYValue] - [self minYValue];
227259
}
228260

229261
-(NSDecimalNumber *) zRange{
@@ -262,6 +294,22 @@ -(SFPoint *) topRight{
262294
return [SFPoint pointWithX:_maxX andY:_maxY];
263295
}
264296

297+
-(SFPoint *) leftMid{
298+
return [SFPoint pointWithX:_minX andY:[[NSDecimalNumber alloc] initWithDouble:[self midY]]];
299+
}
300+
301+
-(SFPoint *) bottomMid{
302+
return [SFPoint pointWithX:[[NSDecimalNumber alloc] initWithDouble:[self midX]] andY:_minY];
303+
}
304+
305+
-(SFPoint *) rightMid{
306+
return [SFPoint pointWithX:_maxX andY:[[NSDecimalNumber alloc] initWithDouble:[self midY]]];
307+
}
308+
309+
-(SFPoint *) topMid{
310+
return [SFPoint pointWithX:[[NSDecimalNumber alloc] initWithDouble:[self midX]] andY:_maxY];
311+
}
312+
265313
-(SFLine *) left{
266314
return [SFLine lineWithPoint1:[self topLeft] andPoint2:[self bottomLeft]];
267315
}
@@ -279,11 +327,11 @@ -(SFLine *) top{
279327
}
280328

281329
-(double) midX{
282-
return ([_minX doubleValue] + [_maxX doubleValue]) / 2.0;
330+
return ([self minXValue] + [self maxXValue]) / 2.0;
283331
}
284332

285333
-(double) midY{
286-
return ([_minY doubleValue] + [_maxY doubleValue]) / 2.0;
334+
return ([self minYValue] + [self maxYValue]) / 2.0;
287335
}
288336

289337
-(SFPoint *) centroid{
@@ -308,10 +356,10 @@ -(SFGeometryEnvelope *) overlapWithEnvelope: (SFGeometryEnvelope *) envelope{
308356

309357
-(SFGeometryEnvelope *) overlapWithEnvelope: (SFGeometryEnvelope *) envelope withAllowEmpty: (BOOL) allowEmpty{
310358

311-
double minX = MAX([self.minX doubleValue], [envelope.minX doubleValue]);
312-
double maxX = MIN([self.maxX doubleValue], [envelope.maxX doubleValue]);
313-
double minY = MAX([self.minY doubleValue], [envelope.minY doubleValue]);
314-
double maxY = MIN([self.maxY doubleValue], [envelope.maxY doubleValue]);
359+
double minX = MAX([self minXValue], [envelope minXValue]);
360+
double maxX = MIN([self maxXValue], [envelope maxXValue]);
361+
double minY = MAX([self minYValue], [envelope minYValue]);
362+
double maxY = MIN([self maxYValue], [envelope maxYValue]);
315363

316364
SFGeometryEnvelope *overlap = nil;
317365

@@ -324,10 +372,10 @@ -(SFGeometryEnvelope *) overlapWithEnvelope: (SFGeometryEnvelope *) envelope wit
324372

325373
-(SFGeometryEnvelope *) unionWithEnvelope: (SFGeometryEnvelope *) envelope{
326374

327-
double minX = MIN([self.minX doubleValue], [envelope.minX doubleValue]);
328-
double maxX = MAX([self.maxX doubleValue], [envelope.maxX doubleValue]);
329-
double minY = MIN([self.minY doubleValue], [envelope.minY doubleValue]);
330-
double maxY = MAX([self.maxY doubleValue], [envelope.maxY doubleValue]);
375+
double minX = MIN([self minXValue], [envelope minXValue]);
376+
double maxX = MAX([self maxXValue], [envelope maxXValue]);
377+
double minY = MIN([self minYValue], [envelope minYValue]);
378+
double maxY = MAX([self maxYValue], [envelope maxYValue]);
331379

332380
SFGeometryEnvelope *unionEnvelope = nil;
333381

@@ -343,27 +391,27 @@ -(BOOL) containsPoint: (SFPoint *) point{
343391
}
344392

345393
-(BOOL) containsPoint: (SFPoint *) point withEpsilon: (double) epsilon{
346-
return [self containsX:[point.x doubleValue] andY:[point.y doubleValue] withEpsilon:epsilon];
394+
return [self containsX:[point xValue] andY:[point yValue] withEpsilon:epsilon];
347395
}
348396

349397
-(BOOL) containsX: (double) x andY: (double) y{
350398
return [self containsX:x andY:y withEpsilon:0.0];
351399
}
352400

353401
-(BOOL) containsX: (double) x andY: (double) y withEpsilon: (double) epsilon{
354-
return x >= [_minX doubleValue] - epsilon && x <= [_maxX doubleValue] + epsilon
355-
&& y >= [_minY doubleValue] - epsilon && y <= [_maxY doubleValue] + epsilon;
402+
return x >= [self minXValue] - epsilon && x <= [self maxXValue] + epsilon
403+
&& y >= [self minYValue] - epsilon && y <= [self maxYValue] + epsilon;
356404
}
357405

358406
-(BOOL) containsEnvelope: (SFGeometryEnvelope *) envelope{
359407
return [self containsEnvelope:envelope withEpsilon:0.0];
360408
}
361409

362410
-(BOOL) containsEnvelope: (SFGeometryEnvelope *) envelope withEpsilon: (double) epsilon{
363-
return [_minX doubleValue] - epsilon <= [envelope.minX doubleValue]
364-
&& [_maxX doubleValue] + epsilon >= [envelope.maxX doubleValue]
365-
&& [_minY doubleValue] - epsilon <= [envelope.minY doubleValue]
366-
&& [_maxY doubleValue] + epsilon >= [envelope.maxY doubleValue];
411+
return [self minXValue] - epsilon <= [envelope minXValue]
412+
&& [self maxXValue] + epsilon >= [envelope maxXValue]
413+
&& [self minYValue] - epsilon <= [envelope minYValue]
414+
&& [self maxYValue] + epsilon >= [envelope maxYValue];
367415
}
368416

369417
-(SFGeometry *) buildGeometry{

sf-ios/SFPoint.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,27 +292,55 @@
292292
*/
293293
-(instancetype) initWithPoint: (SFPoint *) point;
294294

295+
/**
296+
* Get the x value
297+
*
298+
* @return x coordinate
299+
*/
300+
-(double) xValue;
301+
295302
/**
296303
* Set the x value
297304
*
298305
* @param x x coordinate
299306
*/
300307
-(void) setXValue: (double) x;
301308

309+
/**
310+
* Get the y value
311+
*
312+
* @return y coordinate
313+
*/
314+
-(double) yValue;
315+
302316
/**
303317
* Set the y value
304318
*
305319
* @param y y coordinate
306320
*/
307321
-(void) setYValue: (double) y;
308322

323+
/**
324+
* Get the z value
325+
*
326+
* @return z coordinate
327+
*/
328+
-(double) zValue;
329+
309330
/**
310331
* Set the z value
311332
*
312333
* @param z z coordinate
313334
*/
314335
-(void) setZValue: (double) z;
315336

337+
/**
338+
* Get the m value
339+
*
340+
* @return m coordinate
341+
*/
342+
-(double) mValue;
343+
316344
/**
317345
* Set the m value
318346
*

0 commit comments

Comments
 (0)