packages

spatial

On this page

Fixed-size math for games and graphics: vectors, quaternions, column-major matrices, affine transforms and simple shapes.

Every type is generic over its component: Vec3<T>, Quat<T>, Mat4<T>, with T = f32 when left out, so Vec3 is Vec3<f32>. DVec3, DQuat, DMat4, ... name the f64 forms; IVec3 and UVec3 the i32 and u32 vectors. Every type is #[repr(C)] with its components in order, so it goes into a GPU buffer or across the C ABI as it is.

Conventions: column vectors (m * v), matrices stored column by column as GPUs read them, right-handed unless a name says _lh, angles in radians. Projections come in four forms each: _rh / _lh for the handedness of view space, and depth 0..1 (Metal, Direct3D, Vulkan, WebGPU) or, with _gl, -1..1 (OpenGL).

Modules

  • shape Shapes for culling, picking and collision tests: boxes, rays, planes and spheres.

Re-exports

shape::{Aabb, Plane, Ray, Sphere}Source

pub use shape::{Aabb, Plane, Ray, Sphere}
  • Aabb The box of points between min and max on every axis.
  • Plane The points p with normal.dot(p) + d == 0.
  • Ray The points origin + dir * t for t >= 0.
  • Sphere The points within radius of center.

Structs

Affine2Source

pub struct Affine2<T = f32>

A 2D affine transform: matrix * p + translation. Smaller and cheaper than a Mat3 with a fixed last row. #[repr(C)]: the Mat2 then the Vec2, six Ts.

nabi
use spatial::{Affine2, Vec2};

let a = Affine2::from_scale_angle_translation(Vec2::ONE, f32::PI / 2.0, Vec2::new(1.0, 0.0));
assert(a.transform_point(Vec2::X).approx_eq(Vec2::new(1.0, 1.0), 1e-6));
  • pub matrix: Mat2<T>§

    Source
  • pub translation: Vec2<T>§

    Source
  • pub const fn new(matrix: Mat2<T>, translation: Vec2<T>) -> Affine2<T>§

    Source

    The transform of a matrix and a translation.

    nabi
    use spatial::{Affine2, Mat2, Vec2};
    
    assert(Affine2::new(Mat2::IDENTITY, Vec2::ZERO) == Affine2::identity());
    
  • pub fn identity() -> Affine2<T>§

    Source

    No change.

    nabi
    use spatial::{Affine2, Vec2};
    
    assert(Affine2::identity().transform_point(Vec2::ONE) == Vec2::ONE);
    
  • pub fn from_translation(t: Vec2<T>) -> Affine2<T>§

    Source

    The translation by t.

    nabi
    use spatial::{Affine2, Vec2};
    
    assert(Affine2::from_translation(Vec2::X).transform_point(Vec2::ZERO) == Vec2::X);
    
  • pub fn from_scale(s: Vec2<T>) -> Affine2<T>§

    Source

    The scale by s.

    nabi
    use spatial::{Affine2, Vec2};
    
    assert(Affine2::from_scale(Vec2::splat(2.0)).transform_point(Vec2::ONE) == Vec2::splat(2.0));
    
  • pub fn from_angle(angle: T) -> Affine2<T>§

    Source

    The counterclockwise rotation by angle radians.

    nabi
    use spatial::{Affine2, Vec2};
    
    assert(Affine2::from_angle(f32::PI).transform_point(Vec2::X).approx_eq(-Vec2::X, 1e-6));
    
  • pub fn from_scale_angle_translation(scale: Vec2<T>, angle: T, t: Vec2<T>) -> Affine2<T>§

    Source

    Scale, rotate by angle radians, then move by t.

    nabi
    use spatial::{Affine2, Vec2};
    
    let a = Affine2::from_scale_angle_translation(Vec2::splat(3.0), 0.0, Vec2::Y);
    assert(a.transform_point(Vec2::X) == Vec2::new(3.0, 1.0));
    
  • pub fn from_mat3(m: Mat3<T>) -> Affine2<T>§

    Source

    The affine part of a 2D homogeneous Mat3 (its last row ignored).

    nabi
    use spatial::{Affine2, Mat3, Vec2};
    
    assert(Affine2::from_mat3(Mat3::from_translation(Vec2::X)) == Affine2::from_translation(Vec2::X));
    
  • pub fn to_mat3(self) -> Mat3<T>§

    Source

    The same transform as a homogeneous Mat3.

    nabi
    use spatial::{Affine2, Mat3};
    
    assert(Affine2::<f32>::identity().to_mat3() == Mat3::IDENTITY);
    
  • pub fn transform_point(self, p: Vec2<T>) -> Vec2<T>§

    Source

    The point p transformed.

    nabi
    use spatial::{Affine2, Vec2};
    
    assert(Affine2::from_translation(Vec2::X).transform_point(Vec2::Y) == Vec2::ONE);
    
  • pub fn transform_vector(self, v: Vec2<T>) -> Vec2<T>§

    Source

    The direction v transformed, translation left out.

    nabi
    use spatial::{Affine2, Vec2};
    
    assert(Affine2::from_translation(Vec2::X).transform_vector(Vec2::Y) == Vec2::Y);
    
  • pub fn inverse(self) -> Affine2<T>§

    Source

    The inverse transform. A singular matrix gives infinite or NaN entries.

    nabi
    use spatial::{DAffine2, DVec2};
    
    let a = DAffine2::from_scale_angle_translation(DVec2::splat(2.0), 0.5, DVec2::ONE);
    assert((a * a.inverse()).transform_point(DVec2::X).approx_eq(DVec2::X, 1e-12));
    
  • pub fn approx_eq(self, o: Affine2<T>, eps: T) -> bool§

    Source

    Whether the matrix and translation are within eps of o's.

    nabi
    use spatial::Affine2;
    
    assert(Affine2::identity().approx_eq(Affine2::from_angle(1e-7), 1e-6));
    
