Add expression for Math.abs

This commit is contained in:
Andreas Hocevar
2021-08-03 23:51:24 +02:00
parent 05eac3e384
commit f0cac76718
2 changed files with 18 additions and 0 deletions

View File

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