[ios, macos] Added distance expression function

Installed an mgl_distanceFrom: aftermarket expression function that corresponds to the “distance” expression operator in style JSON.
This commit is contained in:
Minh Nguyễn
2020-05-01 11:59:04 -07:00
committed by Minh Nguyễn
parent 93141ac0f0
commit 27eee6adf5
8 changed files with 45 additions and 3 deletions

View File

@@ -77,6 +77,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
INSTALL_METHOD(mgl_atan:);
INSTALL_METHOD(mgl_tan:);
INSTALL_METHOD(mgl_log2:);
INSTALL_METHOD(mgl_distanceFrom:);
INSTALL_METHOD(mgl_attributed:);
// Install functions that resemble control structures, taking arbitrary
@@ -162,6 +163,15 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
return @(log2(number.doubleValue));
}
/**
Returns a straight-line distance from the given shape to the evaluated feature.
*/
- (NSNumber *)mgl_distanceFrom:(id)object {
[NSException raise:NSInvalidArgumentException
format:@"Shape distance expressions lack underlying Objective-C implementations."];
return nil;
}
/**
A placeholder for a method that evaluates an interpolation expression.
*/
@@ -656,6 +666,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"floor": @"floor:",
@"ceil": @"ceiling:",
@"^": @"raise:toPower:",
@"distance": @"mgl_distanceFrom:",
@"upcase": @"uppercase:",
@"downcase": @"lowercase:",
@"let": @"MGL_LET",
@@ -970,6 +981,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"mgl_atan:" : @"atan",
@"mgl_tan:" : @"tan",
@"mgl_log2:" : @"log2",
@"mgl_distanceFrom:": @"distance",
// Vararg aftermarket expressions need to be declared with an explicit and implicit first argument.
@"MGL_LET": @"let",
@"MGL_LET:": @"let",