Skip to content

luxe: math


import "luxe: math" for Math

Utility class with static math functions.

Math.add(a : Vec, b : Vec) : unknown

Add two 3D vectors together componentwise, returning the result

Math.add2D(a : Vec, b : Vec) : unknown

Add two vector2s together componentwise, returning the result

Math.add_to(a : Vec, b : Vec) : unknown

Add two 3D vectors together componentwise, updating the first vector

Math.add2D_to(a : Vec, b : Vec) : unknown

Add two 2D vectors together componentwise, updating the first vector

Math.sub(a : Vec, b : Vec) : unknown

Subtract two 3D vectors together componentwise, returning the result

Math.sub2D(a : Vec, b : Vec) : unknown

Subtract two 2D vectors together componentwise, returning the result

Math.sub_to(a : Vec, b : Vec) : unknown

Subtract two 3D vectors together componentwise, updating the first vector

Math.sub2D_to(a : Vec, b : Vec) : unknown

Subtract two 2D vectors together componentwise, updating the first vector

Math.mults(a : Vec, b : Num) : unknown

Multiply a 3D vector by a scalar, returning the result

Math.mult(a : Vec, b : Vec) : unknown

Multiply two 3D vectors together componentwise, returning the result

Math.mult2D(a : Vec, b : Vec) : unknown

Multiply two 2D vectors together componentwise, returning the result

Math.mult_to(a : Vec, b : Vec) : unknown

Multiply two 3D vectors together componentwise, updating the first vector

Math.mults_to(a : Vec, b : Num) : unknown

Multiply a 3D vector by a scalar, updating the vector

Math.mult2D_to(a : Vec, b : Vec) : unknown

Multiply two 2D vectors together componentwise, updating the first vector

Math.scale(a : Vec, s : Num) : unknown

Multiply a 3D vector by a scalar, returning the result

Math.scale2D(a : Vec, s : Num) : unknown

Multiply a 2D vector by a scalar, returning the result

Math.scale_to(a : Vec, s : Num) : unknown

Multiply a 3D vector by a scalar, updating the vector

Math.scale2D_to(a : Vec, s : Num) : unknown

Multiply a 2D vector by a scalar, updating the vector

Math.divide(a : Vec, b : Vec) : unknown

Divide a 3D vector by another, returning the result

Math.divide_to(vec : Vec, other : Vec) : unknown

Divide a 3D vector by another, updating the vector

Math.divide2D(a : Vec, b : Vec) : unknown

Divide a 2D vector by another, returning the result

Math.divide2D_to(vec : Vec, other : Vec) : unknown

Divide a 2D vector by another, updating the vector

Math.div(a : Vec, s : Num) : unknown

Divide a 3D vector by a scalar, returning the result

Math.div2D(a : Vec, s : Num) : unknown

Divide a 2D vector by a scalar, returning the result

Math.div_to(a : Vec, s : Num) : unknown

Divide a 3D vector by a scalar, updating the vector

Math.div2D_to(a : Vec, s : Num) : unknown

Divide a 2D vector by a scalar, updating the vector

Math.equal(a : Vec, b : Vec) : Bool

Checks if two vectors are equal. Vectors of different dimensions (e.g. 2D and 3D) are considered unequal

Math.length(x : Num, y : Num) : Num

Length of a 2d vector.

Math.length(x : Num, y : Num, z : Num) : Num

Length of a 3d vector.

Math.length(vec : Vec) : Num

Length of a 3d vector.

Math.length2D(vec : Vec) : Num

Length of a 2d vector.

Math.length_sq(x : Num, y : Num) : Num

Squared length of a 2d vector (slightly cheaper than length).

Math.length_sq(x : Num, y : Num, z : Num) : Num

Squared length of a 3d vector (slightly cheaper than length).

Math.length_sq(vec : Vec) : Num

Squared length of a 3d vector.

Math.length_sq2D(vec : Vec) : Num

Squared length of a 2d vector.

Math.dot(x : Num, y : Num, z : Num, other_x : Num, other_y : Num, other_z : Num) : Num

Dot product (or scalar product) of two 3d vectors.

Math.dot(x : Num, y : Num, other_x : Num, other_y : Num) : Num

Dot product (or scalar product) of two 2d vectors.

Math.dot(vec : Vec, other : Vec) : Num

Dot product (or scalar product) of two 3d vectors.

Math.dot2D(vec : Vec, other : Vec) : Num

Dot product (or scalar product) of two 2d vectors.