Trait implementations 1
  • impl<T: Real> Mul for Affine2<T>

Affine3Source

pub struct Affine3<T = f32>

A 3D affine transform: matrix * p + translation, any mix of rotation, scale, shear and translation without the projective row of a Mat4. #[repr(C)]: the Mat3 then the Vec3, twelve Ts.

nabi
use spatial::{Affine3, Quat, Vec3};

let a = Affine3::from_scale_rotation_translation(Vec3::ONE, Quat::from_rotation_y(f32::PI / 2.0), Vec3::Y);
assert(a.transform_point(Vec3::Z).approx_eq(Vec3::new(1.0, 1.0, 0.0), 1e-6));
  • pub matrix: Mat3<T>§

    Source
  • pub translation: Vec3<T>§

    Source
  • pub const fn new(matrix: Mat3<T>, translation: Vec3<T>) -> Affine3<T>§

    Source

    The transform of a matrix and a translation.

    nabi
    use spatial::{Affine3, Mat3, Vec3};
    
    assert(Affine3::new(Mat3::IDENTITY, Vec3::ZERO) == Affine3::identity());
    
  • pub fn identity() -> Affine3<T>§

    Source

    No change.

    nabi
    use spatial::{Affine3, Vec3};
    
    assert(Affine3::identity().transform_point(Vec3::ONE) == Vec3::ONE);
    
  • pub fn from_translation(t: Vec3<T>) -> Affine3<T>§

    Source

    The translation by t.

    nabi
    use spatial::{Affine3, Vec3};
    
    assert(Affine3::from_translation(Vec3::X).transform_point(Vec3::ZERO) == Vec3::X);
    
  • pub fn from_scale(s: Vec3<T>) -> Affine3<T>§

    Source

    The scale by s.

    nabi
    use spatial::{Affine3, Vec3};
    
    assert(Affine3::from_scale(Vec3::splat(2.0)).transform_point(Vec3::ONE) == Vec3::splat(2.0));
    
  • pub fn from_quat(q: Quat<T>) -> Affine3<T>§

    Source

    The rotation of a unit quaternion.

    nabi
    use spatial::{Affine3, Quat, Vec3};
    
    let q = Quat::from_rotation_z(0.3);
    assert(Affine3::from_quat(q).transform_point(Vec3::X).approx_eq(q * Vec3::X, 1e-6));
    
  • pub fn from_axis_angle(axis: Vec3<T>, angle: T) -> Affine3<T>§

    Source

    The rotation by angle radians about the unit vector axis.

    nabi
    use spatial::{Affine3, Vec3};
    
    let a = Affine3::from_axis_angle(Vec3::Z, f32::PI / 2.0);
    assert(a.transform_point(Vec3::X).approx_eq(Vec3::Y, 1e-6));
    
  • pub fn from_scale_rotation_translation(scale: Vec3<T>, rotation: Quat<T>, translation: Vec3<T>) -> Affine3<T>§

    Source

    Scale, rotate, then move.

    nabi
    use spatial::{Affine3, Quat, Vec3};
    
    let a = Affine3::from_scale_rotation_translation(Vec3::splat(2.0), Quat::IDENTITY, Vec3::X);
    assert(a.transform_point(Vec3::ONE) == Vec3::new(3.0, 2.0, 2.0));
    
  • pub fn from_mat4(m: Mat4<T>) -> Affine3<T>§

    Source

    The affine part of m (its last row ignored).

    nabi
    use spatial::{Affine3, Mat4, Vec3};
    
    assert(Affine3::from_mat4(Mat4::from_translation(Vec3::X)) == Affine3::from_translation(Vec3::X));
    
  • pub fn to_mat4(self) -> Mat4<T>§

    Source

    The same transform as a Mat4.

    nabi
    use spatial::{Affine3, Mat4};
    
    assert(Affine3::<f32>::identity().to_mat4() == Mat4::IDENTITY);
    
  • pub fn transform_point(self, p: Vec3<T>) -> Vec3<T>§

    Source

    The point p transformed.

    nabi
    use spatial::{Affine3, Vec3};
    
    assert(Affine3::from_translation(Vec3::X).transform_point(Vec3::Y) == Vec3::new(1.0, 1.0, 0.0));
    
  • pub fn transform_vector(self, v: Vec3<T>) -> Vec3<T>§

    Source

    The direction v transformed, translation left out.

    nabi
    use spatial::{Affine3, Vec3};
    
    assert(Affine3::from_translation(Vec3::X).transform_vector(Vec3::Y) == Vec3::Y);
    
  • pub fn inverse(self) -> Affine3<T>§

    Source

    The inverse transform. A singular matrix gives infinite or NaN entries.

    nabi
    use spatial::{DAffine3, DQuat, DVec3};
    
    let a = DAffine3::from_scale_rotation_translation(DVec3::splat(2.0), DQuat::from_rotation_x(1.0), DVec3::ONE);
    assert((a.inverse() * a).approx_eq(DAffine3::identity(), 1e-12));
    
  • pub fn approx_eq(self, o: Affine3<T>, eps: T) -> bool§

    Source

    Whether the matrix and translation are within eps of o's.

    nabi
    use spatial::{Affine3, Vec3};
    
    assert(Affine3::identity().approx_eq(Affine3::from_translation(Vec3::splat(1e-7)), 1e-6));
    
