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::{bool32x4, f32x4, i32x4, u32x4, Num};
use crate::{
    Mat3, Mat3x4, Quat, Quatx4, UnitQuat, UnitQuatx4, UnitVec3, UnitVec3x4, Vec2, Vec2x4, Vec3,
    Vec3x4,
};

pub trait ExtratLaneExternal {
    type Output;
    fn extract_lane_ext(&self, i: usize) -> Self::Output;
    #[inline]
    fn first_lane(&self) -> Self::Output {
        self.extract_lane_ext(0)
    }
}

impl<T, const SIZE: usize> ExtratLaneExternal for [T; SIZE]
where
    T: ExtratLaneExternal,
    <T as ExtratLaneExternal>::Output: Default + Copy,
{
    type Output = [<T as ExtratLaneExternal>::Output; SIZE];

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        let mut result: [<T as ExtratLaneExternal>::Output; SIZE] = [Default::default(); SIZE];
        for j in 0..SIZE {
            result[j] = self[j].extract_lane_ext(i);
        }
        result
    }
}

impl ExtratLaneExternal for Vec3x4 {
    type Output = Vec3;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        self.extract_lane(i)
    }
}
impl ExtratLaneExternal for UnitVec3x4 {
    type Output = UnitVec3;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        self.extract_lane(i)
    }
}

impl ExtratLaneExternal for f32x4 {
    type Output = f32;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        <f32x4 as Num>::extract(self, i)
    }
}
impl ExtratLaneExternal for i32x4 {
    type Output = i32;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        <i32x4 as Num>::extract(self, i)
    }
}
impl ExtratLaneExternal for u32x4 {
    type Output = u32;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        <u32x4 as Num>::extract(self, i)
    }
}
impl ExtratLaneExternal for bool32x4 {
    type Output = bool;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        <bool32x4 as Num>::extract(self, i)
    }
}
impl ExtratLaneExternal for UnitQuatx4 {
    type Output = UnitQuat;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        self.extract_lane(i)
    }
}
impl ExtratLaneExternal for Quatx4 {
    type Output = Quat;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        self.extract_lane(i)
    }
}

impl ExtratLaneExternal for Vec2x4 {
    type Output = Vec2;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        self.extract_lane(i)
    }
}
impl ExtratLaneExternal for Mat3x4 {
    type Output = Mat3;

    #[inline]
    fn extract_lane_ext(&self, i: usize) -> Self::Output {
        self.extract_lane(i)
    }
}