aboutsummaryrefslogtreecommitdiff
path: root/iosApp/WhirlyGlobe.xcframework/ios-arm64_x86_64-simulator/WhirlyGlobe.framework/Headers/MaplyCoordinate.h
blob: 753b77e74e5a5611ef8355739e507c9e13327e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/*
 *  MaplyCoordinate.h
 *  WhirlyGlobe-MaplyComponent
 *
 *  Created by Steve Gifford on 7/21/12.
 *  Copyright 2011-2022 mousebird consulting
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

/** 
    A 2D coordinate representation.
    
    The Maply Coordinate is a simple 2 dimensional coordinate
    passed around to numerous methods.  For geo-coordinates x
    maps to longitude and y to latitude and the values are
    in radians.
  */
typedef struct
{
    float x,y;
} MaplyCoordinate;


extern const MaplyCoordinate kMaplyNullCoordinate;


/** 
    Double precision version of 2D coordinate.
    
    This works the same was as the MaplyCoordinate, but has
    more precision.
  */
typedef struct
{
    double x,y;
} MaplyCoordinateD;

extern const MaplyCoordinateD kMaplyNullCoordinateD;


/** 
    A 3D coordinate representation.
    
    The 3D version of the Maply Coordinate adds a z values, often
    in meters, but not always.  Consult the appropriate method to
    be sure.
  */
typedef struct
{
    float x,y,z;
} MaplyCoordinate3d;

/** 
    An NSObject based wrapper for 3D coordinates.
    
    This wrapper encapsulates a MaplyCoordinate3d so we can pass them around in NSDictionary objects.
  */
@interface MaplyCoordinate3dWrapper : NSObject

/// Initialize with a 3D coordinate
- (instancetype)initWithCoord:(MaplyCoordinate3d)coord;

/// 3D coordinate
@property (nonatomic,readonly) MaplyCoordinate3d coord;

@end

typedef struct
{
    double x,y,z;
} MaplyCoordinate3dD;

extern const MaplyCoordinate3dD kMaplyNullCoordinate3dD;

/** 
    An NSObject based wrapper for 3D coordinates.
 
    This wrapper encapsulates a MaplyCoordinate3d so we can pass them around in NSDictionary objects.
 */
@interface MaplyCoordinate3dDWrapper : NSObject

/// Initialize with a 3D coordinate
- (instancetype)initWithCoord:(MaplyCoordinate3dD)coord;

/// 3D coordinate
@property (nonatomic,readonly) MaplyCoordinate3dD coord;

@end

/** 
    Represents a bounding box in a particular coordinate system.
    
    ll is the lower left and ur is the upper right.
  */
typedef struct
{
    MaplyCoordinate ll;
    MaplyCoordinate ur;
} MaplyBoundingBox;

extern const MaplyBoundingBox kMaplyNullBoundingBox;

/**
    A category that uses NSValue to store MaplyCoordinate data
 */
@interface NSValue (MaplyCoordinate)
+ (instancetype)valueWithMaplyCoordinate:(MaplyCoordinate)value;
@property (readonly) MaplyCoordinate maplyCoordinateValue;
@end

/**
    A category that uses NSValue to store MaplyCoordinateD data
 */
@interface NSValue (MaplyCoordinateD)
+ (instancetype)valueWithMaplyCoordinateD:(MaplyCoordinateD)value;
@property (readonly) MaplyCoordinateD maplyCoordinateDValue;
@end

/**
    A category that uses NSValue to store MaplyBoundingBox data
 */
@interface NSValue (MaplyBoundingBox)
+ (instancetype)valueWithMaplyBoundingBox:(MaplyBoundingBox)value;
@property (readonly) MaplyBoundingBox maplyBoundingBoxValue;
@end

/** 
    Represents a bounding box in a particular coordinate system.
    
    ll is the lower left and ur is the upper right.
 */
