atl::math
Math helpers and the value types Vec3, Quat, Color and Uuid. Their math runs in WASM.
LuaNumber
Section titled "LuaNumber"pub struct LuaNumber(pub f64)Numbers: whole numbers print without a fraction, anything else through Lua's tostring, so the output matches what a Lua mod would print.
Implements Display
pub struct Vec3A 3D vector (sm.vec3). Plain value type; arithmetic happens in WASM.
Fields
pub x: f64pub y: f64pub z: f64Methods and constants
pub const fn new(x: f64, y: f64, z: f64) -> Vec3A vector from its components.
pub const ZERO: Vec3 = Vec3::new(0.0, 0.0, 0.0)(0, 0, 0).
pub const ONE: Vec3 = Vec3::new(1.0, 1.0, 1.0)(1, 1, 1).
pub fn dot(self, o: Vec3) -> f64Dot product.
pub fn cross(self, o: Vec3) -> Vec3Cross product.
pub fn length2(self) -> f64Squared length (cheaper than length()).
pub fn length(self) -> f64Length.
pub fn distance(self, o: Vec3) -> f64Distance to another point.
pub fn distance2(self, o: Vec3) -> f64Squared distance to another point.
pub fn normalize(self) -> Vec3Unit vector in the same direction; a zero vector stays zero.
pub fn safe_normalize(self, fallback: Vec3) -> Vec3Unit vector in the same direction, or fallback for a zero vector.
pub fn lerp(self, to: Vec3, t: f64) -> Vec3Linear interpolation towards to.
pub fn fuzzy_equals(self, o: Vec3, eps: f64) -> boolTrue when the two vectors are within eps of each other.
pub fn abs(self) -> Vec3Component-wise absolute value, floor and ceil.
pub fn floor(self) -> Vec3pub fn ceil(self) -> Vec3pub fn min(self, o: Vec3) -> Vec3Component-wise minimum and maximum.
pub fn max(self, o: Vec3) -> Vec3pub fn rotate(self, radians: f64, axis: Vec3) -> Vec3This vector rotated radians around axis (same convention as Quat::angle_axis).
pub fn rotate_x(self, radians: f64) -> Vec3Rotation around a world axis.
pub fn rotate_y(self, radians: f64) -> Vec3pub fn rotate_z(self, radians: f64) -> Vec3pub fn closest_axis(self) -> Vec3The axis-aligned unit vector closest to this direction.
pub fn bezier2(c0: Vec3, c1: Vec3, c2: Vec3, t: f64) -> Vec3Point on a quadratic Bezier curve at t (0..1).
pub fn bezier3(c0: Vec3, c1: Vec3, c2: Vec3, c3: Vec3, t: f64) -> Vec3Point on a cubic Bezier curve at t (0..1).
Implements Add, AddAssign, Clone, Codec, Copy, Debug, Default, Display, Div, Div<f64>, DivAssign<f64>, FromLua, IntoLua, Mul, Mul<f64>, Mul<Vec3>, MulAssign<f64>, Neg, PartialEq, Sub, SubAssign
pub struct QuatA rotation quaternion (sm.quat). Plain value type; w = 1 is no rotation.
Fields
pub x: f64pub y: f64pub z: f64pub w: f64Methods and constants
pub const fn new(x: f64, y: f64, z: f64, w: f64) -> QuatA quaternion from its components.
pub const IDENTITY: Quat = Quat::new(0.0, 0.0, 0.0, 1.0)No rotation.
pub const ROT_X90: Quat = Quat::new(HALF_SQRT2, 0.0, 0.0, HALF_SQRT2)Fixed 90 and 180 degree rotations (sm.quat.rotX90() and so on).
pub const ROT_Y90: Quat = Quat::new(0.0, HALF_SQRT2, 0.0, HALF_SQRT2)pub const ROT_Z90: Quat = Quat::new(0.0, 0.0, HALF_SQRT2, HALF_SQRT2)pub const ROT_NEG_X90: Quat = Quat::new(-HALF_SQRT2, 0.0, 0.0, HALF_SQRT2)pub const ROT_NEG_Y90: Quat = Quat::new(0.0, -HALF_SQRT2, 0.0, HALF_SQRT2)pub const ROT_NEG_Z90: Quat = Quat::new(0.0, 0.0, -HALF_SQRT2, HALF_SQRT2)pub const ROT_X180: Quat = Quat::new(1.0, 0.0, 0.0, 0.0)pub const ROT_Y180: Quat = Quat::new(0.0, 1.0, 0.0, 0.0)pub const ROT_Z180: Quat = Quat::new(0.0, 0.0, 1.0, 0.0)pub fn angle_axis(radians: f64, axis: Vec3) -> QuatA rotation of radians around axis.
pub fn from_euler(degrees: Vec3) -> QuatA rotation from Euler angles in degrees (sm.quat.fromEuler).
pub fn look_rotation(at: Vec3, up: Vec3) -> QuatA rotation facing at with up as up (sm.quat.lookRotation).
pub fn from_to(from: Vec3, to: Vec3) -> QuatThe shortest rotation taking direction from to direction to (sm.vec3.getRotation).
pub fn at(self) -> Vec3The rotated forward, up and right directions (Quat:getAt/getUp/getRight).
pub fn up(self) -> Vec3pub fn right(self) -> Vec3pub fn round90(self) -> QuatSnapped to the nearest 90 degree steps.
pub fn safe_normalize(self, fallback: Quat) -> QuatNormalized, or fallback if the quaternion has zero length.
pub fn normalize(self) -> QuatUnit length; a zero quaternion becomes the identity.
pub fn inverse(self) -> QuatThe opposite rotation.
pub fn slerp(self, mut to: Quat, t: f64) -> QuatSpherical interpolation towards to along the shortest path.
Implements Clone, Codec, Copy, Debug, Default, Display, FromLua, IntoLua, Mul, Mul<Vec3>, PartialEq
pub struct ColorAn RGBA color (sm.color) with channels from 0 to 1. Defaults to white.
Fields
pub r: f64pub g: f64pub b: f64pub a: f64Methods and constants
pub const fn new(r: f64, g: f64, b: f64, a: f64) -> ColorA color from its channels.
pub const WHITE: Color = Color::new(1.0, 1.0, 1.0, 1.0)Opaque white.
pub const fn rgb(hex: u32) -> ColorA color from 0xRRGGBB, e.g. Color::rgb(0x4a90d9).
pub const fn rgba(hex: u32) -> ColorA color from 0xRRGGBBAA.
pub fn hex(s: &str) -> ColorA color from "#rrggbb", "rrggbb", "#rrggbbaa" or "rrggbbaa".
pub fn lerp(self, to: Color, t: f64) -> ColorLinear interpolation towards to.
pub fn hex_string(self) -> String"rrggbbaa", as Color:getHexStr().
pub fn tag(self) -> String"#rrggbb", the color tag used in chat and GUI text.
pub fn gui_string(self) -> StringThe engine's GUI color string, as Color:getGuiColorStr().
pub fn uint_rgba(self) -> u320xRRGGBBAA, as Color:getUintRgba().
Implements Clone, Codec, Copy, Debug, Default, Display, FromLua, IntoLua, PartialEq
pub struct UuidA uuid (sm.uuid), stored as its 36-character text.
Methods and constants
pub const NIL: Uuid = Uuid::new("00000000-0000-0000-0000-000000000000")The nil uuid (all zeros).
pub const fn new(s: &str) -> UuidParses the text form; missing characters become '0'.
pub fn random() -> UuidA random uuid.
pub fn named(ns: Uuid, name: &str) -> UuidA version 5 uuid: the same name in the same ns always gives the same uuid.
pub fn is_nil(&self) -> boolTrue for the nil uuid.
pub fn as_str(&self) -> &strThe 36-character text.
pub fn bytes(&self) -> &[u8; 36]The 36 bytes of text.
Implements Clone, Codec, Copy, Debug, Default, Display, Eq, FromLua, Hash, IntoLua, PartialEq
Functions
Section titled "Functions"pub fn sqrt(x: f64) -> f64Square root.
pub fn abs(x: f64) -> f64Absolute value.
pub fn floor(x: f64) -> f64Rounds down / up to a whole number.
pub fn ceil(x: f64) -> f64pub fn sin(x: f64) -> f64Trigonometry and pow, computed by Lua's math library.
pub fn cos(x: f64) -> f64pub fn tan(x: f64) -> f64pub fn asin(x: f64) -> f64pub fn acos(x: f64) -> f64pub fn atan2(y: f64, x: f64) -> f64pub fn pow(x: f64, y: f64) -> f64pub fn clamp(x: f64, lo: f64, hi: f64) -> f64x limited to the range lo..=hi.
pub fn lerp(a: f64, b: f64, t: f64) -> f64Linear interpolation from a (t = 0) to b (t = 1).
pub const fn vec3(x: f64, y: f64, z: f64) -> Vec3Shorthand for Vec3::new.
Constants
Section titled "Constants"pub const PI: f64 = core::f64::consts::PIPi.
pub const DEG: f64 = PI / 180.0Degrees to radians: 90.0 * DEG.