glam
![Build Status] ![codecov-badge] ![Latest Version] ![docs] ![Minimum Supported Rust Version]
This crate uses bytemuck to implement a zero-cost[^zero_cost] strongly typed interface on top of glam.
The API is similar to euclid, but more ergonomic (although YMMV).
One of the API design goals of glam
is to avoid complexity by not going
bananas with traits and generics. This crate is the opposite. But it does
allow you to easily drop down to plain glam
when needed.
See the docs
module for detailed documentation.
compile times and make debug builds slower due to increased code size.
Unit
] for that struct. [Unit::Scalar
] determines the primitive
type used in vector components.f32
, f64
, i32
, or u32
(or bitwise compatible with
one of them)[^custom_scalar].The basic primitive scalars are also units in their own right ("untyped").
[Angle<T>
] is an example of a generic custom scalar.
```rust use glamour::prelude::*;
struct MyUnit; impl Unit for MyUnit { type Scalar = f32; }
// Start using your new unit:
let vector: Vector4
// Use untyped units when needed:
let vectoruntyped: &Vector4
// Use glam when needed: let vectorraw: &glam::Vec4 = vector.asraw(); ```
See the documentation module for more examples.
std
- enables the glam/std
feature. Enabled by default.libm
- required to compile with no_std
(transitively enables
glam/no_std
).mint
- enables conversion to/from
mint
types.glam_0_20
- enables Into
/From
conversions to the glam 0.20 versions of
vector and matrix types. This is intended for interoperability with
significant ecosystems, such as Bevy 0.7. To be clear, this creates a
duplicate dependency on glam
: One at the currently targeted version
(0.21.x), and one at glam 0.20.0.bevy_0_7_0
: Enables the glam_0_20
feature, which is needed to perform
conversions to/from the math types exposed by Bevy 0.7.Size2
] are called width
and
height
, rather than x
and y
.glam
types when needed.glam
euclid
bytemuck
.glam
glam
is a very approachable API.glam
is able to support a wide range of transformation primitives (e.g.
[glam::Affine3A
], [glam::Quat
], etc.), and the user has a lot of
flexibility to choose the most performant kind for their use case. These are
simply unimplemented in glamour
.euclid
Unit
].glam
.no_std
.glam
API conventions - "principle of least surprise".glam
directly).
Comprehensive benchmarks pending.glam
).glam
API. Instead, we make it really easy (and
performant) to drop down to glam
types when needed.glam
API. It's OK to use glam
types in public APIs.The "AoSoA" pattern ("extra wide" vector types). Use ultraviolet instead[^use_uv].
library are actually compatible with the non-wide vector types in
Ultraviolet, so it may actually just work (using bytemuck::cast()
and
friends), but no guarantees.
All operations should perform exactly the same as their glam
counterparts.
There is a zero-tolerance policy for overhead in release builds.
However, debug build performance is also important in some cases. For example, for a video game it can make the difference between being playable or not in debug mode.
This crate should be expected to incur an overhead of about a factor 2 compared
to glam
in debug builds. This may be alleviated in the future, but it seems
that even glam
itself does not go out of its way to perform well in debug
builds.