diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-04-17 16:10:17 -0400 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-04-17 16:10:17 -0400 |
commit | d830d6dacc428bf4779633b4aa65c6fb2bad577a (patch) | |
tree | c531f0d6d9858128aa07ab07b0d0ee3c43bc3555 | |
parent | 5e0c4af7b25c1dd1e008b706e8a8ce1b84f09c02 (diff) | |
download | qtlocation-mapboxgl-d830d6dacc428bf4779633b4aa65c6fb2bad577a.tar.gz |
[ios, macos] Add sine NSExpresssion operator.
-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 aa01fd6126..8c79fd43f8 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -71,6 +71,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_acos:); INSTALL_METHOD(mgl_cos:); INSTALL_METHOD(mgl_asin:); + INSTALL_METHOD(mgl_sin:); INSTALL_METHOD(mgl_atan:); // Install functions that resemble control structures, taking arbitrary @@ -123,6 +124,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = } /** + Computes the principal value of the sine. + */ +- (NSNumber *)mgl_sin:(NSNumber *)number { + return @(sin(number.doubleValue)); +} + +/** Computes the principal value of the inverse tangent. */ - (NSNumber *)mgl_atan:(NSNumber *)number { @@ -710,6 +718,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"acos" : @"mgl_acos:", @"cos" : @"mgl_cos:", @"asin" : @"mgl_asin:", + @"sin" : @"mgl_sin:", @"atan" : @"mgl_atan:", @"floor": @"floor:", @"ceil": @"ceiling:", @@ -956,6 +965,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"mgl_acos:" : @"acos", @"mgl_cos:" : @"cos", @"mgl_asin:" : @"asin", + @"mgl_sin:" : @"sin", @"mgl_atan:" : @"atan", // Vararg aftermarket expressions need to be declared with an explicit and implicit first argument. @"MGL_LET": @"let", diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index badc9904cc..4e18ad694d 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -553,6 +553,13 @@ using namespace std::string_literals; XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } { + NSExpression *expression = [NSExpression expressionForFunction:@"mgl_sin:" arguments:@[MGLConstantExpression(@0)]]; + NSArray *jsonExpression = @[@"sin", @0]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + 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); |