Crate maths_rs

source ·

Modules§

  • multi dimensional row-major matrix with generic mat2, mat3, mat34 and mat4 implementations there is a mat43 type for mat34 transposes but it does not support the full functionality
  • base traits and operations for scalar numbers, signed numbers, integers and floats
  • export float types and all functions for qick and easy integration
  • 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 true if the aabb defined by aabb_min to aabb_max overlaps obb defined by matrix obb, where the matrix transforms an aabb with -1 to 1 extents into an obb
  • 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 the arc-cosine of v where the value v is in radians
  • 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 value a is approximately equal to value b within the specified epsilon eps
  • returns the arc-sine of v where the value v is in radians
  • returns the arc-tangent of v where the value v is in radians
  • returns the arc-tangent of v where the value v is in radians
  • 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 true if the capsule cp0-cp1 with radius cr0 overlaps the capsule cp2-cp3 with radius cr1
  • 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 a chebyshevnormalized unit vector of a (where the normalization projects onto the unit cube)
  • 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 and 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 with extents -1 to 1 into an obb
  • returns the closest point on the plane to point p where 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 poly.
  • 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 true if the convex hull convex0 overlaps convex1 where convex hull is an array of vertices forming a 2D convex polygon
  • returns the value a with the same sign as second paremeter sign
  • returns the cosine of v where the value v is in radians
  • returns the hyperbolic cosine of v where the value v is in radians
  • returns the vector cross product of a x b, makes sense only for 3 or 7 dimensional vectors
  • returns value a cubed (raised to the power 3)
  • returns the cubic interpolation of bezier control points p1-p2-p3-p4 with percentage t
  • 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 tangent of bezier control points p1-p2-p3-p4 with percentage t
  • returns the radian value converted from value a which is specificied in degrees
  • returns scalar distance between 2 points a and b (magnitude of the vector between the 2 points)
  • returns scalar squared distance between 2 points a and b to avoid using sqrt
  • returns scalar distance between 2 points a and b (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 the base-e exponential function of v, which is e raised to the power v
  • returns 2 raised to the given power v
  • 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 field of view converted from focal length with the specified aperture_width
  • returns focal length converted field of view with the specified aperture_width
  • returns the fractional part of value 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 true if the 2d convex hull convex0 overlaps with convex1 using the gjk algorithm
  • returns true if the 3D convex hull convex0 overlaps with convex1 using the gjk algorithm
  • finds support vertices for gjk based on convex meshses where convex0 and convex1 are an array of vertices that form a convex hull
  • 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 a
  • 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 the logarithm of v in base
  • returns the binary (base-2) logarithm of v
  • returns the common (base-10) logarithm of v
  • returns fused multiply add m * a + b
  • returns the scalar magnitude or length of vector a
  • returns the scalar magnitude or length of vector a 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 tuple (min, max) of the value a and min_max tuple (min, max)
  • 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 number of bits divisible by 3 in x. value 0b001001001 returns 0b111
  • returns the x,y grid position for morten order index d
  • returns the x,y,z grid position for morten order index d
  • returns the morten order index from x,y position
  • returns the morten order index from x,y,z 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 true if the aabb defined by obb0 overlaps obb1 where the obb’s are defined by a matrix and the matrix transforms an aabb with -1 to 1 extents into an obb
  • 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 (constanr) 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 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 unsigned distance from point p to the obb defined by matrix obb, where the matrix transforms a unit cube from -1 to 1 into an obb
  • 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 unsigned distance from point p0 to the sphere (or 2d circle) centred at s0 with radius r
  • 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 value a raised to the floating point power of value b
  • returns value a raised to the integer power of value 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 value 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 true if there is an intersection between ray wih origin r0 and direction rv against the cylinder with line c0-c1 and radius cr the intersection point is return as an Option if it exists.
  • returns the intersection point if the ray with origin r0 and direction rv 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 with 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 value 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 rgba which is inside u32 (4 bytes, 0xRRGGBBAA)
  • returns the vec2 rotated anti-clockwise rotation by radian angle
  • 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 value 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 scalar triple product of a x b x c, makes sense only for 3 dimensional vectors
  • 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 value a is negative, 1 if positive and 0 if zero (integers)
  • returns the sine of v where the value v is in radians
  • returns a tuple of (sin(v), cos(v)) of v where the value v is in radian
  • 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 the hyperbolic sine of v where the value v is in radians
  • 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 true if the sphere with centre s0 and radius r0 overlaps obb defined by matrix obb, where the matrix transforms a unit cube with extents -1 to 1 into an obb
  • 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 value a squared (raised to the power 2)
  • returns the square root of value a
  • returns 1 if a > b or 0 otherwise
  • returns the tangent of v where the value v is in radians
  • returns the hyperbolic tangent of v where the value v is in radians
  • 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 v of rgba in 0-1 range
  • returns the vector triple product of a x b x c, mainly used for 3D vectors, but with a 2D specialisation leveraging z-up
  • returns (azimuth, altitude) converted from directional unit vector xyz

Type Aliases§