Trait implementations 1
  • impl<T: Real> Mul for Affine3<T>

Mat2Source

pub struct Mat2<T = f32>

A 2x2 matrix of two column vectors, for 2D rotation and scale. Mat2 alone is Mat2<f32>. #[repr(C)]: x_axis then y_axis, four Ts column by column.

nabi
use spatial::{Mat2, Vec2};

let m = Mat2::from_cols(Vec2::new(1.0, 2.0), Vec2::new(3.0, 4.0));
assert(m * Vec2::new(1.0, 0.0) == Vec2::new(1.0, 2.0));
assert(m.determinant() == -2.0);
  • pub x_axis: Vec2<T>§

    Source
  • pub y_axis: Vec2<T>§

    Source
  • pub const fn from_cols(x_axis: Vec2<T>, y_axis: Vec2<T>) -> Mat2<T>§

    Source

    The matrix of its columns.

    nabi
    use spatial::{Mat2, Vec2};
    
    assert(Mat2::from_cols(Vec2::X, Vec2::Y) == Mat2::IDENTITY);
    
  • pub fn from_cols_array(a: [T; 4]) -> Mat2<T>§

    Source

    From four values, column by column.

    nabi
    assert(spatial::DMat2::from_cols_array([1.0, 0.0, 0.0, 1.0]) == spatial::DMat2::IDENTITY);
    
  • pub fn to_cols_array(self) -> [T; 4]§

    Source

    The four values column by column, as a GPU reads them.

    nabi
    assert(spatial::Mat2::IDENTITY.to_cols_array() == [1.0, 0.0, 0.0, 1.0]);
    
  • pub fn identity() -> Mat2<T>§

    Source

    The identity.

    nabi
    assert(spatial::Mat2::<f32>::identity() == spatial::Mat2::IDENTITY);
    
  • pub fn zero() -> Mat2<T>§

    Source

    All zero.

    nabi
    assert(spatial::Mat2::<f32>::zero().determinant() == 0.0);
    
  • pub fn from_diagonal(d: Vec2<T>) -> Mat2<T>§

    Source

    The diagonal matrix of d, a scale.

    nabi
    use spatial::{Mat2, Vec2};
    
    assert(Mat2::from_diagonal(Vec2::new(2.0, 3.0)) * Vec2::ONE == Vec2::new(2.0, 3.0));
    
  • pub fn from_angle(angle: T) -> Mat2<T>§

    Source

    The counterclockwise rotation by angle radians.

    nabi
    use spatial::{Mat2, Vec2};
    
    assert((Mat2::from_angle(f32::PI / 2.0) * Vec2::X).approx_eq(Vec2::Y, 1e-6));
    
  • pub fn from_scale_angle(scale: Vec2<T>, angle: T) -> Mat2<T>§

    Source

    Scale by scale, then rotate by angle radians.

    nabi
    use spatial::{Mat2, Vec2};
    
    let m = Mat2::from_scale_angle(Vec2::splat(2.0), f32::PI / 2.0);
    assert((m * Vec2::X).approx_eq(Vec2::new(0.0, 2.0), 1e-6));
    
  • pub fn col(self, i: usize) -> Vec2<T>§

    Source

    Column i (0 or 1).

    nabi
    assert(spatial::Mat2::IDENTITY.col(1) == spatial::Vec2::Y);
    
  • pub fn row(self, i: usize) -> Vec2<T>§

    Source

    Row i (0 or 1).

    nabi
    use spatial::{Mat2, Vec2};
    
    let m = Mat2::from_cols_array([1.0, 2.0, 3.0, 4.0]);
    assert(m.row(0) == Vec2::new(1.0, 3.0));
    
  • pub fn transpose(self) -> Mat2<T>§

    Source

    The transpose.

    nabi
    let m = spatial::Mat2::from_cols_array([1.0, 2.0, 3.0, 4.0]);
    assert(m.transpose().to_cols_array() == [1.0, 3.0, 2.0, 4.0]);
    
  • pub fn determinant(self) -> T§

    Source

    The determinant.

    nabi
    assert(spatial::Mat2::from_cols_array([1.0, 2.0, 3.0, 4.0]).determinant() == -2.0);
    
  • pub fn inverse(self) -> Mat2<T>§

    Source

    The inverse. A singular matrix gives infinite or NaN entries; try_inverse gives none for it instead.

    nabi
    use spatial::DMat2;
    
    let m = DMat2::from_cols_array([1.0, 2.0, 3.0, 4.0]);
    assert((m * m.inverse()).approx_eq(DMat2::IDENTITY, 1e-12));
    
  • pub fn try_inverse(self) -> Mat2<T> | none§

    Source

    The inverse, or none when the determinant is zero or the result is not finite.

    nabi
    assert(spatial::Mat2::<f32>::zero().try_inverse() == none);
    
  • pub fn approx_eq(self, o: Mat2<T>, eps: T) -> bool§

    Source

    Whether every entry is within eps of o's.

    nabi
    use spatial::Mat2;
    
    assert(Mat2::IDENTITY.approx_eq(Mat2::from_angle(1e-7), 1e-6));
    
  • pub fn is_finite(self) -> bool§

    Source

    Whether no entry is NaN or infinite.

    nabi
    assert(spatial::Mat2::IDENTITY.is_finite());
    
