Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 36 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"] }
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions src/eigen2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymmetricEigen2> for DSymmetricEigen2 {
#[inline]
fn from(e: SymmetricEigen2) -> Self {
Expand All @@ -88,6 +90,7 @@ impl From<SymmetricEigen2> for DSymmetricEigen2 {
}
}

#[cfg(feature = "f64")]
impl From<DSymmetricEigen2> for SymmetricEigen2 {
#[inline]
fn from(e: DSymmetricEigen2) -> Self {
Expand Down Expand Up @@ -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]]);
Expand Down
6 changes: 6 additions & 0 deletions src/eigen3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymmetricEigen3> for DSymmetricEigen3 {
#[inline]
fn from(e: SymmetricEigen3) -> Self {
Expand All @@ -256,6 +258,7 @@ impl From<SymmetricEigen3> for DSymmetricEigen3 {
}
}

#[cfg(feature = "f64")]
impl From<DSymmetricEigen3> for SymmetricEigen3 {
#[inline]
fn from(e: DSymmetricEigen3) -> Self {
Expand All @@ -266,6 +269,7 @@ impl From<DSymmetricEigen3> for SymmetricEigen3 {
}
}

#[cfg(feature = "f64")]
impl From<SymmetricEigen3A> for DSymmetricEigen3 {
#[inline]
fn from(e: SymmetricEigen3A) -> Self {
Expand All @@ -276,6 +280,7 @@ impl From<SymmetricEigen3A> for DSymmetricEigen3 {
}
}

#[cfg(feature = "f64")]
impl From<DSymmetricEigen3> for SymmetricEigen3A {
#[inline]
fn from(e: DSymmetricEigen3) -> Self {
Expand Down Expand Up @@ -355,6 +360,7 @@ mod tests {
);
}

#[cfg(feature = "f64")]
#[test]
fn eigen_3x3_f64() {
let mat =
Expand Down
78 changes: 62 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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};
}
19 changes: 15 additions & 4 deletions src/matrix_ext.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 9 additions & 1 deletion src/pose2.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -356,6 +358,7 @@ impl_pose2!(
glam::Mat3,
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
);
#[cfg(feature = "f64")]
impl_pose2!(
DPose2,
DRot2,
Expand All @@ -367,6 +370,7 @@ impl_pose2!(
);

// f32 <-> f64 conversions
#[cfg(feature = "f64")]
impl From<Pose2> for DPose2 {
#[inline]
fn from(p: Pose2) -> Self {
Expand All @@ -377,6 +381,7 @@ impl From<Pose2> for DPose2 {
}
}

#[cfg(feature = "f64")]
impl From<DPose2> for Pose2 {
#[inline]
fn from(p: DPose2) -> Self {
Expand Down Expand Up @@ -410,6 +415,7 @@ mod nalgebra_conv {
}
}

#[cfg(feature = "f64")]
impl From<DPose2> for nalgebra::Isometry2<f64> {
fn from(p: DPose2) -> Self {
nalgebra::Isometry2 {
Expand All @@ -419,6 +425,7 @@ mod nalgebra_conv {
}
}

#[cfg(feature = "f64")]
impl From<nalgebra::Isometry2<f64>> for DPose2 {
fn from(iso: nalgebra::Isometry2<f64>) -> Self {
Self {
Expand Down Expand Up @@ -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);
Expand Down
Loading
Loading