From 43c961dafdbcc4e13bc9c83995629c8c90f7f4f5 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Date: Tue, 17 Apr 2018 15:40:53 -0400 Subject: [ios, macos] Add asin NSExpresssion operator. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 12 +++++++++++- platform/darwin/test/MGLExpressionTests.mm | 7 +++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 9238a291a4..f03980f09b 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -69,6 +69,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_coalesce:); INSTALL_METHOD(mgl_does:have:); INSTALL_METHOD(mgl_acos:); + INSTALL_METHOD(mgl_asin:); // Install functions that resemble control structures, taking arbitrary // numbers of arguments. Vararg aftermarket functions need to be declared @@ -99,12 +100,19 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = } /** - Computes the principal value of the arc cosine of number. + Computes the principal value of the arc cosine. */ - (NSNumber *)mgl_acos:(NSNumber *)number { return @(acos(number.doubleValue)); } +/** + Computes the principal value of the arc sine. + */ +- (NSNumber *)mgl_asin:(NSNumber *)number { + return @(asin(number.doubleValue)); +} + /** A placeholder for a method that evaluates an interpolation expression. */ @@ -684,6 +692,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"abs": @"abs:", @"round": @"mgl_round:", @"acos" : @"mgl_acos:", + @"asin" : @"mgl_asin:", @"floor": @"floor:", @"ceil": @"ceiling:", @"^": @"raise:toPower:", @@ -927,6 +936,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"length:": @"length", @"mgl_round:": @"round", @"mgl_acos:" : @"acos", + @"mgl_asin:" : @"asin", // 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 04198dbfc3..0fe7b22ea6 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -538,6 +538,13 @@ using namespace std::string_literals; XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { + NSExpression *expression = [NSExpression expressionForFunction:@"mgl_asin:" arguments:@[MGLConstantExpression(@0)]]; + NSArray *jsonExpression = @[@"asin", @0]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } } - (void)testStringFormattingExpressionObject { -- cgit v1.2.1