5 unstable releases
0.3.1 | Sep 22, 2021 |
---|---|
0.3.0 |
|
0.2.0 | Aug 27, 2021 |
0.1.2 | Aug 14, 2021 |
#442 in Simulation
350KB
956 lines
veccentric
Tiny 2D vector library. Inspired by p5.js's
p5.Vector
.
Usage
Add veccentric
to your Cargo.toml
.
[dependencies]
veccentric = "0.3"
Basic arithmetic on Vecc<T>
.
use veccentric::Vecc;
let a = Vecc::new(3_i32, 4);
let b = a * 5;
let c = Vecc::new(-10, -8);
let d = b - c;
let e = -d;
Fecc
's extended API.
use veccentric::Fecc;
let a: Fecc = (3.0, 4.0).into();
let b = a / 0.2;
let c = b.limit(20.0);
let d = c.rotate(PI);
let e = d.turn(0.0);
lib.rs
:
Tiny 2D vector library. Inspired by p5.js's
p5.Vector
.
The main type, Vecc<T>
, is a generic struct
implementing many useful traits and operator overloading.
Fecc
is a type alias for Vecc<f64>
. It has an extended API, heavily inspired by p5.Vector
.
Features
The random
feature enables additional
methods on Fecc
:
from_rng
,
from_seed
,
from_entropy
.
The all
feature enables just random
.
Notes
float_cmp::assert_approx_eq
is used in some examples.
Examples
use veccentric::Fecc;
let a = Fecc::new(3.0, 4.0);
assert_approx_eq!(f64, a.mag(), 5.0);
let five_a = a * 5.0;
assert_approx_eq!(f64, five_a.mag(), 25.0);
let b = Fecc::new(-3.0, 0.0);
let c = a + b; // (0.0, 4.0)
assert_approx_eq!(f64, c.angle(), PI / 2.0);
For more examples, go to Vecc
's docs or to
the repository.