@openhps/core
Version:
Open Hybrid Positioning System - Core component
63 lines (59 loc) • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sinc = exports.pcurve = exports.parabola = exports.gain = void 0;
var _OperatorNode = require("./OperatorNode.js");
var _MathNode = require("./MathNode.js");
/**
* A function that remaps the `[0,1]` interval into the `[0,1]` interval.
* The corners are mapped to `0` and the center to `1`.
* Reference: {@link https://iquilezles.org/articles/functions/}.
*
* @tsl
* @function
* @param {Node<float>} x - The value to remap.
* @param {Node<float>} k - Allows to control the remapping functions shape by rising the parabola to a power `k`.
* @return {Node<float>} The remapped value.
*/
const parabola = (x, k) => (0, _MathNode.pow)((0, _OperatorNode.mul)(4.0, x.mul((0, _OperatorNode.sub)(1.0, x))), k);
/**
* A function that remaps the `[0,1]` interval into the `[0,1]` interval.
* Expands the sides and compresses the center, and keeps `0.5` mapped to `0.5`.
* Reference: {@link https://iquilezles.org/articles/functions/}.
*
* @tsl
* @function
* @param {Node<float>} x - The value to remap.
* @param {Node<float>} k - `k=1` is the identity curve,`k<1` produces the classic `gain()` shape, and `k>1` produces "s" shaped curves.
* @return {Node<float>} The remapped value.
*/
exports.parabola = parabola;
const gain = (x, k) => x.lessThan(0.5) ? parabola(x.mul(2.0), k).div(2.0) : (0, _OperatorNode.sub)(1.0, parabola((0, _OperatorNode.mul)((0, _OperatorNode.sub)(1.0, x), 2.0), k).div(2.0));
/**
* A function that remaps the `[0,1]` interval into the `[0,1]` interval.
* A generalization of the `parabola()`. Keeps the corners mapped to 0 but allows the control of the shape one either side of the curve.
* Reference: {@link https://iquilezles.org/articles/functions/}.
*
* @tsl
* @function
* @param {Node<float>} x - The value to remap.
* @param {Node<float>} a - First control parameter.
* @param {Node<float>} b - Second control parameter.
* @return {Node<float>} The remapped value.
*/
exports.gain = gain;
const pcurve = (x, a, b) => (0, _MathNode.pow)((0, _OperatorNode.div)((0, _MathNode.pow)(x, a), (0, _OperatorNode.add)((0, _MathNode.pow)(x, a), (0, _MathNode.pow)((0, _OperatorNode.sub)(1.0, x), b))), 1.0 / a);
/**
* A phase shifted sinus curve that starts at zero and ends at zero, with bouncing behavior.
* Reference: {@link https://iquilezles.org/articles/functions/}.
*
* @tsl
* @function
* @param {Node<float>} x - The value to compute the sin for.
* @param {Node<float>} k - Controls the amount of bounces.
* @return {Node<float>} The result value.
*/
exports.pcurve = pcurve;
const sinc = (x, k) => (0, _MathNode.sin)(_MathNode.PI.mul(k.mul(x).sub(1.0))).div(_MathNode.PI.mul(k.mul(x).sub(1.0)));
exports.sinc = sinc;