diff options
author | Anand Thakker <anandthakker@users.noreply.github.com> | 2018-04-11 12:03:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-11 12:03:56 -0400 |
commit | f0f67b4788f967ee34f307312db302cecb68dd0b (patch) | |
tree | 90f207635e1c6a67aed11655e9e03b058c556665 /platform/android/MapboxGLAndroidSDK/src/main/java | |
parent | 797486bc5f4d064821865c72425911994fa9fe22 (diff) | |
download | qtlocation-mapboxgl-f0f67b4788f967ee34f307312db302cecb68dd0b.tar.gz |
Add abs, round, floor, ceil operators (#11653)
* Add abs, round, floor, ceil operators
Port of https://github.com/mapbox/mapbox-gl-js/pull/6496
* [ios, macos] Simplified abs, ceiling, floor expressions
* [ios, macos] Added rounding expression function
* [android] - binding integration for round, ceil, floor and abs expressions
* Update mapbox-gl-js to include non-integer rounding test
* Drop extra braces
* mapbox-gl-js -> master
* Update style-spec docs -> PropertyFactory.java
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java')
2 files changed, 186 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java index 05c67018a4..fa4a802e13 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java @@ -81,7 +81,6 @@ import java.util.List; * ) * } * </pre> - * */ public class Expression { @@ -1061,6 +1060,7 @@ public class Expression { * ); * } * </pre> + * * @return expression * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-properties">Style specification</a> */ @@ -1081,6 +1081,7 @@ public class Expression { * ); * } * </pre> + * * @return expression * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-geometry-types">Style specification</a> */ @@ -2295,6 +2296,185 @@ public class Expression { } /** + * Rounds the input to the nearest integer. + * Halfway values are rounded away from zero. + * For example `[\"round\", -1.5]` evaluates to -2. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(round(pi())) + * ); + * } + * </pre> + * + * @param expression number expression to round + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-round">Style specification</a> + */ + public static Expression round(Expression expression) { + return new Expression("round", expression); + } + + /** + * Rounds the input to the nearest integer. + * Halfway values are rounded away from zero. + * For example `[\"round\", -1.5]` evaluates to -2. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(round(3.14159265359f)) + * ); + * } + * </pre> + * + * @param number number to round + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-round">Style specification</a> + */ + public static Expression round(Number number) { + return round(literal(number)); + } + + /** + * Returns the absolute value of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(abs(subtract(pi()))) + * ); + * } + * </pre> + * + * @param expression number expression to get absolute value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression abs(Expression expression) { + return new Expression("abs", expression); + } + + /** + * Returns the absolute value of the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(abs(-3.14159265359f)) + * ); + * } + * </pre> + * + * @param number number to get absolute value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression abs(Number number) { + return abs(literal(number)); + } + + /** + * Returns the smallest integer that is greater than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(ceil(pi())) + * ); + * } + * </pre> + * + * @param expression number expression to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression ceil(Expression expression) { + return new Expression("ceil", expression); + } + + /** + * Returns the smallest integer that is greater than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(ceil(3.14159265359)) + * ); + * } + * </pre> + * @param number number to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression ceil(Number number) { + return ceil(literal(number)); + } + + /** + * Returns the largest integer that is less than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(floor(pi())) + * ); + * } + * </pre> + * + * @param expression number expression to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression floor(Expression expression) { + return new Expression("floor", expression); + } + + /** + * Returns the largest integer that is less than or equal to the input. + * <p> + * Example usage: + * </p> + * <pre> + * {@code + * CircleLayer circleLayer = new CircleLayer("layer-id", "source-id"); + * circleLayer.setProperties( + * circleRadius(floor(pi())) + * ); + * } + * </pre> + * + * @param number number to get value from + * @return expression + * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-abs">Style specification</a> + */ + public static Expression floor(Number number) { + return floor(literal(number)); + } + + /** * Returns the input string converted to uppercase. * <p> * Follows the Unicode Default Case Conversion algorithm @@ -3128,6 +3308,7 @@ public class Expression { * ); * } * </pre> + * * @param expression base number expression * @return expression * @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions-interpolate">Style specification</a> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java index 66d78a40e5..4289deeda3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/PropertyFactory.java @@ -1856,7 +1856,7 @@ public class PropertyFactory { } /** - * Name of image in sprite to use for drawing an image background. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Name of image in sprite to use for drawing an image background. * * @param value a String value * @return property wrapper around String @@ -1866,7 +1866,7 @@ public class PropertyFactory { } /** - * Name of image in sprite to use for drawing an image background. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Name of image in sprite to use for drawing an image background. * * @param value a String value * @return property wrapper around String @@ -2036,7 +2036,7 @@ public class PropertyFactory { } /** - * Value to use for a text label. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Value to use for a text label. * * @param value a String value * @return property wrapper around String @@ -2046,7 +2046,7 @@ public class PropertyFactory { } /** - * Value to use for a text label. Within literal values and zoom functions, property names enclosed in curly brackets (e.g. `{token}`) are replaced with the value of the named property. Expressions and property functions do not support this syntax; for equivalent functionality in expressions, use the [`concat`](#expressions-concat) and [`get`](#expressions-get) operators. + * Value to use for a text label. * * @param value a String value * @return property wrapper around String |