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
This commit is contained in:
Anand Thakker
2018-04-11 12:03:56 -04:00
committed by GitHub
parent 797486bc5f
commit f0f67b4788
11 changed files with 317 additions and 33 deletions

View File

@@ -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>
*/
@@ -2294,6 +2295,185 @@ public class Expression {
return max(numberExpression);
}
/**
* 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>
@@ -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>

View File

@@ -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