Trait implementations 7
  • impl<T: Real> Mul for Mat2<T>
  • impl<T: Real> Mul<Vec2<T>> for Mat2<T>
  • impl<T: Real> Mul<T> for Mat2<T>
  • impl<T: Real> Add for Mat2<T>
  • impl<T: Real> Sub for Mat2<T>
  • impl<T: Real> MulAssign for Mat2<T>
  • impl<T: Real> Display for Mat2<T>

Mat3

pub struct Mat3<T = f32>

31 members, 7 trait implementations →

Mat4

pub struct Mat4<T = f32>

41 members, 7 trait implementations →

Quat

pub struct Quat<T = f32>

32 members, 8 trait implementations →

Transform

pub struct Transform<T = f32>

21 members, 1 trait implementations →

Vec2

pub struct Vec2<T = f32>

48 members, 19 trait implementations →

Vec3

pub struct Vec3<T = f32>

57 members, 19 trait implementations →

Vec3ASource

pub struct Vec3A<T = f32>

A Vec3 stored in 16 bytes, aligned to 16, as a vec3<f32> sits in a WGSL uniform or std140 / std430 buffer: a struct of Vec3As matches the shader's layout with no hand-written padding. Convert with Vec3A::from(v) and .to_vec3(); the arithmetic is Vec3's.

