Crate maths_rs

source ·

Modules

multi dimensional row-major matrix with generic mat2, mat3, mat34 and mat4 implementations
base traits and operations for scalar numbers, signed numbers, integers and floats
generic quaternion for varying floating point precision
module containing vector swizzling traits
multi dimensional column vector with generic vec2, vec3 and vec4 implementations

Enums

classification for tests vs planes (behind, infront or intersects)

Functions

returns true if the aabb defined by aabb_min1 to aabb_max1 intersects aabb_min2-aabb_max2
returns true if the aabb defined by aabb_pos (centre) and aabb_extent is inside the frustum defined by 6 planes packed as vec4’s .xyz = normal, .w = plane distance
returns the classification of the 3D aabb defined as aabb_min to aabb_max vs the plane defined by point on plane x and normal n
returns ture if the aabb defined by aabb_min to aabb_max intersects the sphere (or circle) centred at s with radius r
returns the absolute (positive) value of a
returns soft clipping (in a cubic fashion) of x; let m be the threshold (anything above m stays unchanged), and n the value things will take when the signal is zero
returns true if a is approximately equal to b within the specified epsilon
returns an xyz directional unit vector converted from azimuth altitude
returns the barycentric coordinate (u, v, w) of point p inside triangle t1-t2-t3
returns the classification of a capsule defined by line c1-c2 with radius r vs a plane defined by point on plane x and normal n
returns the ceil’d value of a(round up to nearest integer)
returns the value x clamped to the range of min and max
returns the closest point on the aabb defined by aabb_min and aabb_max to point p, if the point is inside the aabb it will return p
returns the closest point to p on the cone defined by cp position, with direction cv height h an radius r
returns the clostest point to p on the edge of the convex hull defined by point list ‘hull’ with clockwise winding
returns the closest point on the line l1-l2 to point p
returns the closest point to point p on the obb defined by mat which will transform an aabb centred at 0 with extents -1 to 1 into an obb
returns the closest point on the plane to point p wher the plane is defined by point on plane x and normal n
returns the clostest point to p on the edge of the polygon defined by point list polygon.
returns the closest point to p on the the ray starting at r0 with diection rv
returns the closest point from p on sphere or circle centred at s with radius r
returns the closest point to p on the triangle defined by t1-t2-t3
return the classification of cone defined by position cp, direction cv with height h and radius at the base of r. vs the plane defined by point x and normal n
returns a convex hull wound clockwise from point cloud “points”
returns the value a with the same sign as second paremeter sign
returns the vector cross product of a x b, makes sense only for 3 or 7 dimensional vectors
returns a cubed (raised to the power 3)
returns a cubic pulse (y position on a graph for x); equivalent to: smoothstep(c-w,c,x)-smoothstep(c,c+w,x)
returns the radian value converted from a which is specificied in degrees
returns scalar distance between 2 points (magnitude of the vector between the 2 points)
returns scalar squared distance between 2 points to avoid using sqrt
returns scalar distance between 2 points (magnitude of the vector between the 2 points)
returns the distance parameter t of point p projected along the line l1-l2, the value is not clamped to the line segment extents
returns the distance parameter t of point p projected along the ray r0 with direction rv, the value is not clamped to 0 or the start of the ray
returns the vector dot product between a . b
returns an exponential impulse (y position on a graph for x); k controls the stretching of the function
returns an exponential step (y position on a graph for x); k is control parameter, n is power which gives sharper curves.
returns an exponential sustained impulse (y position on a graph for x); control on the width of attack with k and release with f
returns the floored value of a (round down to nearest integer)
returns the floating point remainder of a / b
returns the fractional part of a
returns gain (y position on a graph for x); remapping the unit interval into the unit interval by expanding the sides and compressing the center
returns the normalized unit vector normal of triangle t1-t2-t3
returns an rgb value in 0-1 range converted from hsv in 0-1 range
returns the integral smoothstep of x it’s derivative is never larger than 1
returns the scalar magnitude or length of vector
returns a value interpolated between edges e0 and e1 by percentage t
returns the intersection point if the line segment l1-l2 intersects with s1-s2
returns the intersection point of the line segment l1-l2 and plane defined by point on plane x and normal n, returns None if no intersection exists
returns the intersection point if the infinite line l1-l2 intersects with s1-s2
returns the intersection point of the infinite line defined as point on line l0 and direction lv with the plane defined by point on plane x and normal n
returns fused multiply add m * a + b
returns the scalar magnitude or length of vector
returns the scalar magnitude or length of vector squared to avoid using sqrt
remap v within in_start -> in_end range to the new range out_start -> out_end
returns the maximum of a and b
returns the minimum of a and b
returns the value v broken down into a tuple (fractional, integer) parts
returns the number even bits extracted from x as set bits in the return; value 0b010101 returns 0b111
returns the x,t grid position for morten order index d
returns the morten order index from x,y position
returns a value interpolated between edges e0 and e1 by percentage t with the result being normalised
returns a normalized unit vector of a
returns a parabola (y position on a graph for x); use k to control its shape
returns a power curve (y position on a graph for x); this is a generalziation of the parabola
returns the perpedicular vector of a performing anti-clockwise rotation by 90 degrees
returns the distance to the plane define by a point on the plane x and normal of the plane n
returns a plane placked into Vec4 in the form .xyz = plane normal, .w = plane distance / constant from x (point on plane) and n (planes normal)
returns the distance that point p is from an aabb defined by aabb_min to aabb_max
returns the distance from point p to the cone defined by position cp, with height h and radius at the base of r
returns the distance from point p to the edge of the convex hull defined by point list ‘hull’ with clockwise winding
returns true if point p is inside the aabb defined by aabb_min and aabb_max
returns true if point p is inside cone defined by position cp facing direction cv with height h and radius r
returns true if the point p is inside the 2D convex hull defined by point list ‘hull’ with clockwise winding
returns true if the point p is inside the frustum defined by 6 planes packed as vec4’s .xyz = normal, .w = plane distance
returns true if the point p is inside the obb defined by mat which will transform an aabb centred at 0 with extents -1 to 1 into an obb
returns true if point p is inside the polygon defined by point list ‘poly’
returns true if sphere (or cirlcle) with centre s and radius r contains point p
returns true if the point p is inside the triangle defined by t1-t2-t3
returns the distance that point p is from the line segment defined by l1-l2
returns the distance to the plane from point p where the plane is defined by point on plane x and normal n
returns the distance from point p to the edge of the polygon defined by point list ‘poly’
returns the distance point p is from a triangle defined by t1-t2-t3
returns the classification of point p vs the plane defined by point on plane x and normal n
returns a quadratic impulse (y position on a graph for x); n is the degree of the polynomial and k controls the stretching of the function
returns a raised to the floating point power b
returns a raised to the integer power b
returns the 3D normalized device coordinate of point p projected by view_projection matrix, perfroming homogenous divide
returns the 2D screen coordinate of 3D point p projected with view_projection, performing homogenous divide and viewport correction assumes screen coordinates are vup in the y-axis y.0 = bottom y.height = top
returns the 2D screen coordinate of 3D point p projected with view_projection, performing homogenous divide and viewport correction coordinates are vdown in the y-axis vdown = y.0 = top y.height = bottom
returns an quadratic impulse (y position on a graph for x); k controls the stretching of the function
returns the degree value converted from a which is specificied in radians
returns the intersection point of the ray with origin r0 and direction rv with the aabb defined by aabb_min and aabb_max
returns the intersection point of ray wih origin r0 and direction rv against the capsule with line c0 - c1 and radius cr
returns the intersection point if the ray intersects the line segment l1-l2
returns the intersection of the 3D ray with origin r0 and direction rv with the obb defined by mat
returns the intersection point of the ray defined as origin of ray r0 and direction rv with the plane defined by point on plane x and normal n
returns the intersection point of ray wih origin r0 and direction rv against the sphere (or circle) centred at s0 with radius r
returns the intersection point of ray r0 and normalized direction rv with triangle t0-t1-t2
returns the reciprocal of a
returns a hsv value in 0-1 range converted from rgb in 0-1 range
returns a vec4 of rgba in 0-1 range from a packed rgba8 inside u32 (4 bytes, R8G8B8A8)
returns the value a rounded to closest integer floor if a < 0.5 or ceil if a >= 0.5
returns the reciprocal square root of a
returns the saturated value of x into to the 0-1 range, this is the same as clamp(x, 0.0, 1.0)
returns the shortest line segment between 2 line segments (p1-p2) and (p3-p4) as an option tuple where .0 is the point on line segment 1 and .1 is the point on line segment 2
returns the shortest line segment between 2 line segments (p1-p2) and (p3-p4) as an option tuple where .0 is the point on line segment 1 and .1 is the point on line segment 2
returns the shortest line segment between 2 lines (p1-p2) and (p3-p4) as an option tuple where .0 is the point on line segment 1 and .1 is the point on line segment 2
returns -1 if number is negative, 1 if positive and 0 if zero (integers)
returns a sin curve (y position on a graph for x); can be used for some bouncing behaviors. give k different integer values to tweak the amount of bounces
returns a value spherically interpolated between edges e0 and e1 by percentage t
returns value t between the range c and d with offset b creating smooth easing at the start (t^2)
returns value t between the range c and d with offset b creating smooth easing at the start (t^3)
returns value t between the range c and d with offset b creating smooth easing at the start (t^4)
returns value t between the range c and d with offset b creating smooth easing at the start (t^5)
returns value t between the range c and d with offset b creating smooth easing at the end of t (t^2)
returns value t between the range c and d with offset b creating smooth easing at the end of t (t^3)
returns value t between the range c and d with offset b creating smooth easing at the end of t (t^4)
returns value t between the range c and d with offset b creating smooth easing at the end of t (t^5)
returns the hermite interpolated value between edge e0 and e1 by percentage t
returns true if the sphere or circle at centre s1 with radius r1 intsercts capsule c0-c1 with radius cr
returns true if the sphere with centre s and radius r is inside the frustum defined by 6 planes packed as vec4’s .xyz = normal, .w = plane distance
returns the classification of sphere defined by centre s and radius r vs the plane defined by point on plane x and normal n
returns true if the sphere or circle at centre s1 with radius r1 intsercts s2-r2
returns a squared (raised to the power 2)
returns the square root of a
returns 1 if a > b or 0 otherwise
truncates value a - removing the fractional part, truncating to an integer
returns the unprojected 3D world position of point p which is specified in normalized device coordinates
returns the unprojected 3D world position of screen coordinate p assumes screen coordinates are vup in the y-axis y.0 = bottom y.height = top
returns the unprojected 3D world position of screen coordinate p coordinates are vdown in the y-axis vdown = y.0 = top y.height = bottom
returns a packed u32 containing rgba8 (4 bytes, R8G8B8A8) converted from a Vec4 of rgba in 0-1 range
returns (azimuth, altitude) converted from xyz directional unit vector

Type Definitions