From a6c02adeb6938e97aa6c78c67c0738bd5fda6bdc Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Tue, 17 Apr 2018 18:23:35 -0400 Subject: [ios, macos] Add trigonometric support to NSExpression. (#11716) * [ios, macos] Add acos NSExpresssion operator. * [ios, macos] Add asin NSExpresssion operator. * [ios, macos] Add atan NSExpresssion operator. * [ios, macos] Add cosine NSExpresssion operator. * [ios, macos] Add sine NSExpresssion operator. * [ios, macos] Add tangent NSExpresssion operator. * [ios, macos] Add log2 NSExpresssion operator. * [ios, macos] Update style authors documentation. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm') diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 54f98c6ab9..46a463430b 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -68,6 +68,13 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = INSTALL_METHOD(mgl_step:from:stops:); INSTALL_METHOD(mgl_coalesce:); INSTALL_METHOD(mgl_does:have:); + INSTALL_METHOD(mgl_acos:); + INSTALL_METHOD(mgl_cos:); + INSTALL_METHOD(mgl_asin:); + 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 @@ -97,6 +104,55 @@ const MGLExpressionInterpolationMode MGLExpressionInterpolationModeCubicBezier = return @(round(number.doubleValue)); } +/** + Computes the principal value of the inverse cosine. + */ +- (NSNumber *)mgl_acos:(NSNumber *)number { + return @(acos(number.doubleValue)); +} + +/** + Computes the principal value of the cosine. + */ +- (NSNumber *)mgl_cos:(NSNumber *)number { + return @(cos(number.doubleValue)); +} + +/** + Computes the principal value of the inverse sine. + */ +- (NSNumber *)mgl_asin:(NSNumber *)number { + return @(asin(number.doubleValue)); +} + +/** + Computes the principal value of the sine. + */ +- (NSNumber *)mgl_sin:(NSNumber *)number { + return @(sin(number.doubleValue)); +} + +/** + Computes the principal value of the inverse tangent. + */ +- (NSNumber *)mgl_atan:(NSNumber *)number { + return @(atan(number.doubleValue)); +} + +/** + Computes the principal value of the tangent. + */ +- (NSNumber *)mgl_tan:(NSNumber *)number { + return @(tan(number.doubleValue)); +} + +/** + 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. */ @@ -675,6 +731,13 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"ln": @"ln:", @"abs": @"abs:", @"round": @"mgl_round:", + @"acos" : @"mgl_acos:", + @"cos" : @"mgl_cos:", + @"asin" : @"mgl_asin:", + @"sin" : @"mgl_sin:", + @"atan" : @"mgl_atan:", + @"tan" : @"mgl_tan:", + @"log2" : @"mgl_log2:", @"floor": @"floor:", @"ceil": @"ceiling:", @"^": @"raise:toPower:", @@ -917,6 +980,13 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { @"lowercase:": @"downcase", @"length:": @"length", @"mgl_round:": @"round", + @"mgl_acos:" : @"acos", + @"mgl_cos:" : @"cos", + @"mgl_asin:" : @"asin", + @"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", -- cgit v1.2.1