simple-vectors

Crates.iosimple-vectors
lib.rssimple-vectors
version0.2.1
created_at2021-04-12 10:16:57.826084+00
updated_at2025-09-18 17:00:07.039749+00
descriptionSimple, dimension generic vector math
homepage
repositoryhttps://gitlab.com/porky11/simple-vectors
max_upload_size
id382323
size16,454
Fabio Krapohl (porky11)

documentation

https://docs.rs/simple-vectors

README

simple-vectors

Crates.io Docs.rs License

A simple, dimension-generic vector mathematics library for Rust.

Features

  • Dimension and type generic: Works with vectors of any compile-time dimension and scalar type
  • Trait integration: Implements VectorSpace, DotProduct, and InnerSpace from the vector-space ecosystem
  • Optional parsing: Parsing support via the parsable feature

Installation

Add this to your Cargo.toml:

[dependencies]
simple-vectors = "0.2"

Quick Start

use simple_vectors::Vector;
use vector_space::InnerSpace;

// Create vectors
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;

// Vector operations (require `InnerSpace` trait)
let magnitude = v.magnitude();
let normalized = v.normalize();

Examples

2D Physics Simulation

use simple_vectors::Vector;
use vector_space::InnerSpace;

struct Particle {
    position: Vector<f64, 2>,
    velocity: Vector<f64, 2>,
    acceleration: Vector<f64, 2>,
}

impl Particle {
    fn update(&mut self, dt: f64) {
        self.velocity += self.acceleration * dt;
        self.position += self.velocity * dt;
        self.acceleration = Vector::zero();
    }
}

Generic Dimension Mathematics

use simple_vectors::Vector;
use vector_space::InnerSpace;

fn angle_between<T: num_traits::real::Real, const N: usize>(
    v: Vector<T, N>,
    w: Vector<T, N>,
) -> T {
    (v.dot(w) / (v.magnitude() * w.magnitude())).acos()
}

let v = Vector::new([1.0, 0.0]);
let w = Vector::new([0.0, 1.0]);
let angle = angle_between(v, w);

Integration with vector-space Ecosystem

This crate implements standard vector space traits, making it compatible with other libraries:

use simple_vectors::Vector;
use vector_space::{distance, InnerSpace};

let point_a = Vector::new([1.0, 2.0]);
let point_b = Vector::new([4.0, 6.0]);

// Calculate distance between points
let dist = distance(point_a, point_b); // 5.0

// Or manually
let diff = point_b - point_a;
let manual_dist = diff.magnitude(); // Also 5.0
Commit count: 16

cargo fmt