Couchbase Lite
Objective-C API for iOS and Mac OS
CBLGeometry.h
Go to the documentation of this file.
1 //
2 // CBLGeometry.h
3 // CouchbaseLite
4 //
5 // Created by Jens Alfke on 9/22/13.
6 // Copyright (c) 2013 Couchbase, Inc. All rights reserved.
7 //
8 
9 #import "CBLBase.h"
10 
12 
14 typedef struct CBLGeoPoint {
15  double x, y;
16 } CBLGeoPoint;
17 
22 typedef struct CBLGeoRect {
24 } CBLGeoRect;
25 
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 
33 static inline BOOL CBLGeoRectEqual(CBLGeoRect a, CBLGeoRect b) {
34  return a.min.x == b.min.x && a.min.y == b.min.y && a.max.x == b.max.x && a.max.y == b.max.y;
35 }
36 
38 static inline BOOL CBLGeoRectIsEmpty(CBLGeoRect r) {
39  return r.min.x == r.max.x && r.min.y == r.max.y;
40 }
41 
42 
44 BOOL CBLGeoCoordsStringToRect(NSString* __nullable coordsStr, CBLGeoRect* outRect);
45 
46 
47 #pragma mark - CONVERTING TO/FROM JSON:
48 
51 CBLJSONDict* CBLGeoPointToJSON(CBLGeoPoint pt);
52 
55 CBLJSONDict* CBLGeoRectToJSON(CBLGeoRect rect);
56 
59 BOOL CBLGeoJSONBoundingBox(NSDictionary* __nullable geoJSON, CBLGeoRect* outBBox);
60 
61 
63 CBLArrayOf(NSNumber*)* CBLGeoPointToCoordPair(CBLGeoPoint pt);
64 
66 BOOL CBLGeoCoordPairToPoint(NSArray* __nullable coords, CBLGeoPoint* outPoint);
67 
69 BOOL CBLGeoCoordsToRect(NSArray* __nullable coords, CBLGeoRect* outRect);
70 
71 #pragma mark - KEYS FOR MAP FUNCTIONS:
72 
75 id CBLGeoPointKey(double x, double y);
76 
78 id CBLGeoRectKey(double x0, double y0, double x1, double y1);
79 
83 id CBLGeoJSONKey(NSDictionary* geoJSON);
84 
85 
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 
A 2D geometric point.
Definition: CBLGeometry.h:14
#define NS_ASSUME_NONNULL_BEGIN
Definition: CBLBase.h:20
A 2D geometric rectangle.
Definition: CBLGeometry.h:22
CBLJSONDict * CBLGeoRectToJSON(CBLGeoRect rect)
Converts a rectangle to GeoJSON format (as a polygon.) For details see http://geojson.org/geojson-spec.html#polygon.
#define __nullable
Definition: CBLBase.h:23
struct CBLGeoRect CBLGeoRect
A 2D geometric rectangle.
BOOL CBLGeoCoordsStringToRect(NSString *__nullable coordsStr, CBLGeoRect *outRect)
Converts a string of four comma-separated numbers ("x0,y0,x1,y1") to a rectangle. ...
#define NS_ASSUME_NONNULL_END
Definition: CBLBase.h:21
CBLJSONDict * CBLGeoPointToJSON(CBLGeoPoint pt)
Converts a point to GeoJSON format.
double y
Definition: CBLGeometry.h:15
CBLArrayOf(NSNumber *) *CBLGeoPointToCoordPair(CBLGeoPoint pt)
Converts a point to a JSON-compatible array of two coordinates.
BOOL CBLGeoCoordsToRect(NSArray *__nullable coords, CBLGeoRect *outRect)
Converts a JSON array of four coordinates [x0, y0, x1, y1] to a rectangle.
NS_ASSUME_NONNULL_BEGIN struct CBLGeoPoint CBLGeoPoint
A 2D geometric point.
CBLGeoPoint min
Definition: CBLGeometry.h:23
id CBLGeoJSONKey(NSDictionary *geoJSON)
Returns a special value that, when emitted as a key, is indexed as a GeoJSON shape.
id CBLGeoRectKey(double x0, double y0, double x1, double y1)
Returns a special value that, when emitted as a key, is indexed as a geometric rectangle.
id CBLGeoPointKey(double x, double y)
Returns a special value that, when emitted as a key, is indexed as a geometric point.
BOOL CBLGeoCoordPairToPoint(NSArray *__nullable coords, CBLGeoPoint *outPoint)
Converts a JSON array of two coordinates [x,y] back into a point.
BOOL CBLGeoJSONBoundingBox(NSDictionary *__nullable geoJSON, CBLGeoRect *outBBox)
Computes the bounding box of a GeoJSON object.
double x
Definition: CBLGeometry.h:15
CBLGeoPoint max
Definition: CBLGeometry.h:23