1 个不稳定版本

0.1.0 2024 年 5 月 16 日

#1 in #col

Download history 148/week @ 2024-05-12 56/week @ 2024-05-19 32/week @ 2024-05-26 28/week @ 2024-06-02 18/week @ 2024-06-09 20/week @ 2024-06-16 13/week @ 2024-06-23 3/week @ 2024-06-30 12/week @ 2024-07-07 28/week @ 2024-07-14 15/week @ 2024-07-21 20/week @ 2024-07-28 14/week @ 2024-08-04 8/week @ 2024-08-11

每月 60 次下载
7 包中使用 7 (2 直接)

MIT/Apache

25KB
751

F3l Glam

一个改进的包,用于获取和设置 glam 类型。
因为 glam 是基于列的,它提供了一些特性,可以快速获取 行信息

F3lMatrix

用于从矩阵获取行向量。

/// A trait of matrix for glam type
pub trait F3lMatrix {
    type RowType: Copy;

    // getter
    fn cols(&self) -> usize;
    fn rows(&self) -> usize;
    fn row(&self, r: usize) -> Self::RowType;
    /// get value with bound check
    fn get(&self, r: usize, c: usize) -> Option<f32>;
    fn at(&self, r: usize, c: usize) -> f32 {
        self.get(r, c).unwrap()
    }

    // setter
    fn set_row<R: Into<Self::RowType> + Copy>(&mut self, row: usize, v: R);
    /// pos: (row, col)
    fn set_element(&mut self, pos: (usize, usize), v: f32);
}

ArrayRowMajor

用于获取行数据和行矩阵。

/// A trait of from/to for glam types
pub trait ArrayRowMajor {
    type Row: Copy;
    type Mat: Copy;

    fn from_rows<R: Index<usize, Output = f32>>(rows: &[R]) -> Self;
    fn from_rows_slice(m: &[f32]) -> Self;
    fn to_rows_array(&self) -> Self::Row;
    fn from_cols_array_2d(m: &Self::Mat) -> Self;
    fn to_rows_array_2d(&self) -> Self::Mat;
    fn write_rows_to_slice(self, slice: &mut [f32]);
}

/// A dimension getter
pub trait ArrayDimensions {
    fn nb_cols() -> usize;
    fn nb_rows() -> usize;
}

更多实现

见每个文件。

pub mod mat2;
pub mod mat3;
pub mod mat3a;
pub mod mat4;
pub mod vec2;
pub mod vec3;
pub mod vec3a;
pub mod vec4;

依赖

~3.5MB
~99K SLoC