diff options
Diffstat (limited to 'platform/darwin/src/MGLGeometry.h')
-rw-r--r-- | platform/darwin/src/MGLGeometry.h | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/platform/darwin/src/MGLGeometry.h b/platform/darwin/src/MGLGeometry.h index 003a7638e7..3a3e59fb3e 100644 --- a/platform/darwin/src/MGLGeometry.h +++ b/platform/darwin/src/MGLGeometry.h @@ -48,17 +48,18 @@ typedef struct MGLCoordinateBounds { /** A quadrilateral area as measured on a two-dimensional map projection. `MGLCoordinateQuad` differs from `MGLCoordinateBounds` in that it allows - representation of non-axis aligned bounds and non-rectangular quadrilaterals + representation of non-axis aligned bounds and non-rectangular quadrilaterals. + The coordinates are described in counter clockwise order from top left. */ typedef struct MGLCoordinateQuad { /** Coordinate at the top left corner. */ CLLocationCoordinate2D topLeft; - /** Coordinate at the top right corner. */ - CLLocationCoordinate2D topRight; - /** Coordinate at the bottom right corner. */ - CLLocationCoordinate2D bottomRight; /** Coordinate at the bottom left corner. */ CLLocationCoordinate2D bottomLeft; + /** Coordinate at the bottom right corner. */ + CLLocationCoordinate2D bottomRight; + /** Coordinate at the top right corner. */ + CLLocationCoordinate2D topRight; } MGLCoordinateQuad; @@ -73,6 +74,33 @@ NS_INLINE MGLCoordinateBounds MGLCoordinateBoundsMake(CLLocationCoordinate2D sw, return bounds; } +/** + Creates a new `MGLCoordinateQuad` structure from the given top left, + bottom left, bottom right, and top right coordinates. + */ +NS_INLINE MGLCoordinateQuad MGLCoordinateQuadMake(CLLocationCoordinate2D topLeft, CLLocationCoordinate2D bottomLeft, CLLocationCoordinate2D bottomRight, CLLocationCoordinate2D topRight) { + MGLCoordinateQuad quad; + quad.topLeft = topLeft; + quad.bottomLeft = bottomLeft; + quad.bottomRight = bottomRight; + quad.topRight = topRight; + return quad; +} + +/** + Creates a new `MGLCoordinateQuad` structure from the given `MGLCoordinateBounds`. + The returned quad uses the bounds' northeast coordinate as the top right, and the + southwest coordinate at the bottom left. + */ +NS_INLINE MGLCoordinateQuad MGLCoordinateQuadFromCoordinateBounds(MGLCoordinateBounds bounds) { + MGLCoordinateQuad quad; + quad.topLeft = CLLocationCoordinate2DMake(bounds.ne.latitude, bounds.sw.longitude); + quad.bottomLeft = bounds.sw; + quad.bottomRight = CLLocationCoordinate2DMake(bounds.sw.latitude, bounds.ne.longitude); + quad.topRight = bounds.ne; + return quad; +} + /** Returns `YES` if the two coordinate bounds are equal to each other. */ NS_INLINE BOOL MGLCoordinateBoundsEqualToCoordinateBounds(MGLCoordinateBounds bounds1, MGLCoordinateBounds bounds2) { return (bounds1.sw.latitude == bounds2.sw.latitude && @@ -134,6 +162,15 @@ NS_INLINE NSString *MGLStringFromCoordinateBounds(MGLCoordinateBounds bounds) { bounds.ne.latitude, bounds.ne.longitude]; } +/** Returns a formatted string for the given coordinate quad. */ +NS_INLINE NSString *MGLStringFromCoordinateQuad(MGLCoordinateQuad quad) { + return [NSString stringWithFormat:@"{ topleft = {%.1f, %.1f}, bottomleft = {%.1f, %.1f}}, bottomright = {%.1f, %.1f}, topright = {%.1f, %.1f}", + quad.topLeft.latitude, quad.topLeft.longitude, + quad.bottomLeft.latitude, quad.bottomLeft.longitude, + quad.bottomRight.latitude, quad.bottomRight.longitude, + quad.topRight.latitude, quad.topRight.longitude]; +} + /** Returns radians, converted from degrees. */ NS_INLINE CGFloat MGLRadiansFromDegrees(CLLocationDegrees degrees) { return (CGFloat)(degrees * M_PI) / 180; |