#vector #fixed-size #allocated #statically #fixed-point #dimension #floating-point

xyzvec

Statically allocated fixed-size vectors for working in 2 and 3 dimensions

11 releases

new 0.1.11 May 15, 2024
0.1.10 May 15, 2024
0.1.6 Mar 11, 2024
0.1.3 Feb 15, 2024

#765 in Algorithms

Download history 123/week @ 2024-02-09 61/week @ 2024-02-16 36/week @ 2024-02-23 168/week @ 2024-03-01 297/week @ 2024-03-08 40/week @ 2024-03-15 1/week @ 2024-03-22 28/week @ 2024-03-29 229/week @ 2024-04-26 4/week @ 2024-05-03 353/week @ 2024-05-10

586 downloads per month

MIT license

29KB
618 lines

XYZVec

Statically allocated fixed-size vectors for working in 2 and 3 dimensions. These vectors are parameterized over number representations, so the library
works equally well for floating-point and fixed-point arithmetic.

f32, f64, and fixed-point (using the fixed crate) have been extensively tested. Other number representations may work, but have not been tested.

use xyzvec::XYZVec;

fn main(){
    // define an initial position
    let pos = XYZVec::new([1.0, 1.0, 1.0]);
    // define a velocity factor 
    let v = XYZVec::new([2.0, 3.0, 4.0]);
    // calculate new position (x + vt) after 2 seconds
    let new_pos = pos + v.scale_by(2.0);
    // prints (5.0, 7.0, 9.0) 
    println!("{}", new_pos);
}

Dependencies

~2.5MB
~45K SLoC