From 6b97f71bd6e25fc9d1aac7987768f56b78fcf24d Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 17 Apr 2018 16:15:26 -0400 Subject: [ios, macos] Add tangent NSExpresssion operator. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 10 ++++++++++ platform/darwin/test/MGLExpressionTests.mm | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 8c79fd43f8..e641c79628 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -73,6 +73,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_asin:); INSTALL_METHOD(mgl_sin:); INSTALL_METHOD(mgl_atan:); + INSTALL_METHOD(mgl_tan:); // Install functions that resemble control structures, taking arbitrary // numbers of arguments. Vararg aftermarket functions need to be declared @@ -137,6 +138,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = return @(atan(number.doubleValue)); } +/** + Computes the principal value of the tangent. + */ +- (NSNumber *)mgl_tan:(NSNumber *)number { + return @(tan(number.doubleValue)); +} + /** A placeholder for a method that evaluates an interpolation expression. */ @@ -720,6 +728,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"asin" : @"mgl_asin:", @"sin" : @"mgl_sin:", @"atan" : @"mgl_atan:", + @"tan" : @"mgl_tan:", @"floor": @"floor:", @"ceil": @"ceiling:", @"^": @"raise:toPower:", @@ -967,6 +976,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"mgl_asin:" : @"asin", @"mgl_sin:" : @"sin", @"mgl_atan:" : @"atan", + @"mgl_tan:" : @"tan", // 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 4e18ad694d..864310356c 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -567,6 +567,13 @@ using namespace std::string_literals; XCTAssertEqualWithAccuracy(value.doubleValue, 1.52, 0.001); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { + NSExpression *expression = [NSExpression expressionForFunction:@"mgl_tan:" arguments:@[MGLConstantExpression(@0)]]; + NSArray *jsonExpression = @[@"tan", @0]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } } - (void)testStringFormattingExpressionObject { -- cgit v1.2.1