glam_det 2.0.0

A simple and fast 3D math library for games and graphics.
Documentation
// Copyright (C) 2020-2025 glam-det authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::nums::{f32x4, i32x4, u32x4};
use crate::*;
use bytemuck::{Pod, Zeroable};

macro_rules! impl_pod_and_zeroable {
    ( $( $t: ty ),* ) => {
        $(
            unsafe impl Pod for $t {}
            unsafe impl Zeroable for $t {}
        )*
    };
}

impl_pod_and_zeroable!(
    f32x4,
    u32x4,
    i32x4,
    Vec2,
    Vec3,
    Vec3A,
    Vec4,
    Vec2x4,
    Vec3x4,
    Vec4x4,
    DVec2,
    DVec3,
    DVec4,
    UnitVec2,
    UnitVec3,
    UnitVec3A,
    UnitVec4,
    UnitDVec2,
    UnitDVec3,
    UnitDVec4,
    UnitVec2x4,
    UnitVec3x4,
    UnitVec4x4,
    IVec2,
    IVec3,
    IVec4,
    UVec2,
    UVec3,
    UVec4,
    Point2,
    Point3,
    Point3A,
    Point4,
    DPoint2,
    DPoint3,
    DPoint4,
    Point2x4,
    Point3x4,
    Point4x4,
    IPoint2,
    IPoint3,
    IPoint4,
    UPoint2,
    UPoint3,
    UPoint4,
    Quat,
    UnitQuat,
    DQuat,
    UnitDQuat,
    Quatx4,
    UnitQuatx4,
    Mat2,
    Mat3,
    Mat3A,
    Mat4,
    DMat2,
    DMat3,
    DMat4,
    Mat2x4,
    Mat3x4,
    Mat4x4,
    Isometry3x4
);

#[cfg(test)]
mod test {
    use super::*;
    use core::mem;

    macro_rules! test_t {
        ($name:ident, $t:ty) => {
            #[test]
            fn $name() {
                let t = <$t>::default();
                let b = bytemuck::bytes_of(&t);
                assert_eq!(t.as_ref().as_ptr() as usize, b.as_ptr() as usize);
                assert_eq!(b.len(), mem::size_of_val(&t));
            }
        };
    }

    macro_rules! test_all {
        ( $($name:ident => $t:ty),* ) => {
            $(
                test_t!($name, $t);
            )*
        };
    }

    test_all!(
        f32x4 => f32x4,
        u32x4 => u32x4,
        i32x4 => i32x4,
        vec2 => Vec2,
        vec3 => Vec3,
        vec3a => Vec3A,
        vec4 => Vec4,
        vec2x4 => Vec2x4,
        vec3x4 => Vec3x4,
        vec4x4 => Vec4x4,
        dvec2 => DVec2,
        dvec3 => DVec3,
        dvec4 => DVec4,
        unit_vec2 => UnitVec2,
        unit_vec3 => UnitVec3,
        unit_vec3a => UnitVec3A,
        unit_vec4 => UnitVec4,
        unit_dvec2 => UnitDVec2,
        unit_dvec3 => UnitDVec3,
        unit_dvec4 => UnitDVec4,
        unit_vec2x4 => UnitVec2x4,
        unit_vec3x4 => UnitVec3x4,
        unit_vec4x4 => UnitVec4x4,
        ivec2 => IVec2,
        ivec3 => IVec3,
        ivec4 => IVec4,
        uvec2 => UVec2,
        uvec3 => UVec3,
        uvec4 => UVec4,
        point2 => Point2,
        point3 => Point3,
        point3a => Point3A,
        point4 => Point4,
        dpoint2 => DPoint2,
        dpoint3 => DPoint3,
        dpoint4 => DPoint4,
        point2x4 => Point2x4,
        point3x4 => Point3x4,
        point4x4 => Point4x4,
        ipoint2 => IPoint2,
        ipoint3 => IPoint3,
        ipoint4 => IPoint4,
        upoint2 => UPoint2,
        upoint3 => UPoint3,
        upoint4 => UPoint4,
        quat => Quat,
        unit_quat => UnitQuat,
        dquat => DQuat,
        unit_dquat => UnitDQuat,
        quatx4 => Quatx4,
        unit_quatx4 => UnitQuatx4,
        mat2 => Mat2,
        mat3 => Mat3,
        mat4 => Mat4,
        dmat2 => DMat2,
        dmat3 => DMat3,
        dmat4 => DMat4,
        mat2x4 => Mat2x4,
        mat3x4 => Mat3x4,
        mat4x4 => Mat4x4
    );
}