Tiny Vect
A minimal vector math library for 2D and 3D operations in Rust.
Features
- 2D Vectors (
Vect2) with comprehensive mathematical operations - 3D Vectors (
Vect3) with cross product and 3D-specific operations - Debug assertions for catching numerical errors during development
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
Core Operations
2D Vectors (Vect2)
- Basic operations:
+,-,*,/,+=,-=,*=,/= - Mathematical functions:
length(),normalize(),dot(),cross() - Geometric operations:
distance(),angle(),rotate(),lerp() - Utility functions:
is_zero(),is_normalized(),is_parallel()
3D Vectors (Vect3)
- All 2D operations plus 3D-specific functionality
- Cross product: Returns a 3D vector perpendicular to both inputs
- 3D distance calculations
- 3D angle calculations
Examples
Vector Arithmetic
let a = new;
let b = new;
let sum = a + b; // Vect2 { x: 4.0, y: 6.0 }
let diff = a - b; // Vect2 { x: -2.0, y: -2.0 }
let scaled = a * 2.0; // Vect2 { x: 2.0, y: 4.0 }
Geometric Operations
let v = new;
let length = v.length; // 5.0
let normalized = v.normalize; // Vect2 { x: 0.6, y: 0.8 }
let a = new;
let b = new;
let angle = a.angle_between; // π/2 radians
3D Cross Product
let a = new;
let b = new;
let cross = a.cross; // Vect3 { x: 0.0, y: 0.0, z: 1.0 }
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.