nabi
use spatial::{Vec3, Vec3A};

let a = Vec3A::from(Vec3::new(1.0, 2.0, 3.0));
assert(Vec3A::<f32>::size() == 16 && Vec3A::<f32>::align() == 16);
assert((a + a).to_vec3() == Vec3::new(2.0, 4.0, 6.0));
  • pub x: T§

    Source
  • pub y: T§

    Source
  • pub z: T§

    Source
  • pub const fn new(x: T, y: T, z: T) -> Vec3A<T>§

    Source

    The vector of its components.

    nabi
    assert(spatial::Vec3A::new(1.0, 2.0, 3.0).z == 3.0);
    
  • pub const fn from(v: Vec3<T>) -> Vec3A<T>§

    Source

    The padded form of v.

    nabi
    use spatial::{Vec3, Vec3A};
    
    assert(Vec3A::from(Vec3::<f32>::X).x == 1.0);
    
  • pub const fn to_vec3(self) -> Vec3<T>§

    Source

    The unpadded Vec3.

    nabi
    use spatial::{Vec3, Vec3A};
    
    assert(Vec3A::new(1.0, 2.0, 3.0).to_vec3() == Vec3::new(1.0, 2.0, 3.0));
    
  • pub fn dot(self, o: Vec3A<T>) -> T§

    Source

    The dot product.

    nabi
    assert(spatial::Vec3A::new(1.0, 2.0, 3.0).dot(spatial::Vec3A::new(1.0, 1.0, 1.0)) == 6.0);
    
  • pub fn cross(self, o: Vec3A<T>) -> Vec3A<T>§

    Source

    The cross product, as Vec3::cross.

    nabi
    use spatial::{Vec3, Vec3A};
    
    assert(Vec3A::from(Vec3::<f32>::X).cross(Vec3A::from(Vec3::Y)).to_vec3() == Vec3::Z);
    
  • pub fn length(self) -> T§

    Source

    The length.

    nabi
    assert(spatial::Vec3A::new(3.0, 4.0, 0.0).length() == 5.0);
    
  • pub fn normalize(self) -> Vec3A<T>§

    Source

    The unit vector, as Vec3::normalize.

    nabi
    assert(spatial::Vec3A::new(0.0, 0.0, 2.0).normalize().z == 1.0);
    
Trait implementations 4
  • impl<T: Scalar> Add for Vec3A<T>
  • impl<T: Scalar> Sub for Vec3A<T>
  • impl<T: Scalar> Mul<T> for Vec3A<T>
  • impl<T: Scalar> Display for Vec3A<T>

Vec4

pub struct Vec4<T = f32>

50 members, 19 trait implementations →

Enums

EulerOrderSource

pub enum EulerOrder