Math.cross(a : Vec, b : Vec) : Vec

Cross product of two 3d vectors. Result will always be orthogonal to both input vectors (and [0, 0, 0] if the arguments are parallel)

Math.angle(from : Vec, to : Vec) : Num

Unsigned angle between two 3d vectors.

Math.angle(v1 : Vec, v2 : Vec, up : Vec) : Num

Signed angle between two 3d vectors.

Math.angle2D(from : Vec, to : Vec) : Num

Signed angle between two 2d vectors.

Math.angle2D(from_x : Num, from_y : Num, to_x : Num, to_y : Num) : Num

Signed angle between two 2d vectors.

Math.normalize2D(vec : Vec) : None

Normalize 2d vector. Changes input vector and doesnt return anything. 0 length vectors remain untouched.

Math.normalized(vec : Vec) : None

Normalize 3d vector. Returns the result.

Math.normalized2D(vec : Vec) : None

Normalize 2d vector. Returns the result.

Math.normalize(vec : Vec) : None

Normalize 3d vector. Changes input vector and doesnt return anything. 0 length vectors remain untouched.

Math.dist(x : Num, y : Num, z : Num, other_x : Num, other_y : Num, other_z : Num) : Num

Distance between two 3d vectors.

Math.dist(vec : Vec, other : Vec) : Num

Distance between two 3d vectors.

Math.dist2D(vec : Vec, other : Vec) : Num

Distance between two 2d vectors.

Math.dist2D(x : Num, y : Num, other_x : Num, other_y : Num) : Num

Distance between two 2d vectors.

Math.dir2D(pos : Vec, target : Vec) : Vec

Directional vector (length 1 unless the arguments are the same) between two 2d vectors.

Math.dir(pos : Vec, target : Vec) : Vec

Directional vector (length 1 unless the arguments are the same) between two 3d vectors.

Math.rotate(vec : Vec, axis : Vec, angle : Num) : Vec

Rotate a 3d vector around the given axis by angle degrees

Math.rotate_by_quat(vec : Vec, quat : Float4) : Vec

Rotate a 3d vector using the given quaternion

Math.quat_from_euler(vec : Vec) : Float4

Create a quaternion from float3 euler (radians)

Math.rotate(vec : Vec, ox : Num, oy : Num, angle : Num) : None

Rotate 2d vector around another 2d vector. This rotates the input vector and doesnt return anything.

Math.ray_intersect_plane(plane_x : Num, plane_y : Num, plane_z : Num, normal_x : Num, normal_y : Num, normal_z : Num, ray_x : Num, ray_y : Num, ray_z : Num, ray_dir_x : Num, ray_dir_y : Num, ray_dir_z : Num) : Vec

Intersection point between an infinitely long ray and a infinitely big plane. Returns null if parallel.

Math.closest_point_on_plane(plane_x : Num, plane_y : Num, plane_z : Num, normal_x : Num, normal_y : Num, normal_z : Num, point_x : Num, point_y : Num, point_z : Num) : Vec

Closest point on an infinite plane to a point.

Math.closest_point_on_line(line_x : Num, line_y : Num, line_z : Num, line_end_x : Num, line_end_y : Num, line_end_z : Num, point_x : Num, point_y : Num, point_z : Num) : Vec

Closest point on an infinite line to a point. The progress from line start to line end in 4th component of return value. Line is constructed by 2 points on the line, but the closest point can also be before the start of after the end (in that case the 4th component of the return value wont be in the 0-1 range).

Math.closest_point_on_line(line : Vec, line_end : Vec, point : Vec) : Vec

Closest point on an infinite line to a point. The progress from line start to line end in 4th component of return value. Line is constructed by 2 points on the line, but the closest point can also be before the start of after the end (in that case the 4th component of the return value wont be in the 0-1 range).

Math.in_rect(x : Num, y : Num, rx : Num, ry : Num, rw : Num, rh : Num) : Bool

Checks if a 2d point is inside a rectangle. Only works for positive rectangle sizes.

Math.in_volume(pos : Vec, origin : Vec, extents : Vec) : unknown

Checks if point is inside the volume at origin with extents

Math.wrap(value : Num, modulus : Num) : Num

no docs found

Math.overlaps(x0 : Num, y0 : Num, w0 : Num, h0 : Num, x1 : Num, y1 : Num, w1 : Num, h1 : Num) : Bool

Checks if two rectangles overlap. Only works for positive rectangle sizes.

