diff options
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 10 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 54f98c6ab9..9238a291a4 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -68,6 +68,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_step:from:stops:); INSTALL_METHOD(mgl_coalesce:); INSTALL_METHOD(mgl_does:have:); + INSTALL_METHOD(mgl_acos:); // Install functions that resemble control structures, taking arbitrary // numbers of arguments. Vararg aftermarket functions need to be declared @@ -98,6 +99,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = } /** + Computes the principal value of the arc cosine of number. + */ +- (NSNumber *)mgl_acos:(NSNumber *)number { + return @(acos(number.doubleValue)); +} + +/** A placeholder for a method that evaluates an interpolation expression. */ - (id)mgl_interpolate:(id)inputExpression withCurveType:(NSString *)curveType parameters:(NSDictionary *)params stops:(NSDictionary *)stops { @@ -675,6 +683,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"ln": @"ln:", @"abs": @"abs:", @"round": @"mgl_round:", + @"acos" : @"mgl_acos:", @"floor": @"floor:", @"ceil": @"ceiling:", @"^": @"raise:toPower:", @@ -917,6 +926,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"lowercase:": @"downcase", @"length:": @"length", @"mgl_round:": @"round", + @"mgl_acos:" : @"acos", // Vararg aftermarket expressions need to be declared with an explicit and implicit first argument. @"MGL_LET": @"let", @"MGL_LET:": @"let", diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index e078c4f4b6..04198dbfc3 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -531,6 +531,13 @@ using namespace std::string_literals; XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @(M_PI)); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { + NSExpression *expression = [NSExpression expressionForFunction:@"mgl_acos:" arguments:@[MGLConstantExpression(@1)]]; + NSArray *jsonExpression = @[@"acos", @1]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } } - (void)testStringFormattingExpressionObject { |