The axes of three Euler angles a, b, c, first to last. With XYZ the rotation is R_x(a) * R_y(b) * R_z(c): on a column vector c about z applies first, then b about y, then a about x. Read as moving axes, it is a about x, then b about the turned y, then c about the twice-turned z (intrinsic X-Y'-Z'').

For a y-up, -z-forward camera or character, YXZ is yaw, pitch, roll; for z-up worlds (aircraft, robotics), ZYX is.

nabi
use spatial::{DMat3, EulerOrder};

let m = DMat3::from_euler(EulerOrder::XYZ, 0.1, 0.2, 0.3);
let want = DMat3::from_rotation_x(0.1) * DMat3::from_rotation_y(0.2) * DMat3::from_rotation_z(0.3);
assert(m.approx_eq(want, 1e-12));

Traits

RealSource

pub trait Real: Scalar + FloatingPoint

A float component type, f32 or f64: what lengths, normals, rotations, matrices and shapes take.

nabi
use spatial::{DVec3, Real, Vec3, vec3};

fn unit<T: Real>(v: Vec3<T>) -> Vec3<T> { v.normalize() }

assert(unit(vec3(0.0, 0.0, 2.0)) == Vec3::Z);
assert(unit(DVec3::new(0.0, 3.0, 0.0)) == DVec3::Y);

ScalarSource

pub trait Scalar: Num + SimdElement + Debug + Display

A component type: f32, f64, i32 or u32. The arithmetic of IVec3 and UVec3 is the integer type's, so u32 components that go below zero panic as u32 subtraction does.

nabi
use spatial::{IVec2, Scalar, Vec2};

fn area<T: Scalar>(size: Vec2<T>) -> T { size.x * size.y }

assert(area(IVec2::new(3, 4)) == 12);
assert(area(Vec2::new(1.5, 2.0)) == 3.0);

Type aliases

DAffine2Source

pub type DAffine2 = Affine2<f64>

Affine2<f64>.

nabi
assert(spatial::DAffine2::identity().translation == spatial::DVec2::ZERO);

DAffine3Source

pub type DAffine3 = Affine3<f64>

Affine3<f64>.

nabi
assert(spatial::DAffine3::identity().translation == spatial::DVec3::ZERO);

DMat2Source

pub type DMat2 = Mat2<f64>

Mat2<f64>.

nabi
assert(spatial::DMat2::IDENTITY.determinant() == 1.0);

DMat3Source

pub type DMat3 = Mat3<f64>

Mat3<f64>.

nabi
assert(spatial::DMat3::IDENTITY.determinant() == 1.0);

DMat4Source

pub type DMat4 = Mat4<f64>

Mat4<f64>.

nabi
assert(spatial::DMat4::IDENTITY.determinant() == 1.0);

DQuatSource

pub type DQuat = Quat<f64>

Quat<f64>.

nabi
assert(spatial::DQuat::IDENTITY.w == 1.0);

DTransformSource

pub type DTransform = Transform<f64>

Transform<f64>.

nabi
assert(spatial::DTransform::identity().scale == spatial::DVec3::ONE);

DVec2Source

pub type DVec2 = Vec2<f64>

Vec2<f64>.

nabi
assert(spatial::DVec2::new(1.0, 2.0).length_squared() == 5.0);

DVec3Source

pub type DVec3 = Vec3<f64>

Vec3<f64>.

nabi
assert(spatial::DVec3::X.cross(spatial::DVec3::Y) == spatial::DVec3::Z);

DVec3ASource

pub type DVec3A = Vec3A<f64>

Vec3A<f64>, 32 bytes.

nabi
assert(spatial::DVec3A::size() == 32);

DVec4Source

pub type DVec4 = Vec4<f64>

Vec4<f64>.

nabi
assert(spatial::DVec4::ONE.element_sum() == 4.0);

IVec2Source

pub type IVec2 = Vec2<i32>

Vec2<i32>, a grid position or a pixel size.

nabi
assert(spatial::IVec2::new(3, -4).dot(spatial::IVec2::ONE) == -1);

IVec3Source

pub type IVec3 = Vec3<i32>

Vec3<i32>, a voxel or chunk coordinate.

nabi
assert(spatial::IVec3::new(1, 2, 3) * 2 == spatial::IVec3::new(2, 4, 6));

IVec4Source

pub type IVec4 = Vec4<i32>

Vec4<i32>.

nabi
assert(spatial::IVec4::splat(2).element_product() == 16);

UVec2Source

pub type UVec2 = Vec2<u32>

Vec2<u32>, a texture or window size.

nabi
assert(spatial::UVec2::new(1920, 1080).element_product() == 2073600);

UVec3Source

pub type UVec3 = Vec3<u32>

Vec3<u32>, a compute dispatch size.

nabi
assert(spatial::UVec3::new(8, 8, 1).element_product() == 64);

UVec4Source

pub type UVec4 = Vec4<u32>

Vec4<u32>, an RGBA8 colour widened, or four indices.

nabi
assert(spatial::UVec4::splat(255).max_element() == 255);

Functions

dvec2Source

pub const fn dvec2(x: f64, y: f64) -> DVec2

DVec2::new(x, y) with f64 components, whatever the literals.

nabi
use spatial::{DVec2, dvec2};

assert(dvec2(1.0, 2.0) == DVec2::new(1.0, 2.0));

dvec3Source

pub const fn dvec3(x: f64, y: f64, z: f64) -> DVec3

DVec3::new(x, y, z) with f64 components, whatever the literals.

nabi
use spatial::{DVec3, dvec3};

assert(dvec3(1.0, 2.0, 3.0) == DVec3::new(1.0, 2.0, 3.0));

dvec4Source

pub const fn dvec4(x: f64, y: f64, z: f64, w: f64) -> DVec4

DVec4::new(x, y, z, w) with f64 components, whatever the literals.

nabi
use spatial::{DVec4, dvec4};

assert(dvec4(1.0, 2.0, 3.0, 4.0) == DVec4::new(1.0, 2.0, 3.0, 4.0));

ivec2Source

pub const fn ivec2(x: i32, y: i32) -> IVec2

IVec2::new(x, y) with i32 components, whatever the literals.

nabi
use spatial::{IVec2, ivec2};

assert(ivec2(1, -2) == IVec2::new(1, -2));

ivec3Source

pub const fn ivec3(x: i32, y: i32, z: i32) -> IVec3

IVec3::new(x, y, z) with i32 components, whatever the literals.

nabi
use spatial::{IVec3, ivec3};

assert(ivec3(1, -2, 3) == IVec3::new(1, -2, 3));

ivec4Source

pub const fn ivec4(x: i32, y: i32, z: i32, w: i32) -> IVec4

IVec4::new(x, y, z, w) with i32 components, whatever the literals.

nabi
use spatial::{IVec4, ivec4};

assert(ivec4(1, -2, 3, 4) == IVec4::new(1, -2, 3, 4));

uvec2Source

pub const fn uvec2(x: u32, y: u32) -> UVec2

UVec2::new(x, y) with u32 components, whatever the literals.

nabi
use spatial::{UVec2, uvec2};

assert(uvec2(1, 2) == UVec2::new(1, 2));

uvec3Source

pub const fn uvec3(x: u32, y: u32, z: u32) -> UVec3

UVec3::new(x, y, z) with u32 components, whatever the literals.

nabi
use spatial::{UVec3, uvec3};

assert(uvec3(1, 2, 3) == UVec3::new(1, 2, 3));

uvec4Source

pub const fn uvec4(x: u32, y: u32, z: u32, w: u32) -> UVec4

UVec4::new(x, y, z, w) with u32 components, whatever the literals.

nabi
use spatial::{UVec4, uvec4};

assert(uvec4(1, 2, 3, 4) == UVec4::new(1, 2, 3, 4));

vec2Source

pub const fn vec2(x: f32, y: f32) -> Vec2

Vec2::new(x, y) with f32 components, whatever the literals.

nabi
use spatial::{Vec2, vec2};

assert(vec2(1.0, 2.0) == Vec2::<f32>::new(1.0, 2.0));

vec3Source

pub const fn vec3(x: f32, y: f32, z: f32) -> Vec3

Vec3::new(x, y, z) with f32 components, whatever the literals.

nabi
use spatial::{Vec3, vec3};

assert(vec3(1.0, 2.0, 3.0) == Vec3::<f32>::new(1.0, 2.0, 3.0));

vec4Source

pub const fn vec4(x: f32, y: f32, z: f32, w: f32) -> Vec4

Vec4::new(x, y, z, w) with f32 components, whatever the literals.

nabi
use spatial::{Vec4, vec4};

assert(vec4(1.0, 2.0, 3.0, 4.0) == Vec4::<f32>::new(1.0, 2.0, 3.0, 4.0));