Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaticWyrm467 authored Jan 18, 2024
1 parent 04d73be commit 03d89cf
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ use swift_vec::vector::Vec2;

fn main() {

// Vectors support all primitive numerical types.
let vec_i32: Vec2<i32> = Vec2::ones_like();
let vec_u32: Vec2<u32> = Vec2::of(2);
let vec_usize: Vec2<usize> = Vec2::of(3);
let vec_f64: Vec2<f64> = Vec2::of(4.0);

// Vectors can be cast to other types, and can be manipulated just like any other numerical data.
let avg: Vec2<f32> = (vec_i32.cast() + vec_u32.cast() + vec_usize.cast() + vec_f64.cast()) / 4.0;
// Vectors support all primitive numerical types.
let vec_i32: Vec2<i32> = Vec2::ones_like();
let vec_u32: Vec2<u32> = Vec2::of(2);
let vec_usize: Vec2<usize> = Vec2::of(3);
let vec_f64: Vec2<f64> = Vec2::of(4.0);

assert_eq!(avg, Vec2(2.5, 2.5));

// Several operations are implemented, such as dot/cross products, magnitude/normalization, etc.
let dot: f64 = Vec2(5.0, 3.0).dot(&Vec2(1.0, 2.0));
let mag: f64 = Vec2(3.0, 4.0).magnitude();
// Vectors can be cast to other types, and can be manipulated just like any other numerical data.
let avg: Vec2<f32> = (vec_i32.cast() + vec_u32.cast() + vec_usize.cast() + vec_f64.cast()) / 4.0;

assert_eq!(avg, Vec2(2.5, 2.5));

assert_eq!(dot, 11.0);
assert_eq!(mag, 5.0);
assert_eq!(Vec2(3.0, 4.0).normalized().magnitude(), 1.0);

// Interpolation is added to both scalar and vector types.
let a: Vec2<f32> = Vec2(1.0, 2.0);
let b: Vec2<f32> = Vec2(3.0, 3.0);
let c: Vec2<f32> = a.lerp(&b, 0.5);

assert_eq!(c, Vec2(2.0, 2.5));
assert_eq!(1.0.lerp(2.0, 0.5), 1.5);

// min(), max(), and clamp() functions are also implemented for floating point scalars.
assert_eq!(1.0.min(2.0), 1.0);
assert_eq!(1.0.max(2.0), 2.0);
assert_eq!(1.0.clamp(0.0, 2.0), 1.0);
// Several operations are implemented, such as dot/cross products, magnitude/normalization, etc.
let dot: f64 = Vec2(5.0, 3.0).dot(&Vec2(1.0, 2.0));
let mag: f64 = Vec2(3.0, 4.0).magnitude();

assert_eq!(dot, 11.0);
assert_eq!(mag, 5.0);
assert_eq!(Vec2(3.0, 4.0).normalized().magnitude(), 1.0);

// Interpolation is added to both scalar and vector types.
let a: Vec2<f32> = Vec2(1.0, 2.0);
let b: Vec2<f32> = Vec2(3.0, 3.0);
let c: Vec2<f32> = a.lerp(&b, 0.5);

assert_eq!(c, Vec2(2.0, 2.5));
assert_eq!(1.0.lerp(2.0, 0.5), 1.5);

// min(), max(), and clamp() functions are also implemented for floating point scalars.
assert_eq!(1.0.min(2.0), 1.0);
assert_eq!(1.0.max(2.0), 2.0);
assert_eq!(1.0.clamp(0.0, 2.0), 1.0);
}
```

Expand Down

0 comments on commit 03d89cf

Please sign in to comment.