diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1166511..0bfadd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,6 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: "1.87" + toolchain: "1.89" - uses: Swatinem/rust-cache@v2 - run: cargo check --all-features diff --git a/Cargo.toml b/Cargo.toml index 25a36a3..378286a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ license = "MIT OR Apache-2.0" edition = "2021" [features] -default = ["std"] +default = ["std", "all-types"] # Standard library support std = ["glam/std", "simba/std", "approx?/std"] @@ -60,16 +60,47 @@ rand = ["glam/rand"] encase = ["glam/encase"] +# Type-gating features (mirror glam 0.33). Enabling any of these transitively +# enables the matching glam feature so the corresponding type aliases become +# available. glamx only adds extensions for floating-point types, so the +# integer-/size-type features are pure passthroughs. +all-types = ["float-types", "integer-types", "size-types", "glam/all-types"] +float-types = ["f64", "glam/float-types"] +integer-types = [ + "i8", + "u8", + "i16", + "u16", + "i32", + "u32", + "i64", + "u64", + "glam/integer-types", +] +size-types = ["isize", "usize", "glam/size-types"] + +f64 = ["glam/f64"] +i8 = ["glam/i8"] +u8 = ["glam/u8"] +i16 = ["glam/i16"] +u16 = ["glam/u16"] +i32 = ["glam/i32"] +u32 = ["glam/u32"] +i64 = ["glam/i64"] +u64 = ["glam/u64"] +isize = ["glam/isize"] +usize = ["glam/usize"] + [dependencies] -glam = { version = "0.32", default-features = false } -simba = { version = "0.9", default-features = false } +glam = { version = "0.33", default-features = false } +simba = { version = "0.10", default-features = false } num-traits = { version = "0.2", default-features = false, features = ["libm"] } approx = { version = "0.5", default-features = false, optional = true } serde = { version = "1.0", optional = true, features = ["derive"] } bytemuck = { version = "1", features = ["derive"], optional = true } -nalgebra = { version = "0.34", default-features = false, features = ["convert-glam032"], optional = true } +nalgebra = { version = "0.35", default-features = false, features = ["convert-glam033"], optional = true } rkyv = { version = "0.8", optional = true, default-features = false } [dev-dependencies] approx = "0.5" -glam = { version = "0.32", features = ["approx"] } +glam = { version = "0.33", features = ["approx"] } diff --git a/README.md b/README.md index 071ef65..a02d79a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ This crate re-exports all of glam's types, so you can use it as a drop-in replac | Feature | Description | |-----------------|----------------------------------------| | `std` (default) | Enables standard library support | +| `f64` (default via `all-types`) | Enables `f64` glam types and the corresponding glamx `D*` types (`DRot2`, `DPose2`, `DSymmetricEigen2`, ...) | | `serde` | Enables serialization via serde | | `bytemuck` | Enables bytemuck derives for `Rot2`/`DRot2` | | `nalgebra` | Enables conversions to/from nalgebra types | @@ -34,6 +35,8 @@ This crate re-exports all of glam's types, so you can use it as a drop-in replac | `mint` | Enables mint type conversions | | `encase` | Enables encase encoding | +All of glam's other type-gating features (`all-types`, `float-types`, `integer-types`, `size-types`, `i8`/`u8`/`i16`/`u16`/`i32`/`u32`/`i64`/`u64`/`isize`/`usize`) are also exposed as passthroughs to glam. + ## `no_std` Support `glamx` is `no_std` compatible. Disable default features and enable `libm` for math operations: diff --git a/src/eigen2.rs b/src/eigen2.rs index ef119cf..33db170 100644 --- a/src/eigen2.rs +++ b/src/eigen2.rs @@ -75,9 +75,11 @@ macro_rules! impl_symmetric_eigen2 { } impl_symmetric_eigen2!(SymmetricEigen2, glam::Mat2, glam::Vec2, f32); +#[cfg(feature = "f64")] impl_symmetric_eigen2!(DSymmetricEigen2, glam::DMat2, glam::DVec2, f64); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DSymmetricEigen2 { #[inline] fn from(e: SymmetricEigen2) -> Self { @@ -88,6 +90,7 @@ impl From for DSymmetricEigen2 { } } +#[cfg(feature = "f64")] impl From for SymmetricEigen2 { #[inline] fn from(e: DSymmetricEigen2) -> Self { @@ -123,6 +126,7 @@ mod tests { ); } + #[cfg(feature = "f64")] #[test] fn eigen_2x2_f64() { let mat = glam::DMat2::from_cols_array_2d(&[[6.0, 3.0], [3.0, 4.0]]); diff --git a/src/eigen3.rs b/src/eigen3.rs index 0467ed0..678e66a 100644 --- a/src/eigen3.rs +++ b/src/eigen3.rs @@ -243,9 +243,11 @@ macro_rules! impl_symmetric_eigen3 { impl_symmetric_eigen3!(SymmetricEigen3, glam::Mat3, glam::Vec3, f32); impl_symmetric_eigen3!(SymmetricEigen3A, glam::Mat3A, glam::Vec3A, f32); +#[cfg(feature = "f64")] impl_symmetric_eigen3!(DSymmetricEigen3, glam::DMat3, glam::DVec3, f64); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DSymmetricEigen3 { #[inline] fn from(e: SymmetricEigen3) -> Self { @@ -256,6 +258,7 @@ impl From for DSymmetricEigen3 { } } +#[cfg(feature = "f64")] impl From for SymmetricEigen3 { #[inline] fn from(e: DSymmetricEigen3) -> Self { @@ -266,6 +269,7 @@ impl From for SymmetricEigen3 { } } +#[cfg(feature = "f64")] impl From for DSymmetricEigen3 { #[inline] fn from(e: SymmetricEigen3A) -> Self { @@ -276,6 +280,7 @@ impl From for DSymmetricEigen3 { } } +#[cfg(feature = "f64")] impl From for SymmetricEigen3A { #[inline] fn from(e: DSymmetricEigen3) -> Self { @@ -355,6 +360,7 @@ mod tests { ); } + #[cfg(feature = "f64")] #[test] fn eigen_3x3_f64() { let mat = diff --git a/src/lib.rs b/src/lib.rs index 63090b7..2d5b0db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,20 @@ //! - `nalgebra`: Enables conversions to/from nalgebra types //! - `libm`: Uses libm for no_std math operations //! +//! ### Type-gating features (mirror glam 0.33) +//! +//! These transitively enable the matching feature on `glam`. They control which +//! type aliases the underlying `glam` re-export exposes; glamx adds extension +//! types only for the floating-point variants, so disabling `f64` also removes +//! all `D*` types (DRot2, DPose2, DSymmetricEigen2, ...). +//! +//! - `all-types` (default): enables `float-types`, `integer-types`, `size-types`. +//! - `float-types`: enables `f64`. +//! - `integer-types`: enables `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`. +//! - `size-types`: enables `isize`, `usize`. +//! - Individual features: `f64`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, +//! `u64`, `isize`, `usize`. +//! //! ## glam Re-exports //! //! This crate re-exports all of glam's types so you can use it as a drop-in replacement without @@ -52,28 +66,60 @@ mod rot3; mod svd2; mod svd3; -pub use eigen2::{DSymmetricEigen2, SymmetricEigen2}; -pub use eigen3::{DSymmetricEigen3, SymmetricEigen3, SymmetricEigen3A}; +#[cfg(feature = "f64")] +pub use eigen2::DSymmetricEigen2; +pub use eigen2::SymmetricEigen2; +#[cfg(feature = "f64")] +pub use eigen3::DSymmetricEigen3; +pub use eigen3::{SymmetricEigen3, SymmetricEigen3A}; pub use glam::*; pub use matrix_ext::MatExt; -pub use pose2::{DPose2, Pose2}; -pub use pose3::{DPose3, Pose3, Pose3A}; -pub use rot2::{DRot2, Rot2}; -pub use rot3::{DRot3, Rot3}; -pub use svd2::{DSvd2, Svd2}; -pub use svd3::{DSvd3, Svd3, Svd3A}; +#[cfg(feature = "f64")] +pub use pose2::DPose2; +pub use pose2::Pose2; +#[cfg(feature = "f64")] +pub use pose3::DPose3; +pub use pose3::{Pose3, Pose3A}; +#[cfg(feature = "f64")] +pub use rot2::DRot2; +pub use rot2::Rot2; +#[cfg(feature = "f64")] +pub use rot3::DRot3; +pub use rot3::Rot3; +#[cfg(feature = "f64")] +pub use svd2::DSvd2; +pub use svd2::Svd2; +#[cfg(feature = "f64")] +pub use svd3::DSvd3; +pub use svd3::{Svd3, Svd3A}; /// Prelude module for convenient imports. /// /// This module re-exports all public types and traits. pub mod prelude { - pub use crate::eigen2::{DSymmetricEigen2, SymmetricEigen2}; - pub use crate::eigen3::{DSymmetricEigen3, SymmetricEigen3, SymmetricEigen3A}; + #[cfg(feature = "f64")] + pub use crate::eigen2::DSymmetricEigen2; + pub use crate::eigen2::SymmetricEigen2; + #[cfg(feature = "f64")] + pub use crate::eigen3::DSymmetricEigen3; + pub use crate::eigen3::{SymmetricEigen3, SymmetricEigen3A}; pub use crate::matrix_ext::MatExt; - pub use crate::pose2::{DPose2, Pose2}; - pub use crate::pose3::{DPose3, Pose3}; - pub use crate::rot2::{DRot2, Rot2}; - pub use crate::rot3::{DRot3, Rot3}; - pub use crate::svd2::{DSvd2, Svd2}; - pub use crate::svd3::{DSvd3, Svd3, Svd3A}; + #[cfg(feature = "f64")] + pub use crate::pose2::DPose2; + pub use crate::pose2::Pose2; + #[cfg(feature = "f64")] + pub use crate::pose3::DPose3; + pub use crate::pose3::Pose3; + #[cfg(feature = "f64")] + pub use crate::rot2::DRot2; + pub use crate::rot2::Rot2; + #[cfg(feature = "f64")] + pub use crate::rot3::DRot3; + pub use crate::rot3::Rot3; + #[cfg(feature = "f64")] + pub use crate::svd2::DSvd2; + pub use crate::svd2::Svd2; + #[cfg(feature = "f64")] + pub use crate::svd3::DSvd3; + pub use crate::svd3::{Svd3, Svd3A}; } diff --git a/src/matrix_ext.rs b/src/matrix_ext.rs index cd17dac..8a87299 100644 --- a/src/matrix_ext.rs +++ b/src/matrix_ext.rs @@ -1,9 +1,17 @@ //! Matrix extension traits for glam types. -use crate::eigen2::{DSymmetricEigen2, SymmetricEigen2}; -use crate::eigen3::{DSymmetricEigen3, SymmetricEigen3, SymmetricEigen3A}; -use crate::svd2::{DSvd2, Svd2}; -use crate::svd3::{DSvd3, Svd3, Svd3A}; +#[cfg(feature = "f64")] +use crate::eigen2::DSymmetricEigen2; +use crate::eigen2::SymmetricEigen2; +#[cfg(feature = "f64")] +use crate::eigen3::DSymmetricEigen3; +use crate::eigen3::{SymmetricEigen3, SymmetricEigen3A}; +#[cfg(feature = "f64")] +use crate::svd2::DSvd2; +use crate::svd2::Svd2; +#[cfg(feature = "f64")] +use crate::svd3::DSvd3; +use crate::svd3::{Svd3, Svd3A}; /// Extension trait for square matrix types. /// @@ -168,9 +176,11 @@ macro_rules! impl_mat3_ext { } impl_mat2_ext!(glam::Mat2, glam::Vec2, f32, SymmetricEigen2, Svd2); +#[cfg(feature = "f64")] impl_mat2_ext!(glam::DMat2, glam::DVec2, f64, DSymmetricEigen2, DSvd2); impl_mat3_ext!(glam::Mat3, glam::Vec3, f32, SymmetricEigen3, Svd3); impl_mat3_ext!(glam::Mat3A, glam::Vec3A, f32, SymmetricEigen3A, Svd3A); +#[cfg(feature = "f64")] impl_mat3_ext!(glam::DMat3, glam::DVec3, f64, DSymmetricEigen3, DSvd3); #[cfg(test)] @@ -222,6 +232,7 @@ mod tests { assert_eq!(m.z_axis, glam::Vec3::new(1.0, 2.0, 3.0)); } + #[cfg(feature = "f64")] #[test] fn test_dmat2_abs() { let m = glam::DMat2::from_cols(glam::DVec2::new(-1.0, 2.0), glam::DVec2::new(3.0, -4.0)); diff --git a/src/pose2.rs b/src/pose2.rs index 7fa86fa..0c8c461 100644 --- a/src/pose2.rs +++ b/src/pose2.rs @@ -1,6 +1,8 @@ //! 2D pose types for rigid body transformations. -use crate::rot2::{DRot2, Rot2}; +#[cfg(feature = "f64")] +use crate::rot2::DRot2; +use crate::rot2::Rot2; use core::ops::{Mul, MulAssign}; /// Macro to generate a 2D pose type for a specific scalar type. @@ -356,6 +358,7 @@ impl_pose2!( glam::Mat3, #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] ); +#[cfg(feature = "f64")] impl_pose2!( DPose2, DRot2, @@ -367,6 +370,7 @@ impl_pose2!( ); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DPose2 { #[inline] fn from(p: Pose2) -> Self { @@ -377,6 +381,7 @@ impl From for DPose2 { } } +#[cfg(feature = "f64")] impl From for Pose2 { #[inline] fn from(p: DPose2) -> Self { @@ -410,6 +415,7 @@ mod nalgebra_conv { } } + #[cfg(feature = "f64")] impl From for nalgebra::Isometry2 { fn from(p: DPose2) -> Self { nalgebra::Isometry2 { @@ -419,6 +425,7 @@ mod nalgebra_conv { } } + #[cfg(feature = "f64")] impl From> for DPose2 { fn from(iso: nalgebra::Isometry2) -> Self { Self { @@ -505,6 +512,7 @@ mod tests { assert_relative_eq!(p.translation.y, p2.translation.y, epsilon = 1e-6); } + #[cfg(feature = "f64")] #[test] fn test_dpose2_new() { let p = DPose2::new(glam::DVec2::new(1.0, 2.0), core::f64::consts::PI / 4.0); diff --git a/src/pose3.rs b/src/pose3.rs index 89ba212..bd1b684 100644 --- a/src/pose3.rs +++ b/src/pose3.rs @@ -1,6 +1,8 @@ //! 3D pose types for rigid body transformations. -use crate::rot3::{DRot3, Rot3}; +#[cfg(feature = "f64")] +use crate::rot3::DRot3; +use crate::rot3::Rot3; use core::ops::{Mul, MulAssign}; /// Macro to generate a 3D pose type for a specific scalar type. @@ -413,9 +415,11 @@ macro_rules! impl_pose3 { impl_pose3!(Pose3, Rot3, f32, glam::Vec3, glam::Mat4, u32, bytemuck); impl_pose3!(Pose3A, Rot3, f32, glam::Vec3A, glam::Mat4); +#[cfg(feature = "f64")] impl_pose3!(DPose3, DRot3, f64, glam::DVec3, glam::DMat4); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DPose3 { #[inline] fn from(p: Pose3) -> Self { @@ -426,6 +430,7 @@ impl From for DPose3 { } } +#[cfg(feature = "f64")] impl From for Pose3 { #[inline] fn from(p: DPose3) -> Self { @@ -437,6 +442,7 @@ impl From for Pose3 { } } +#[cfg(feature = "f64")] impl From for DPose3 { #[inline] fn from(p: Pose3A) -> Self { @@ -447,6 +453,7 @@ impl From for DPose3 { } } +#[cfg(feature = "f64")] impl From for Pose3A { #[inline] fn from(p: DPose3) -> Self { @@ -512,6 +519,7 @@ mod nalgebra_conv { } } + #[cfg(feature = "f64")] impl From for nalgebra::Isometry3 { fn from(p: DPose3) -> Self { nalgebra::Isometry3 { @@ -521,6 +529,7 @@ mod nalgebra_conv { } } + #[cfg(feature = "f64")] impl From> for DPose3 { fn from(iso: nalgebra::Isometry3) -> Self { Self { @@ -617,6 +626,7 @@ mod tests { assert_relative_eq!(p.translation.z, p2.translation.z, epsilon = 1e-6); } + #[cfg(feature = "f64")] #[test] fn test_dpose3_new() { let axisangle = glam::DVec3::new(0.1, 0.2, 0.3); diff --git a/src/rot2.rs b/src/rot2.rs index 2923722..cd58076 100644 --- a/src/rot2.rs +++ b/src/rot2.rs @@ -363,9 +363,11 @@ macro_rules! impl_rot2 { } impl_rot2!(Rot2, f32, glam::Vec2, glam::Mat2); +#[cfg(feature = "f64")] impl_rot2!(DRot2, f64, glam::DVec2, glam::DMat2); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DRot2 { #[inline] fn from(r: Rot2) -> Self { @@ -376,6 +378,7 @@ impl From for DRot2 { } } +#[cfg(feature = "f64")] impl From for Rot2 { #[inline] fn from(r: DRot2) -> Self { @@ -403,12 +406,14 @@ mod nalgebra_conv { } } + #[cfg(feature = "f64")] impl From for nalgebra::UnitComplex { fn from(r: DRot2) -> Self { nalgebra::UnitComplex::from_cos_sin_unchecked(r.re, r.im) } } + #[cfg(feature = "f64")] impl From> for DRot2 { fn from(r: nalgebra::UnitComplex) -> Self { Self { re: r.re, im: r.im } @@ -499,6 +504,7 @@ mod tests { assert_relative_eq!(r1.angle_between(&r2), PI / 2.0, epsilon = 1e-6); } + #[cfg(feature = "f64")] #[test] fn test_drot2_new() { let r = DRot2::new(core::f64::consts::PI / 2.0); diff --git a/src/rot3.rs b/src/rot3.rs index 63bdd1f..0d82923 100644 --- a/src/rot3.rs +++ b/src/rot3.rs @@ -11,4 +11,5 @@ pub type Rot3 = glam::Quat; /// A 3D rotation represented as a unit quaternion (f64 precision). /// /// This is a direct re-export of `glam::DQuat`. +#[cfg(feature = "f64")] pub type DRot3 = glam::DQuat; diff --git a/src/svd2.rs b/src/svd2.rs index 21924cd..13be296 100644 --- a/src/svd2.rs +++ b/src/svd2.rs @@ -88,9 +88,11 @@ macro_rules! impl_svd2 { } impl_svd2!(Svd2, glam::Mat2, glam::Vec2, f32); +#[cfg(feature = "f64")] impl_svd2!(DSvd2, glam::DMat2, glam::DVec2, f64); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DSvd2 { #[inline] fn from(svd: Svd2) -> Self { @@ -102,6 +104,7 @@ impl From for DSvd2 { } } +#[cfg(feature = "f64")] impl From for Svd2 { #[inline] fn from(svd: DSvd2) -> Self { @@ -172,6 +175,7 @@ mod tests { assert_relative_eq!(svd.recompose(), mat, epsilon = 1e-6); } + #[cfg(feature = "f64")] #[test] fn svd_2x2_f64() { let mat = glam::DMat2::from_cols_array_2d(&[[4.0, 3.0], [2.0, 1.0]]); diff --git a/src/svd3.rs b/src/svd3.rs index 6c74e02..134ceea 100644 --- a/src/svd3.rs +++ b/src/svd3.rs @@ -6,7 +6,9 @@ #[cfg(not(feature = "std"))] use simba::scalar::ComplexField; -use crate::eigen3::{DSymmetricEigen3, SymmetricEigen3}; +#[cfg(feature = "f64")] +use crate::eigen3::DSymmetricEigen3; +use crate::eigen3::SymmetricEigen3; use crate::SymmetricEigen3A; /// Macro to generate Svd3 for a specific scalar type. @@ -130,9 +132,11 @@ macro_rules! impl_svd3 { impl_svd3!(Svd3, glam::Mat3, glam::Vec3, SymmetricEigen3, f32); impl_svd3!(Svd3A, glam::Mat3A, glam::Vec3A, SymmetricEigen3A, f32); +#[cfg(feature = "f64")] impl_svd3!(DSvd3, glam::DMat3, glam::DVec3, DSymmetricEigen3, f64); // f32 <-> f64 conversions +#[cfg(feature = "f64")] impl From for DSvd3 { #[inline] fn from(svd: Svd3) -> Self { @@ -144,6 +148,7 @@ impl From for DSvd3 { } } +#[cfg(feature = "f64")] impl From for Svd3 { #[inline] fn from(svd: DSvd3) -> Self { @@ -155,6 +160,7 @@ impl From for Svd3 { } } +#[cfg(feature = "f64")] impl From for DSvd3 { #[inline] fn from(svd: Svd3A) -> Self { @@ -166,6 +172,7 @@ impl From for DSvd3 { } } +#[cfg(feature = "f64")] impl From for Svd3A { #[inline] fn from(svd: DSvd3) -> Self { @@ -263,6 +270,7 @@ mod tests { assert_relative_eq!(svd.recompose(), mat, epsilon = 1e-5); } + #[cfg(feature = "f64")] #[test] fn svd_3x3_f64() { let mat =