summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 13:59:19 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 13:59:19 -0400
commitdd31a1f94ea363311854d47c62150c5744e2bc19 (patch)
treea26ae5e4c5bc7079684533bacdf051e2ba29a3a1
parent2eeebe5c38b95758db2c69b38d69b877f5a0de31 (diff)
downloadqtlocation-mapboxgl-dd31a1f94ea363311854d47c62150c5744e2bc19.tar.gz
[ios, macos] Add acos NSExpresssion operator.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm10
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm7
2 files changed, 17 insertions, 0 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 54f98c6ab9..9238a291a4 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -68,6 +68,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
INSTALL_METHOD(mgl_step:from:stops:);
INSTALL_METHOD(mgl_coalesce:);
INSTALL_METHOD(mgl_does:have:);
+ INSTALL_METHOD(mgl_acos:);
// Install functions that resemble control structures, taking arbitrary
// numbers of arguments. Vararg aftermarket functions need to be declared
@@ -98,6 +99,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
}
/**
+ Computes the principal value of the arc cosine of number.
+ */
+- (NSNumber *)mgl_acos:(NSNumber *)number {
+ return @(acos(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 {
@@ -675,6 +683,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"ln": @"ln:",
@"abs": @"abs:",
@"round": @"mgl_round:",
+ @"acos" : @"mgl_acos:",
@"floor": @"floor:",
@"ceil": @"ceiling:",
@"^": @"raise:toPower:",
@@ -917,6 +926,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"lowercase:": @"downcase",
@"length:": @"length",
@"mgl_round:": @"round",
+ @"mgl_acos:" : @"acos",
// 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 e078c4f4b6..04198dbfc3 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -531,6 +531,13 @@ using namespace std::string_literals;
XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @(M_PI));
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
+ {
+ NSExpression *expression = [NSExpression expressionForFunction:@"mgl_acos:" arguments:@[MGLConstantExpression(@1)]];
+ NSArray *jsonExpression = @[@"acos", @1];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
}
- (void)testStringFormattingExpressionObject {