From 3951b203c8a316ca6bc5f0b46c8aea4e3bd7c1f5 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 17 Apr 2018 15:57:09 -0400 Subject: [ios, macos] Add atan NSExpresssion operator. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 14 ++++++++++++-- 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,19 +101,26 @@ 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. */ @@ -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 { -- cgit v1.2.1