Quaternion support for dew expressions.
Provides quaternion types and operations for 3D rotations. Uses [x, y, z, w] component order (scalar last, matching GLM/glTF convention).
Quick Start
use Expr;
use ;
use HashMap;
// Create a rotation quaternion and normalize it
let expr = parse.unwrap;
let vars: = .into;
let result = eval.unwrap;
assert_eq!;
Features
| Feature | Description |
|---|---|
wgsl |
WGSL shader code generation |
lua |
Lua code generation |
cranelift |
Cranelift JIT compilation |
Types
| Type | Description |
|---|---|
Scalar |
Real number |
Vec3 |
3D vector [x, y, z] |
Quaternion |
Quaternion [x, y, z, w] |
Functions
| Function | Description |
|---|---|
vec3(x, y, z) |
Construct vector → vec3 |
quat(x, y, z, w) |
Construct quaternion → quaternion |
conj(q) |
Conjugate → quaternion |
length(q) |
Magnitude → scalar |
normalize(q) |
Unit quaternion → quaternion |
inverse(q) |
Multiplicative inverse → quaternion |
dot(q1, q2) |
Dot product → scalar |
lerp(q1, q2, t) |
Linear interpolation → quaternion |
slerp(q1, q2, t) |
Spherical interpolation → quaternion |
axis_angle(axis, θ) |
From axis-angle → quaternion |
rotate(v, q) |
Rotate vector by quaternion → vec3 |
Operators
| Operation | Result |
|---|---|
q1 * q2 |
Quaternion multiplication |
q * scalar |
Scalar multiplication |
q1 + q2 |
Component-wise addition |
q1 - q2 |
Component-wise subtraction |
-q |
Negation |
Component Order
This crate uses [x, y, z, w] order (scalar last), matching:
- GLM (OpenGL Mathematics)
- glTF format
- Unity (internal representation)
Other conventions exist (w first), so be careful when interfacing with external libraries.