Inner Space
A Rust crate providing essential traits for vector operations, building on vector-space.
Features
DotProducttrait: Defines dot product with flexible output typeInnerSpacetrait: Provides common vector operations like normalize, project, reflect...- Free functions:
distanceanddistance2for point operations - Zero-cost abstractions: All operations are inlined and allocation-free
Example
use ;
use ;
use Zero;
// distance
let a = new;
let b = new;
assert_eq!;
// projection, rejection, reflection
let a = new;
let b = new;
assert_eq!;
assert_eq!;
assert_eq!;
Core Components
DotProduct Trait
InnerSpace Trait
Automatically implemented for types that implement DotProduct<Output = Scalar>. Provides:
magnitude()andmagnitude2()normalize()project()andreject()reflect()angle()with_magnitude()andwith_direction()
Free Functions
distance(a, b): Distance between two pointsdistance2(a, b): Squared distance between two points
Example: Vector Operations
let v = Vec2;
let unit = v.normalize;
assert_eq!;
let reflected = v.reflect; // Reflect over x-axis
assert_eq!;
Implementation Guide
- Implement
VectorSpacefromvector-spacecrate (also reexported here) - Implement
DotProductwithOutput = VectorSpace::Scalar - Get all
InnerSpacemethods automatically
Compatibility
Works with any type that implements VectorSpace and the required operations. Perfect for:
- Custom vector types
- Game development
- Physics simulations
- Graphics programming