Math.sign(x : Num) : Num

The sign of the number, expressed as a -1, 1 or 0, for negative and positive numbers, and zero.

Math.sign0(x : Num) : Num

The sign of the number, expressed as a -1 0r 1, for negative and positive numbers, zero is positive.

Math.atan2(y : Num, x : Num) : Num

The arc tangent of y when divided by x, using the signs of the two numbers to determine the quadrant of the result. (equivalient to y.atan(x))

Math.degrees(radians : Num) : Num

Convert radians (0…2*PI) to degree (0…360).

Math.radians(degrees : Num) : Num

Convert degree (0…360) to radians (0…2*PI).

Math.clamp(value : Num, a : Num, b : Num) : Num

Clamp value between a and b (result will never be smaller than a or bigger than b). Equivalent to value.clamp(a, b).

Math.min(a : Num, b : Num) : Num

The smaller of two numbers. Eqivalent to a.min(b).

Math.max(a : Num, b : Num) : Num

The larger of two numbers. Eqivalent to a.max(b).

Math.floor_around_zero(a : Num) : Num

Round towards zero. (floor when positive, ceil when negative)

Math.ceil_around_zero(a : Num) : Num

Round away from zero. (ceil when positive, floor when negative)

Math.fixed(value : Num) : Num

Round number to 3 digits after comma precision.

Math.fixed(value : Num, precision : Num) : Num

Round number to precision digits after comma precision.

Math.angle_delta(from : Num, to : Num) : Num

Signed difference between two (degree) angles. Always in -180…180 range.

Math.lerp2D(a : Vec, b : Vec, t : Num) : Vec

Linearly interpolate between two vectors. Returns a when t is 0 and b when t is 1, with values inbetween interpolating inbetween. If t is outside 0-1 range, the output will be extrapolated.

Math.lerp3D(a : Vec, b : Vec, t : Num) : Vec

Linearly interpolate between two vectors. Returns a when t is 0 and b when t is 1, with values inbetween interpolating inbetween. If t is outside 0-1 range, the output will be extrapolated.

Math.smooth_t(t : Num, smoothness : Num) : Num

Get a smooth time t for lerping, based on a smoothness value. e.g t = smooth_t(delta, 1.25). exponential decay

Math.smoother_t(t : Num, smoothness : Num) : Num

Get a smooth time t for lerping, based on a smoothness value. e.g t = smoother_t(delta, 1.25). s curve like shape

Math.lerp(a : Num, b : Num, t : Num) : Num

Linearly interpolate between two numbers. Returns a when t is 0 and b when t is 1, with values inbetween interpolating inbetween. If t is outside 0-1 range, the output will be extrapolated.

Math.lerp_angle(a : Num, b : Num, t : Num) : Num

Interpolates between angles. Always in 0…360 range.

Math.weighted_avg(value : Num, target : Num, slowness : Num) : unknown

no docs found

Math.within_range(value : Num, start_range : Num, end_range : Num) : unknown

Checks whether value is inbetween start_range and end_range (inclusive).

Math.approx(one : Num, other : Num) : Bool

Checks whether two values are approximately the same (with a max difference of 0.001).

Math.approx(one : Num, other : Num, epsilon : Num) : Bool

Checks whether two values are approximately the same (with a max difference of epsilon).

Math.wrap_angle(degrees : Num) : Num

Bring angle into 0…360 degree space.

Math.wrap_angle(degrees : Num, lower : Num, upper : Num) : Num

Bring angle into lower…upper degree space.

Math.wrap_radians(radians : Num, lower : Num, upper : Num) : Num

no docs found

Math.nearest_power_of_two(value : Num) : Num

no docs found

Math.map_linear(value : Num, a1 : Num, a2 : Num, b1 : Num, b2 : Num) : Num

Remap value from a1...a2 space to b1...b2 space (unclamped).

Math.smoothstep(x : Num, min : Num, max : Num) : Num

Smoothed inverse lerp using cubic hermite interpolation. Output is clamped between 0 and 1.

Math.smootherstep(x : Num, min : Num, max : Num) : Num

Alternate smooth inverse interpolation with derivative of 0 at min and max points. Output is clamped between 0 and 1.

Math.smoothstepx(x : Num, round : Num, steep : Num) : unknown

no docs found

Math.random_point_in_unit_circle(rng : Random) : Num

Random 2d point in circle of radius 1. Has uniform distribution.

Math.slerp(a : Quat, b : Quat, t : Num) : unknown

no docs found