Expand description
A simple, dimension-generic vector math library.
This crate provides a generic Vector
type for performing vector operations with compile-time dimension checking. It’s designed to be lightweight, and integrates well with the vector-space
ecosystem.
§Features
- Dimension and type generic: Works with vectors of any compile-time dimension and scalar type
- Trait integration: Implements
VectorSpace
,DotProduct
, andInnerSpace
- Optional parsing: Parsing support via the
parsable
feature
§Basic Usage
use num_traits::Zero;
use simple_vectors::Vector;
// Create a 3D vector
let v = Vector::new([1.0, 2.0, 3.0]);
let w = Vector::new([4.0, 5.0, 6.0]);
// Basic arithmetic
let sum = v + w;
let scaled = v * 2.0;
// Dot product
let dot = v * w;
// Zero vector
let zero = Vector::<f64, 3>::zero();
§Examples
§2D Vector Operations
use simple_vectors::Vector;
let position = Vector::new([10.0, 20.0]);
let velocity = Vector::new([5.0, -2.0]);
let new_position = position + velocity;
§Generic Dimension Functions
use num_traits::real::Real;
use simple_vectors::Vector;
fn magnitude<T: Real, const N: usize>(v: Vector<T, N>) -> T {
(v * v).sqrt()
}
let v = Vector::new([1.0, 2.0, 3.0]);
let mag = magnitude(v);
§Integration with vector-space
This crate implements the standard vector-space
traits, making it compatible
with other libraries in the ecosystem:
use simple_vectors::Vector;
use vector_space::{InnerSpace, distance};
let v = Vector::new([1.0, 2.0]);
let w = Vector::new([3.0, 4.0]);
// Both work the same:
let dis1 = distance(v, w);
let dis2 = (w - v).magnitude();
assert_eq!(dis1, dis2);
Structs§
- Vector
- A generic, fixed-size vector with compile-time dimension checking.