Files
cell/scripts/math.cm
2025-11-06 18:11:01 -06:00

39 lines
2.5 KiB
Plaintext

var math = this
math.dot[cell.DOC] = "Compute the dot product between two numeric arrays, returning a scalar. Extra elements are ignored."
math.project[cell.DOC] = "Project one vector onto another, returning a new array of the same dimension."
math.rotate[cell.DOC] = "Rotate a 2D point (or array of length 2) by the given angle (in turns) around an optional pivot."
math.midpoint[cell.DOC] = "Compute the midpoint of two arrays of numbers. Only the first two entries are used if 2D is intended."
math.reflect[cell.DOC] = "Reflect a vector across a plane normal. Both arguments must be numeric arrays."
math.distance[cell.DOC] = "Compute the Euclidean distance between two numeric arrays of matching length."
math.direction[cell.DOC] = "Compute the normalized direction vector from the first array to the second."
math.angle[cell.DOC] = "Given a 2D vector, return its angle from the X-axis in radians or some chosen units."
math.norm[cell.DOC] = "Return a normalized copy of the given numeric array. For 2D/3D/4D or arbitrary length."
math.angle_between[cell.DOC] = "Compute the angle between two vectors (2D/3D/4D)."
math.lerp[cell.DOC] = "Linear interpolation between two numbers: lerp(a, b, t)."
math.gcd[cell.DOC] = "Compute the greatest common divisor of two integers."
math.lcm[cell.DOC] = "Compute the least common multiple of two integers."
math.clamp[cell.DOC] = "Clamp a number between low and high. clamp(value, low, high)."
math.angledist[cell.DOC] = "Compute the signed distance between two angles in 'turn' units, e.g. 0..1 range."
math.jitter[cell.DOC] = "Apply a random +/- percentage noise to a number. Example: jitter(100, 0.05) -> ~95..105."
math.mean[cell.DOC] = "Compute the arithmetic mean of an array of numbers."
math.sum[cell.DOC] = "Sum all elements of an array of numbers."
math.sigma[cell.DOC] = "Compute standard deviation of an array of numbers."
math.median[cell.DOC] = "Compute the median of an array of numbers."
math.length[cell.DOC] = "Return the length of a vector (i.e. sqrt of sum of squares)."
math.from_to[cell.DOC] = "Return an array of points from a start to an end, spaced out by a certain distance."
math.TAU = Math.PI * 2;
math.deg2rad = function (deg) { return deg * 0.0174533; };
math.rad2deg = function (rad) { return rad / 0.0174533; };
math.turn2rad = function (x) { return x * Math.TAU; };
math.rad2turn = function (x) { return x / Math.TAU; };
math.turn2deg = function (x) { return x * 360; };
math.deg2turn = function (x) { return x / 360; };
math.rand_int = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
return math