typedef struct
{
	MaplyCoordinateD ll;
	MaplyCoordinateD ur;
} MaplyBoundingBoxD;

extern const MaplyBoundingBoxD kMaplyNullBoundingBoxD;

#if __cplusplus
extern "C" {
#endif

/** 
    Construct a MaplyCoordiante with longitude and latitude values in radians.
    
    MaplyCoordinate's are in radians when they represent lon/lat values.  This constructs one with radians as input.
    
    @return A 2D MaplyCoordinate in radians (if representing a lon/lat value).
  */
MaplyCoordinate MaplyCoordinateMake(float radLon,float radLat);

/** 
    Construct a MaplyCoordianteD with longitude and latitude values in radians.
    
    MaplyCoordinate's are in radians when they represent lon/lat values.  This constructs one with radians as input.
    
    @return A 2D MaplyCoordinateD in radians (if representing a lon/lat value).
    */
MaplyCoordinateD MaplyCoordinateDMake(double radLon,double radLat);
    
/** 
    Construct a MaplyGeoCoordinate with longitude and latitude values in degrees.
    
    MaplyCoordinate's are in radians when they represent lon/lat values.  This function does that conversion for you.
    
    @param degLon The longitude value (east to west) in degrees.
    
    @param degLat The latitude value (north to south) in degrees.
    
    @return A 2D MaplyCoordinate in radians (if representing a lon/lat value).
  */
MaplyCoordinate MaplyCoordinateMakeWithDegrees(float degLon,float degLat);

/** 
    Construct a MaplyGeoCoordinate with longitude and latitude values in degrees.
 
    MaplyCoordinate's are in radians when they represent lon/lat values.  This function does that conversion for you.
 
    @param degLon The longitude value (east to west) in degrees.
 
    @param degLat The latitude value (north to south) in degrees.
 
    @return A 2D MaplyCoordinate in radians (if representing a lon/lat value).
 */
MaplyCoordinateD MaplyCoordinateDMakeWithDegrees(double degLon,double degLat);

/** 
    Construct a MaplyCoordinateD with a MaplyCoordinate.
    
    This function constructs a MaplyCoordinateD with the component values of the input MaplyCoordinate.
    
    @param c The input MaplyCoordinate value.
    
    @return A 2D MaplyCoordinateD in radians (if representing a lon/lat value).
  */
MaplyCoordinateD MaplyCoordinateDMakeWithMaplyCoordinate(MaplyCoordinate c);

/**
    Construct a MaplyCoordinate with a MaplyCoordinateD.
    
    This function constructs a MaplyCoordinate with the component values of the input MaplyCoordinateD.
    
    @param c The input MaplyCoordinateD value.
    
    @return A 2D MaplyCoordinate in radians (if representing a lon/lat value).
  */
MaplyCoordinate MaplyCoordinateMakeWithMaplyCoordinateD(MaplyCoordinateD c);

/**
    Construct a MaplyCoordinat3d from the values given.
    
    @param x The x value, or longitude in radians if we're making geo coordinates.
    
    @param y The y value, or latitude in radians if we're making geo coordinates.
    
    @param z The z value, sometimes this is display coordinates (radius == 1.0 for a sphere)
              and sometimes this is meters.  It depends on how you're using it.
    
    @return A 3D MaplyCoordinate3d in radians + other (if representing a lon/lat value).
  */
MaplyCoordinate3d MaplyCoordinate3dMake(float x,float y,float z);

/** 
    Construct a MaplyCoordinat3d from the values given.
    
    @param x The x value, or longitude in radians if we're making geo coordinates.
    
    @param y The y value, or latitude in radians if we're making geo coordinates.
    
    @param z The z value, sometimes this is display coordinates (radius == 1.0 for a sphere)
 and sometimes this is meters.  It depends on how you're using it.
    
    @return A 3D MaplyCoordinate3d in radians + other (if representing a lon/lat value).
 */
MaplyCoordinate3dD MaplyCoordinate3dDMake(double x,double y,double z);

/** 
    Construct a MaplyBoundingBox from the values given.
    
    The inputs are in degrees and the order is longitude *then* latitude.
    
    @param degLon0 The left side of the bounding box in degrees.
    
    @param degLat0 The bottom of the bounding box in degrees.
    
    @param degLon1 The right side of the bounding box in degrees.
    
    @param degLat1 The top of the bounding box in degrees.
    
    @return A MaplyBoundingBox in radians.
  */
MaplyBoundingBox MaplyBoundingBoxMakeWithDegrees(float degLon0,float degLat0,float degLon1,float degLat1);

/** Double version of MaplyBoundingBoxMakeWithDegrees
  */
MaplyBoundingBoxD MaplyBoundingBoxDMakeWithDegrees(double degLon0,double degLat0,double degLon1,double degLat1);

/** 
    Check if two bounding boxes overlap.
     
    @return Returns true if they did overlap, false otherwise.
  */
bool MaplyBoundingBoxesOverlap(MaplyBoundingBox bbox0,MaplyBoundingBox bbox1);
    
/** 
    Check if a bounding contains a given coordinate.
     
    @return Returns true if the bounding box contains the coordinate.
  */
bool MaplyBoundingBoxContains(MaplyBoundingBox bbox, MaplyCoordinate c);

/**
  Set up a bounding box from a list of 2D locations.
 */
MaplyBoundingBox MaplyBoundingBoxFromLocations(const CLLocationCoordinate2D locs[], unsigned int numLocs);

/**
  Set up a bounding box from a list of 2D coordinates
 */
MaplyBoundingBox MaplyBoundingBoxFromCoordinates(const MaplyCoordinate coords[], unsigned int numCoords);
MaplyBoundingBox MaplyBoundingBoxFromCoordinatesD(const MaplyCoordinateD coords[], unsigned int numCoords);
MaplyBoundingBoxD MaplyBoundingBoxDFromCoordinates(const MaplyCoordinate coords[], unsigned int numCoords);
MaplyBoundingBoxD MaplyBoundingBoxDFromCoordinatesD(const MaplyCoordinateD coords[], unsigned int numCoords);

/**
  Expand a bounding box with a list of 2D coordinates
 */
MaplyBoundingBox MaplyBoundingBoxAddCoordinates(MaplyBoundingBox box, const MaplyCoordinate coords[], unsigned int numCoords);
MaplyBoundingBox MaplyBoundingBoxAddCoordinatesD(MaplyBoundingBox box, const MaplyCoordinateD coords[], unsigned int numCoords);
MaplyBoundingBoxD MaplyBoundingBoxDAddCoordinates(MaplyBoundingBoxD box, const MaplyCoordinate coords[], unsigned int numCoords);
MaplyBoundingBoxD MaplyBoundingBoxDAddCoordinatesD(MaplyBoundingBoxD box, const MaplyCoordinateD coords[], unsigned int numCoords);

/**
 Return the intersection of two bounding boxes.
 */
MaplyBoundingBox MaplyBoundingBoxIntersection(MaplyBoundingBox bbox0,MaplyBoundingBox bbox1);

/** 
    Expands a bounding box by a given fraction of its size.
     
    @return Returns the expanded bounding box.
  */
MaplyBoundingBox MaplyBoundingBoxExpandByFraction(MaplyBoundingBox bbox, float buffer);
    
/** 
    Calculate the great circle distance between two geo coordinates.
    
    This calculates the distance on a sphere between one point and another.
    
    @param p0 The starting point, lon/lat in radians.
    
    @param p1 The end point, lon/lat in radians.
    
    @return The distance between p0 and p1 in meters.
  */
double MaplyGreatCircleDistance(MaplyCoordinate p0,MaplyCoordinate p1);
    
#if __cplusplus
}
#endif