#import "NSValue+MGLStyleAttributeAdditions.h" #import "MGLLight.h" #if TARGET_OS_IPHONE #import #define MGLEdgeInsets UIEdgeInsets #else #define MGLEdgeInsets NSEdgeInsets #endif @implementation NSValue (MGLStyleAttributeAdditions) + (instancetype)mgl_valueWithOffsetArray:(std::array)offsetArray { CGVector vector = CGVectorMake(offsetArray[0], offsetArray[1]); #if !TARGET_OS_IPHONE // Style specification assumes an origin at the upper-left corner. // macOS defines an origin at the lower-left corner. vector.dy *= -1; #endif return [NSValue value:&vector withObjCType:@encode(CGVector)]; } + (instancetype)mgl_valueWithPaddingArray:(std::array)paddingArray { // Style specification defines padding in clockwise order: top, right, bottom, left. // Foundation defines padding in counterclockwise order: top, left, bottom, right. MGLEdgeInsets insets = { .top = paddingArray[0], .right = paddingArray[1], .bottom = paddingArray[2], .left = paddingArray[3], }; return [NSValue value:&insets withObjCType:@encode(MGLEdgeInsets)]; } - (std::array)mgl_offsetArrayValue { NSAssert(strcmp(self.objCType, @encode(CGVector)) == 0, @"Value does not represent a CGVector"); CGVector vector; [self getValue:&vector]; #if !TARGET_OS_IPHONE vector.dy *= -1; #endif return { static_cast(vector.dx), static_cast(vector.dy), }; } - (std::array)mgl_paddingArrayValue { NSAssert(strcmp(self.objCType, @encode(MGLEdgeInsets)) == 0, @"Value does not represent an NSEdgeInsets/UIEdgeInsets"); MGLEdgeInsets insets; [self getValue:&insets]; // Style specification defines padding in clockwise order: top, right, bottom, left. return { static_cast(insets.top), static_cast(insets.right), static_cast(insets.bottom), static_cast(insets.left), }; } - (std::array)mgl_lightPositionArrayValue { NSAssert(strcmp(self.objCType, @encode(MGLSphericalPosition)) == 0, @"Value does not represent an MGLSphericalPosition"); MGLSphericalPosition lightPosition; [self getValue:&lightPosition]; // Style specification defines padding in clockwise order: top, right, bottom, left. return { static_cast(lightPosition.radial), static_cast(lightPosition.azimuthal), static_cast(lightPosition.polar), }; } @end