diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-04-17 17:14:42 -0400 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-04-17 17:14:42 -0400 |
commit | 798bcbee01467ac48347d54405277104ccdedec5 (patch) | |
tree | 3cda70d6e50495b3655c85e6e4b657e11e6efdf8 | |
parent | 6b97f71bd6e25fc9d1aac7987768f56b78fcf24d (diff) | |
download | qtlocation-mapboxgl-798bcbee01467ac48347d54405277104ccdedec5.tar.gz |
[ios, macos] Add log2 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 e641c79628..46a463430b 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -74,6 +74,7 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_sin:); INSTALL_METHOD(mgl_atan:); INSTALL_METHOD(mgl_tan:); + INSTALL_METHOD(mgl_log2:); // Install functions that resemble control structures, taking arbitrary // numbers of arguments. Vararg aftermarket functions need to be declared @@ -146,6 +147,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = } /** + Computes the logarithm base two of the value. + */ +- (NSNumber *)mgl_log2:(NSNumber *)number { + return @(log2(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 { @@ -729,6 +737,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"sin" : @"mgl_sin:", @"atan" : @"mgl_atan:", @"tan" : @"mgl_tan:", + @"log2" : @"mgl_log2:", @"floor": @"floor:", @"ceil": @"ceiling:", @"^": @"raise:toPower:", @@ -977,6 +986,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"mgl_sin:" : @"sin", @"mgl_atan:" : @"atan", @"mgl_tan:" : @"tan", + @"mgl_log2:" : @"log2", // 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 864310356c..d7c86ed07c 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -504,6 +504,13 @@ using namespace std::string_literals; XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } { + NSExpression *expression = [NSExpression expressionForFunction:@"mgl_log2:" arguments:@[MGLConstantExpression(@1024)]]; + NSArray *jsonExpression = @[@"log2", @1024]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([expression expressionValueWithObject:nil context:nil], @10); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { NSExpression *expression = [NSExpression expressionForFunction:@"raise:toPower:" arguments:arguments]; NSArray *jsonExpression = @[@"^", @1, @1]; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); |