Add floor, round and ceil
This commit is contained in:
@@ -38,6 +38,9 @@ import {log2} from '../math.js';
|
||||
* * `['%', 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`
|
||||
* * `['floor', value1]` returns the nearest integer less than or equal to `value1`
|
||||
* * `['round', value1]` returns the nearest integer to `value1`
|
||||
* * `['ceil', value1]` returns the nearest integer greater than or equal to `value1`
|
||||
* * `['sin', value1]` returns the sine of `value1`
|
||||
* * `['cos', value1]` returns the cosine of `value1`
|
||||
* * `['atan', value1, value2]` returns `atan2(value1, value2)`. If `value2` is not provided, returns `atan(value1)`
|
||||
@@ -667,6 +670,39 @@ Operators['abs'] = {
|
||||
},
|
||||
};
|
||||
|
||||
Operators['floor'] = {
|
||||
getReturnType: function (args) {
|
||||
return ValueTypes.NUMBER;
|
||||
},
|
||||
toGlsl: function (context, args) {
|
||||
assertArgsCount(args, 1);
|
||||
assertNumbers(args);
|
||||
return `floor(${expressionToGlsl(context, args[0])})`;
|
||||
},
|
||||
};
|
||||
|
||||
Operators['round'] = {
|
||||
getReturnType: function (args) {
|
||||
return ValueTypes.NUMBER;
|
||||
},
|
||||
toGlsl: function (context, args) {
|
||||
assertArgsCount(args, 1);
|
||||
assertNumbers(args);
|
||||
return `floor(${expressionToGlsl(context, args[0])} + 0.5)`;
|
||||
},
|
||||
};
|
||||
|
||||
Operators['ceil'] = {
|
||||
getReturnType: function (args) {
|
||||
return ValueTypes.NUMBER;
|
||||
},
|
||||
toGlsl: function (context, args) {
|
||||
assertArgsCount(args, 1);
|
||||
assertNumbers(args);
|
||||
return `ceil(${expressionToGlsl(context, args[0])})`;
|
||||
},
|
||||
};
|
||||
|
||||
Operators['sin'] = {
|
||||
getReturnType: function (args) {
|
||||
return ValueTypes.NUMBER;
|
||||
|
||||
Reference in New Issue
Block a user