summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 15:57:09 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 15:57:09 -0400
commit3951b203c8a316ca6bc5f0b46c8aea4e3bd7c1f5 (patch)
tree6fcbe97384f97571d9599b87016b79d6c621db7d
parent43c961dafdbcc4e13bc9c83995629c8c90f7f4f5 (diff)
downloadqtlocation-mapboxgl-3951b203c8a316ca6bc5f0b46c8aea4e3bd7c1f5.tar.gz
[ios, macos] Add atan NSExpresssion operator.
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm14
-rw-r--r--platform/darwin/test/MGLExpressionTests.mm8
2 files changed, 20 insertions, 2 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index f03980f09b..d23da18597 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -70,6 +70,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
INSTALL_METHOD(mgl_does:have:);
INSTALL_METHOD(mgl_acos:);
INSTALL_METHOD(mgl_asin:);
+ INSTALL_METHOD(mgl_atan:);
// Install functions that resemble control structures, taking arbitrary
// numbers of arguments. Vararg aftermarket functions need to be declared
@@ -100,20 +101,27 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
}
/**
- Computes the principal value of the arc cosine.
+ Computes the principal value of the inverse cosine.
*/
- (NSNumber *)mgl_acos:(NSNumber *)number {
return @(acos(number.doubleValue));
}
/**
- Computes the principal value of the arc sine.
+ Computes the principal value of the inverse sine.
*/
- (NSNumber *)mgl_asin:(NSNumber *)number {
return @(asin(number.doubleValue));
}
/**
+ Computes the principal value of the inverse tangent.
+ */
+- (NSNumber *)mgl_atan:(NSNumber *)number {
+ return @(atan(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 {
@@ -693,6 +701,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"round": @"mgl_round:",
@"acos" : @"mgl_acos:",
@"asin" : @"mgl_asin:",
+ @"atan" : @"mgl_atan:",
@"floor": @"floor:",
@"ceil": @"ceiling:",
@"^": @"raise:toPower:",
@@ -937,6 +946,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"mgl_round:": @"round",
@"mgl_acos:" : @"acos",
@"mgl_asin:" : @"asin",
+ @"mgl_atan:" : @"atan",
// 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 0fe7b22ea6..20e252c06b 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -545,6 +545,14 @@ using namespace std::string_literals;
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);
+ NSNumber *value = [expression expressionValueWithObject:nil context:nil];
+ XCTAssertEqualWithAccuracy(value.doubleValue, 1.52, 0.001);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
}
- (void)testStringFormattingExpressionObject {