MBMapkit
/Users/dongkui/ios_api/branches/1.0.x/code/config/MBMapDemo/MBMapkit/MBMapkit/MBGeometry.h
00001 //
00002 //  MBGeometry.h
00003 //  MBMapKit
00004 //
00005 //  Copyright 2011 Mapbar Inc. All rights reserved.
00006 //
00007 
00008 
00009 #import <CoreGraphics/CoreGraphics.h>
00010 #import <CoreLocation/CLLocation.h>
00011 
00012 #import <UIKit/UIKit.h>
00013 
00020 typedef struct {
00022     CLLocationDegrees latitudeDelta;
00024     CLLocationDegrees longitudeDelta;
00025 } MBCoordinateSpan;
00026 
00031 typedef struct {
00033         CLLocationCoordinate2D center;
00035         MBCoordinateSpan span;
00036 } MBCoordinateRegion;
00037 
00045 UIKIT_STATIC_INLINE MBCoordinateSpan MBCoordinateSpanMake(CLLocationDegrees latitudeDelta, CLLocationDegrees longitudeDelta)
00046 {
00047     MBCoordinateSpan span;
00048     span.latitudeDelta = latitudeDelta;
00049     span.longitudeDelta = longitudeDelta;
00050     return span;
00051 }
00052 
00060 UIKIT_STATIC_INLINE MBCoordinateRegion MBCoordinateRegionMake(CLLocationCoordinate2D centerCoordinate, MBCoordinateSpan span)
00061 {
00062         MBCoordinateRegion region;
00063         region.center = centerCoordinate;
00064     region.span = span;
00065         return region;
00066 }
00067 
00076  UIKIT_EXTERN MBCoordinateRegion MBCoordinateRegionMakeWithDistance(CLLocationCoordinate2D centerCoordinate, CLLocationDistance latitudinalMeters, CLLocationDistance longitudinalMeters);
00077 
00089 typedef struct {
00091     double x;
00093     double y;   
00094 } MBMapPoint;
00095 
00103 typedef struct {
00105     double width; 
00107     double height;  
00108 } MBMapSize;
00109 
00117 typedef struct {
00119     MBMapPoint origin;
00121     MBMapSize size;
00122 } MBMapRect;
00123 
00130 typedef CGFloat MBZoomScale;
00131 
00136 UIKIT_EXTERN const MBMapSize MBMapSizeWorld;
00137 
00144 UIKIT_EXTERN const MBMapRect MBMapRectWorld;
00145 
00152 UIKIT_EXTERN MBMapPoint MBMapPointForCoordinate(CLLocationCoordinate2D coordinate);
00153 
00160 UIKIT_EXTERN CLLocationCoordinate2D MBCoordinateForMapPoint(MBMapPoint mapPoint);
00161 
00170 UIKIT_EXTERN CLLocationDistance MBMetersPerMapPointAtLatitude(CLLocationDegrees latitude);
00171 
00178 UIKIT_EXTERN double MBMapPointsPerMeterAtLatitude(CLLocationDegrees latitude);
00179 
00189 UIKIT_EXTERN CLLocationDistance MBMetersBetweenMapPoints(MBMapPoint a, MBMapPoint b);
00190 
00197 UIKIT_EXTERN const MBMapRect MBMapRectNull;
00198 
00206 UIKIT_STATIC_INLINE MBMapPoint MBMapPointMake(double x, double y) {
00207     return (MBMapPoint){x, y};
00208 }
00209 
00217 UIKIT_STATIC_INLINE MBMapSize MBMapSizeMake(double width, double height) {
00218     return (MBMapSize){width, height};
00219 }
00220 
00230 UIKIT_STATIC_INLINE MBMapRect MBMapRectMake(double x, double y, double width, double height) {
00231     return (MBMapRect){ MBMapPointMake(x, y), MBMapSizeMake(width, height) };
00232 }
00233 
00240 UIKIT_STATIC_INLINE double MBMapRectGetMinX(MBMapRect rect) {
00241     return rect.origin.x;
00242 }
00243 
00250 UIKIT_STATIC_INLINE double MBMapRectGetMinY(MBMapRect rect) {
00251     return rect.origin.y;
00252 }
00253 
00260 UIKIT_STATIC_INLINE double MBMapRectGetMidX(MBMapRect rect) {
00261     return rect.origin.x + rect.size.width / 2.0;
00262 }
00263 
00270 UIKIT_STATIC_INLINE double MBMapRectGetMidY(MBMapRect rect) {
00271     return rect.origin.y + rect.size.height / 2.0;
00272 }
00273 
00280 UIKIT_STATIC_INLINE double MBMapRectGetMaxX(MBMapRect rect) {
00281     return rect.origin.x + rect.size.width;
00282 }
00283 
00290 UIKIT_STATIC_INLINE double MBMapRectGetMaxY(MBMapRect rect) {
00291     return rect.origin.y + rect.size.height;
00292 }
00293 
00300 UIKIT_STATIC_INLINE double MBMapRectGetWidth(MBMapRect rect) {
00301     return rect.size.width;
00302 }
00303 
00310 UIKIT_STATIC_INLINE double MBMapRectGetHeight(MBMapRect rect) {
00311     return rect.size.height;
00312 }
00313 
00321 UIKIT_STATIC_INLINE BOOL MBMapPointEqualToPoint(MBMapPoint point1, MBMapPoint point2) {
00322     return point1.x == point2.x && point1.y == point2.y;
00323 }
00324 
00332 UIKIT_STATIC_INLINE BOOL MBMapSizeEqualToSize(MBMapSize size1, MBMapSize size2) {
00333     return size1.width == size2.width && size1.height == size2.height;
00334 }
00335 
00343 UIKIT_STATIC_INLINE BOOL MBMapRectEqualToRect(MBMapRect rect1, MBMapRect rect2) {
00344     return 
00345     MBMapPointEqualToPoint(rect1.origin, rect2.origin) &&
00346     MBMapSizeEqualToSize(rect1.size, rect2.size);
00347 }
00348 
00357 UIKIT_STATIC_INLINE BOOL MBMapRectIsNull(MBMapRect rect) {
00358     return isinf(rect.origin.x) || isinf(rect.origin.y);
00359 }
00360 
00367 UIKIT_STATIC_INLINE BOOL MBMapRectIsEmpty(MBMapRect rect) {
00368     return MBMapRectIsNull(rect) || (rect.size.width == 0.0 && rect.size.height == 0.0);
00369 }
00370 
00377 UIKIT_STATIC_INLINE NSString *MBStringFromMapPoint(MBMapPoint point) {
00378     return [NSString stringWithFormat:@"{%.1f, %.1f}", point.x, point.y];
00379 }
00380 
00387 UIKIT_STATIC_INLINE NSString *MBStringFromMapSize(MBMapSize size) {
00388     return [NSString stringWithFormat:@"{%.1f, %.1f}", size.width, size.height];
00389 }
00390 
00397 UIKIT_STATIC_INLINE NSString *MBStringFromMapRect(MBMapRect rect) 
00398 {
00399     return [NSString stringWithFormat:@"{%@, %@}", MBStringFromMapPoint(rect.origin), MBStringFromMapSize(rect.size)];
00400 }
00401 
00412 UIKIT_EXTERN MBMapRect MBMapRectUnion(MBMapRect rect1, MBMapRect rect2);
00413 
00414 
00422 UIKIT_EXTERN MBMapRect MBMapRectIntersection(MBMapRect rect1, MBMapRect rect2);
00423 
00432 UIKIT_EXTERN MBMapRect MBMapRectInset(MBMapRect rect, double dx, double dy);
00433 
00442 UIKIT_EXTERN MBMapRect MBMapRectOffset(MBMapRect rect, double dx, double dy);
00443 
00453 UIKIT_EXTERN void MBMapRectDivide(MBMapRect rect, MBMapRect *slice, MBMapRect *remainder, double amount, CGRectEdge edge);
00454 
00464 UIKIT_EXTERN BOOL MBMapRectContainsPoint(MBMapRect rect, MBMapPoint point);
00465 
00473 UIKIT_EXTERN BOOL MBMapRectContainsRect(MBMapRect rect1, MBMapRect rect2);
00474 
00484 UIKIT_EXTERN BOOL MBMapRectIntersectsRect(MBMapRect rect1, MBMapRect rect2);
00485 
00492 UIKIT_EXTERN MBCoordinateRegion MBCoordinateRegionForMapRect(MBMapRect rect);
00493 
00500  UIKIT_EXTERN BOOL MBMapRectSpans180thMeridian(MBMapRect rect);
00501 
00509 UIKIT_EXTERN MBMapRect MBMapRectRemainder(MBMapRect rect);
00510 
00517 UIKIT_EXTERN CGFloat MBRoadWidthAtZoomScale(MBZoomScale zoomScale);
 全部  函数 变量 属性