Add expression for Math.abs
This commit is contained in:
@@ -27,6 +27,7 @@ import {asArray, isStringColor} from '../color.js';
|
||||
* * `['clamp', value, low, high]` clamps `value` between `low` and `high`
|
||||
* * `['%', value1, value2]` returns the result of `value1 % value2` (modulo)
|
||||
* * `['^', value1, value2]` returns the value of `value1` raised to the `value2` power
|
||||
* * `['abs', value1]` returns the absolute value of `value1`
|
||||
*
|
||||
* * Transform operators:
|
||||
* * `['case', condition1, output1, ...conditionN, outputN, fallback]` selects the first output whose corresponding
|
||||
@@ -551,6 +552,17 @@ Operators['^'] = {
|
||||
},
|
||||
};
|
||||
|
||||
Operators['abs'] = {
|
||||
getReturnType: function (args) {
|
||||
return ValueTypes.NUMBER;
|
||||
},
|
||||
toGlsl: function (context, args) {
|
||||
assertArgsCount(args, 1);
|
||||
assertNumbers(args);
|
||||
return `abs(${expressionToGlsl(context, args[0])})`;
|
||||
},
|
||||
};
|
||||
|
||||
Operators['>'] = {
|
||||
getReturnType: function (args) {
|
||||
return ValueTypes.BOOLEAN;
|
||||
|
||||
@@ -235,6 +235,12 @@ describe('ol.style.expressions', function () {
|
||||
expect(expressionToGlsl(context, ['^', ['%', ['time'], 10], 2])).to.eql(
|
||||
'pow(mod(u_time, 10.0), 2.0)'
|
||||
);
|
||||
expect(
|
||||
expressionToGlsl(context, [
|
||||
'abs',
|
||||
['-', ['get', 'attr3'], ['get', 'attr2']],
|
||||
])
|
||||
).to.eql('abs((a_attr3 - a_attr2))');
|
||||
expect(expressionToGlsl(context, ['>', 10, ['get', 'attr4']])).to.eql(
|
||||
'(10.0 > a_attr4)'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user