summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 16:15:26 -0400
committerFabian Guerra <fabian.guerra@mapbox.com>2018-04-17 16:15:26 -0400
commit6b97f71bd6e25fc9d1aac7987768f56b78fcf24d (patch)
tree90093a76b3e31d7062c5b8cfe0da9f63304bcce8
parentd830d6dacc428bf4779633b4aa65c6fb2bad577a (diff)
downloadqtlocation-mapboxgl-6b97f71bd6e25fc9d1aac7987768f56b78fcf24d.tar.gz
[ios, macos] Add tangent 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 8c79fd43f8..e641c79628 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -73,6 +73,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
INSTALL_METHOD(mgl_asin:);
INSTALL_METHOD(mgl_sin:);
INSTALL_METHOD(mgl_atan:);
+ INSTALL_METHOD(mgl_tan:);
// Install functions that resemble control structures, taking arbitrary
// numbers of arguments. Vararg aftermarket functions need to be declared
@@ -138,6 +139,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier =
}
/**
+ Computes the principal value of the tangent.
+ */
+- (NSNumber *)mgl_tan:(NSNumber *)number {
+ return @(tan(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 {
@@ -720,6 +728,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"asin" : @"mgl_asin:",
@"sin" : @"mgl_sin:",
@"atan" : @"mgl_atan:",
+ @"tan" : @"mgl_tan:",
@"floor": @"floor:",
@"ceil": @"ceiling:",
@"^": @"raise:toPower:",
@@ -967,6 +976,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
@"mgl_asin:" : @"asin",
@"mgl_sin:" : @"sin",
@"mgl_atan:" : @"atan",
+ @"mgl_tan:" : @"tan",
// 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 4e18ad694d..864310356c 100644
--- a/platform/darwin/test/MGLExpressionTests.mm
+++ b/platform/darwin/test/MGLExpressionTests.mm
@@ -567,6 +567,13 @@ using namespace std::string_literals;
XCTAssertEqualWithAccuracy(value.doubleValue, 1.52, 0.001);
XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
}
+ {
+ NSExpression *expression = [NSExpression expressionForFunction:@"mgl_tan:" arguments:@[MGLConstantExpression(@0)]];
+ NSArray *jsonExpression = @[@"tan", @0];
+ XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression);
+ XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @0);
+ XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression);
+ }
}
- (void)testStringFormattingExpressionObject {