summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 15:40:53 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 15:40:53 -0400
commit43c961dafdbcc4e13bc9c83995629c8c90f7f4f5 (patch)
tree120db398d32d9ec24f420eb4abe5fb441b27ce05
parentdd31a1f94ea363311854d47c62150c5744e2bc19 (diff)
downloadqtlocation-mapboxgl-43c961dafdbcc4e13bc9c83995629c8c90f7f4f5.tar.gz
[ios, macos] Add asin NSExpresssion operator.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm12
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm7
2 files changed, 18 insertions, 1 deletions
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,13 +100,20 @@ 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.
*/
- (id)mgl_interpolate:(id)inputExpression withCurveType:(NSString *)curveType parameters:(NSDictionary *)params stops:(NSDictionary *)stops {
@@ -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 {