//
//  DMKGeometry.h
//  DMKMap
//
//  Created by yunfei on 2025/3/19.
//

#import <CoreGraphics/CoreGraphics.h>
#import <CoreLocation/CoreLocation.h>
#import <UIKit/UIKit.h>

#ifdef __cplusplus
extern "C" {
#endif

///平面投影坐标结构定义
typedef struct DMKMapPoint {
    double x; ///<x坐标
    double y; ///<y坐标
} DMKMapPoint;

///平面投影大小结构定义
typedef struct DMKMapSize {
    double width;   ///<宽度
    double height;  ///<高度
} DMKMapSize;

///平面投影矩形结构定义
typedef struct DMKMapRect {
    DMKMapPoint origin;  ///<左上角坐标
    DMKMapSize size;     ///<大小
} DMKMapRect;

///经度、纬度定义的经纬度跨度范围
typedef struct DMKCoordinateSpan {
    CLLocationDegrees latitudeDelta;  ///< 纬度跨度
    CLLocationDegrees longitudeDelta; ///< 经度跨度
} DMKCoordinateSpan;

///中心点、跨度范围定义的四边形经纬度范围
typedef struct DMKCoordinateRegion {
    CLLocationCoordinate2D center;  ///< 中心点经纬度
    DMKCoordinateSpan span;          ///< 跨度范围
} DMKCoordinateRegion;


static inline DMKCoordinateSpan DMKCoordinateSpanMake(CLLocationDegrees latitudeDelta, CLLocationDegrees longitudeDelta)
{
    return (DMKCoordinateSpan){latitudeDelta, longitudeDelta};
}

static inline DMKCoordinateRegion DMKCoordinateRegionMake(CLLocationCoordinate2D centerCoordinate, DMKCoordinateSpan span)
{
    return (DMKCoordinateRegion){centerCoordinate, span};
}

static inline DMKMapPoint DMKMapPointMake(double x, double y)
{
    return (DMKMapPoint){x, y};
}

static inline DMKMapSize DMKMapSizeMake(double width, double height)
{
    return (DMKMapSize){width, height};
}

static inline DMKMapRect DMKMapRectMake(double x, double y, double width, double height)
{
    return (DMKMapRect){DMKMapPointMake(x, y), DMKMapSizeMake(width, height)};
}

static inline double DMKMapRectGetMinX(DMKMapRect rect)
{
    return rect.origin.x;
}

static inline double DMKMapRectGetMinY(DMKMapRect rect)
{
    return rect.origin.y;
}

static inline double DMKMapRectGetMidX(DMKMapRect rect)
{
    return rect.origin.x + rect.size.width / 2.0;
}

static inline double DMKMapRectGetMidY(DMKMapRect rect)
{
    return rect.origin.y + rect.size.height / 2.0;
}

static inline double DMKMapRectGetMaxX(DMKMapRect rect)
{
    return rect.origin.x + rect.size.width;
}

static inline double DMKMapRectGetMaxY(DMKMapRect rect)
{
    return rect.origin.y + rect.size.height;
}

static inline double DMKMapRectGetWidth(DMKMapRect rect)
{
    return rect.size.width;
}

static inline double DMKMapRectGetHeight(DMKMapRect rect)
{
    return rect.size.height;
}

static inline BOOL DMKMapPointEqualToPoint(DMKMapPoint point1, DMKMapPoint point2) {
    return point1.x == point2.x && point1.y == point2.y;
}

static inline BOOL DMKMapSizeEqualToSize(DMKMapSize size1, DMKMapSize size2) {
    return size1.width == size2.width && size1.height == size2.height;
}

static inline BOOL DMKMapRectEqualToRect(DMKMapRect rect1, DMKMapRect rect2) {
    return
    DMKMapPointEqualToPoint(rect1.origin, rect2.origin) &&
    DMKMapSizeEqualToSize(rect1.size, rect2.size);
}

static inline BOOL DMKMapRectIsNull(DMKMapRect rect) {
    return isinf(rect.origin.x) || isinf(rect.origin.y);
}

static inline BOOL DMKMapRectIsEmpty(DMKMapRect rect) {
    return DMKMapRectIsNull(rect) || (rect.size.width == 0.0 && rect.size.height == 0.0);
}

#ifdef __cplusplus
}
#endif
