Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Upgrade to edition 2024
- Minor implementation updates
- Minor documentation fixes
- Added `encase` feature, providing `encase` trait implementations for `ultraviolet` types.

## 0.10.0

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde = { version = "1.0", features = [], optional = true }
mint = { version = "0.5", optional = true }
bytemuck = { version = "1.22", optional = true }
num-traits = { version = "0.2", optional = true }
encase = { version = "0.12", optional = true }

[features]
default = ["int"]
Expand All @@ -28,6 +29,7 @@ serde = ["dep:serde"]
mint = ["dep:mint"]
bytemuck = ["dep:bytemuck"]
num-traits = ["dep:num-traits"]
encase = ["dep:encase"]

[dev-dependencies]
serde_test = "1.0"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Here's a list of the available features:
* `mint` – Enable interoperation with other math crates through the `mint` interface.
* `num-traits` – Enable [identity traits](https://docs.rs/num-traits/latest/num_traits/identities/index.html) for interoperation with other math crates.
* `serde` – Enable `Serialize` and `Deserialize` implementations for many scalar types.
* `encase` – Enable `encase` trait implementations for `ultraviolet` types.

## Crate Features

Expand Down
75 changes: 75 additions & 0 deletions src/impl_encase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::{IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, UVec2, UVec3, UVec4, Vec2, Vec3, Vec4};
use encase::{
matrix::{AsMutMatrixParts, AsRefMatrixParts, impl_matrix},
vector::{AsMutVectorParts, AsRefVectorParts, impl_vector},
};

impl_vector!(2, Vec2, f32; using From);
impl_vector!(2, UVec2, u32; using From);
impl_vector!(2, IVec2, i32; using From);

impl_vector!(3, Vec3, f32; using From);
impl_vector!(3, UVec3, u32; using From);
impl_vector!(3, IVec3, i32; using From);

impl_vector!(4, Vec4, f32; using From);
impl_vector!(4, UVec4, u32; using From);
impl_vector!(4, IVec4, i32; using From);

impl_matrix!(2, 2, Mat2, f32; using From);
impl_matrix!(3, 3, Mat3, f32; using From);
impl_matrix!(4, 4, Mat4, f32; using From);

macro_rules! impl_vector_traits {
($n:literal, $type:ty, $el_ty:ty) => {
impl AsRefVectorParts<$el_ty, $n> for $type {
fn as_ref_parts(&self) -> &[$el_ty; $n] {
self.as_slice().try_into().unwrap()
}
}
impl AsMutVectorParts<$el_ty, $n> for $type {
fn as_mut_parts(&mut self) -> &mut [$el_ty; $n] {
self.as_mut_slice().try_into().unwrap()
}
}
};
}

impl_vector_traits!(2, Vec2, f32);
impl_vector_traits!(2, UVec2, u32);
impl_vector_traits!(2, IVec2, i32);

impl_vector_traits!(3, Vec3, f32);
impl_vector_traits!(3, UVec3, u32);
impl_vector_traits!(3, IVec3, i32);

impl_vector_traits!(4, Vec4, f32);
impl_vector_traits!(4, UVec4, u32);
impl_vector_traits!(4, IVec4, i32);

macro_rules! impl_matrix_traits {
($c:literal, $r:literal, $type:ty, $el_ty:ty) => {
impl AsRefMatrixParts<$el_ty, $c, $r> for $type {
fn as_ref_parts(&self) -> &[[$el_ty; $r]; $c] {
unsafe {
::core::mem::transmute::<&[$el_ty; $r * $c], &[[$el_ty; $r]; $c]>(
self.as_array(),
)
}
}
}
impl AsMutMatrixParts<$el_ty, $c, $r> for $type {
fn as_mut_parts(&mut self) -> &mut [[$el_ty; $r]; $c] {
unsafe {
::core::mem::transmute::<&mut [$el_ty; $r * $c], &mut [[$el_ty; $r]; $c]>(
self.as_mut_array(),
)
}
}
}
};
}

impl_matrix_traits!(2, 2, Mat2, f32);
impl_matrix_traits!(3, 3, Mat3, f32);
impl_matrix_traits!(4, 4, Mat4, f32);
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
//! * `mint` – Enable interoperation with other math crates through the `mint` interface.
//! * `num-traits` – Enable [identity traits](https://docs.rs/num-traits/latest/num_traits/identities/index.html) for interoperation with other math crates.
//! * `serde` – Enable `Serialize` and `Deserialize` implementations for many scalar types.
//! * `encase` – Enable `encase` trait implementations for `ultraviolet` types.
//!
//! ## Crate Features
//!
Expand Down Expand Up @@ -110,6 +111,9 @@ mod impl_mint;
#[cfg(feature = "bytemuck")]
mod impl_bytemuck;

#[cfg(feature = "encase")]
mod impl_encase;

pub use bivec::*;
#[cfg(feature = "int")]
pub use conversion::*;
Expand Down