diff options
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 14 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 8 |
2 files changed, 20 insertions, 2 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index f03980f09b..d23da18597 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -70,6 +70,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_does:have:); INSTALL_METHOD(mgl_acos:); INSTALL_METHOD(mgl_asin:); + INSTALL_METHOD(mgl_atan:); // Install functions that resemble control structures, taking arbitrary // numbers of arguments. Vararg aftermarket functions need to be declared @@ -100,20 +101,27 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = } /** - Computes the principal value of the arc cosine. + Computes the principal value of the inverse cosine. */ - (NSNumber *)mgl_acos:(NSNumber *)number { return @(acos(number.doubleValue)); } /** - Computes the principal value of the arc sine. + Computes the principal value of the inverse sine. */ - (NSNumber *)mgl_asin:(NSNumber *)number { return @(asin(number.doubleValue)); } /** + Computes the principal value of the inverse tangent. + */ +- (NSNumber *)mgl_atan:(NSNumber *)number { + return @(atan(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 { @@ -693,6 +701,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"round": @"mgl_round:", @"acos" : @"mgl_acos:", @"asin" : @"mgl_asin:", + @"atan" : @"mgl_atan:", @"floor": @"floor:", @"ceil": @"ceiling:", @"^": @"raise:toPower:", @@ -937,6 +946,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"mgl_round:": @"round", @"mgl_acos:" : @"acos", @"mgl_asin:" : @"asin", + @"mgl_atan:" : @"atan", // 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 0fe7b22ea6..20e252c06b 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -545,6 +545,14 @@ using namespace std::string_literals; XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { + NSExpression *expression = [NSExpression expressionForFunction:@"mgl_atan:" arguments:@[MGLConstantExpression(@20)]]; + NSArray *jsonExpression = @[@"atan", @20]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + NSNumber *value = [expression expressionValueWithObject:nil context:nil]; + XCTAssertEqualWithAccuracy(value.doubleValue, 1.52, 0.001); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } } - (void)testStringFormattingExpressionObject { |