pub struct Vec2 {
pub x: f32,
pub y: f32,
/* private fields */
}Expand description
A two dimensional mathematical vector
§Examples
use miscmath::prelude::*;
let a = Vec2::default();
assert!( ( a.x < 0.00001 ) && ( a.y < 0.00001 ) );Fields§
§x: f32§y: f32Implementations§
Source§impl Vec2
impl Vec2
Sourcepub fn new(x: &f32, y: &f32) -> Vec2
pub fn new(x: &f32, y: &f32) -> Vec2
Generates a new instance of Vec2 initialized to chosen values and returns it
§Examples
use miscmath::prelude::*;
let a = Vec2::new( &5.6, &7.2 );
assert!( ( ( a.x - 5.6 ) < 0.00001 ) && ( ( a.y - 7.2 ) < 0.00001 ) );Sourcepub fn create_random(range_x: &Range<f32>) -> Vec2
pub fn create_random(range_x: &Range<f32>) -> Vec2
Generates a new instance of Vec2 initialized to random values in the range entered and returns it
§Examples
Sourcepub fn create_random2(range_x: &Range<f32>, range_y: &Range<f32>) -> Vec2
pub fn create_random2(range_x: &Range<f32>, range_y: &Range<f32>) -> Vec2
Generates a new instance of Vec2 initialized to random values in the range entered and returns it
§Examples
Sourcepub fn from_rand_angle(range_x: &Range<f32>, mag: &Option<f32>) -> Vec2
pub fn from_rand_angle(range_x: &Range<f32>, mag: &Option<f32>) -> Vec2
Generates a new instance of Vec2 initialized to random values in the range entered and returns it
§Examples
Sourcepub fn random_unit(range: &Range<f32>) -> Vec2
pub fn random_unit(range: &Range<f32>) -> Vec2
Generates a new instance of Vec2 initialized to a magnitude of 1 and a angle of random value in the range entered and returns it
§Examples
use std::f32::consts::TAU;
use miscmath::prelude::*;
let mut a = Vec2::random_unit( &( 0.0..TAU ) );
assert!( ( ( a.x - 1.0 ) < 0.00001 ) && ( a.y < TAU ) );Sourcepub fn unit() -> Vec2
pub fn unit() -> Vec2
Generates a new instance of Vec2 initialized as a unit vector of angle 0 and returns it
§Examples
use miscmath::prelude::*;
let mut b = Vec2::unit();
assert!( ( b.x - 1.0 < 0.00001 ) && ( b.y < 0.00001 ) );Sourcepub fn angle_between(&self, rhs: &Vec2) -> f32
pub fn angle_between(&self, rhs: &Vec2) -> f32
Calculates the angle between self and a passed in Vec2
§Examples
use miscmath::prelude::*;
let mut a = Vec2::new( &5.6, &7.2 );
let mut b = Vec2::unit();
let angle = a.angle_between( &mut b );
assert!( ( angle - 1.4731481877 ) < 0.00001 );Sourcepub fn lerp(&mut self, rhs: &Vec2, amt: UnitF)
pub fn lerp(&mut self, rhs: &Vec2, amt: UnitF)
Linearly interpolates between self and a passed in Vec2
§Examples
use miscmath::prelude::*;
let mut a = Vec2::new( &5.6, &7.2 );
let mut b = Vec2::unit();
a.lerp( &b, UnitF::new( 0.5 ) );
assert!( ( ( a.x - 3.3 ) < 0.00001 ) && ( ( a.y - 3.6 ) < 0.00001 ) );Sourcepub fn set(&mut self, input1: &f32, input2: &f32, coord_system: &CoordSystem)
pub fn set(&mut self, input1: &f32, input2: &f32, coord_system: &CoordSystem)
Sourcepub fn system(&self) -> CoordSystem
pub fn system(&self) -> CoordSystem
Trait Implementations§
Source§impl Add for Vec2
Implements Add for Vec2
impl Add for Vec2
Implements Add for Vec2
§Examples
use miscmath::prelude::*;
let mut x = Vec2::default();
let y = Vec2::new( &5.0, &7.0);
x += y;
assert_eq!(x, y);Source§impl AddAssign for Vec2
Implements AddAssign for Vec2
impl AddAssign for Vec2
Implements AddAssign for Vec2
§Examples
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Default for Vec2
Implements Default for Vec2
Generates a new instance of Vec2 initialized to zero and returns it
impl Default for Vec2
Implements Default for Vec2 Generates a new instance of Vec2 initialized to zero and returns it
§Examples
use miscmath::prelude::*;
let a = Vec2::default();
assert!( ( a.x < 0.00001 ) && ( a.y < 0.00001 ) );Source§impl DivAssign for Vec2
Implements DivAssign for Vec2
impl DivAssign for Vec2
Implements DivAssign for Vec2
§Examples
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl MulAssign for Vec2
Implements MulAssign for Vec2
impl MulAssign for Vec2
Implements MulAssign for Vec2
§Examples
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl RemAssign for Vec2
Implements RemAssign for Vec2
impl RemAssign for Vec2
Implements RemAssign for Vec2
§Examples
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl SubAssign for Vec2
Implements SubAssign for Vec2
impl SubAssign for Vec2
Implements SubAssign for Vec2
§Examples
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more