Struct gfxmath_vec2::Vec2
source · #[repr(C)]pub struct Vec2<T> {
pub x: T,
pub y: T,
}
Fields§
§x: T
§y: T
Implementations§
source§impl<T> Vec2<T>
impl<T> Vec2<T>
pub fn new(x: T, y: T) -> Self
pub fn as_ptr(&self) -> *const T
pub fn as_mut_ptr(&mut self) -> *mut T
sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
use gfxmath_vec2::Vec2;
let a = Vec2::<f32>::new(1.0, 2.0);
let a_slice = a.as_slice();
assert_eq!(1.0, a_slice[0]);
assert_eq!(2.0, a_slice[1]);
sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
use gfxmath_vec2::Vec2;
let mut a = Vec2::<f32>::new(1.0, 2.0);
{
let a_slice = a.as_mut_slice();
assert_eq!(1.0, a_slice[0]);
assert_eq!(2.0, a_slice[1]);
a_slice[1] = 108.0;
assert_eq!(108.0, a_slice[1]);
}
a.x = 4.5;
assert_eq!(4.5, a.x);
let a_slice = a.as_mut_slice();
assert_eq!(4.5, a_slice[0]);
assert_eq!(108.0, a_slice[1]);
Trait Implementations§
source§impl<T> Add<Vec2<T>> for Vec2<T>where
T: Add<Output = T> + Clone,
impl<T> Add<Vec2<T>> for Vec2<T>where T: Add<Output = T> + Clone,
source§impl<T> AddAssign<&Vec2<T>> for Vec2<T>where
T: AddAssign<T> + Copy,
impl<T> AddAssign<&Vec2<T>> for Vec2<T>where T: AddAssign<T> + Copy,
source§fn add_assign(&mut self, rhs: &Vec2<T>)
fn add_assign(&mut self, rhs: &Vec2<T>)
Performs the
+=
operation. Read moresource§impl<T> AddAssign<(T, T)> for Vec2<T>where
T: AddAssign,
impl<T> AddAssign<(T, T)> for Vec2<T>where T: AddAssign,
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = (2.0, 5.0);
v1 += v2;
assert_eq!(3.0, v1.x);
assert_eq!(8.0, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = (3.5, 2.0);
*(&mut v1) += v2;
assert_eq!(12.5, v1.x);
assert_eq!(7.0, v1.y);
source§fn add_assign(&mut self, rhs: (T, T))
fn add_assign(&mut self, rhs: (T, T))
Performs the
+=
operation. Read moresource§impl<T> AddAssign<T> for Vec2<T>where
T: AddAssign<T> + Copy,
impl<T> AddAssign<T> for Vec2<T>where T: AddAssign<T> + Copy,
source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(9.0, 5.0);
v1 += 2.0;
assert_eq!(11.0, v1.x);
assert_eq!(7.0, v1.y);
source§impl<T> AddAssign<Vec2<T>> for Vec2<T>where
T: AddAssign<T> + Copy,
impl<T> AddAssign<Vec2<T>> for Vec2<T>where T: AddAssign<T> + Copy,
source§fn add_assign(&mut self, rhs: Vec2<T>)
fn add_assign(&mut self, rhs: Vec2<T>)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = Vec2::new(2.0, 5.0);
v1 += v2;
assert_eq!(3.0, v1.x);
assert_eq!(8.0, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = Vec2::new(3.5, 2.0);
*(&mut v1) += v2;
assert_eq!(12.5, v1.x);
assert_eq!(7.0, v1.y);
source§impl<T> DivAssign<&Vec2<T>> for Vec2<T>where
T: DivAssign<T> + Copy,
impl<T> DivAssign<&Vec2<T>> for Vec2<T>where T: DivAssign<T> + Copy,
source§fn div_assign(&mut self, rhs: &Vec2<T>)
fn div_assign(&mut self, rhs: &Vec2<T>)
Performs the
/=
operation. Read moresource§impl<T> DivAssign<(T, T)> for Vec2<T>where
T: DivAssign,
impl<T> DivAssign<(T, T)> for Vec2<T>where T: DivAssign,
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = (2.0, 5.0);
v1 /= v2;
assert_eq!(0.5, v1.x);
assert_eq!(0.6, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = (2.5, 2.0);
*(&mut v1) /= v2;
assert_eq!(3.6, v1.x);
assert_eq!(2.5, v1.y);
source§fn div_assign(&mut self, rhs: (T, T))
fn div_assign(&mut self, rhs: (T, T))
Performs the
/=
operation. Read moresource§impl<T> DivAssign<T> for Vec2<T>where
T: DivAssign<T> + Copy,
impl<T> DivAssign<T> for Vec2<T>where T: DivAssign<T> + Copy,
source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(9.0, 5.0);
v1 /= 2.0;
assert_eq!(4.5, v1.x);
assert_eq!(2.5, v1.y);
source§impl<T> DivAssign<Vec2<T>> for Vec2<T>where
T: DivAssign<T> + Copy,
impl<T> DivAssign<Vec2<T>> for Vec2<T>where T: DivAssign<T> + Copy,
source§fn div_assign(&mut self, rhs: Vec2<T>)
fn div_assign(&mut self, rhs: Vec2<T>)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = Vec2::new(2.0, 5.0);
v1 /= v2;
assert_eq!(0.5, v1.x);
assert_eq!(0.6, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = Vec2::new(2.5, 2.0);
*(&mut v1) /= v2;
assert_eq!(3.6, v1.x);
assert_eq!(2.5, v1.y);
source§impl<T> From<&(T, T)> for Vec2<T>where
T: Clone,
impl<T> From<&(T, T)> for Vec2<T>where T: Clone,
use gfxmath_vec2::Vec2;
let v0 = (3.0, 2.0);
let v: Vec2<f32> = (&v0).into();
assert_eq!(3.0, v.x);
assert_eq!(2.0, v.y);
source§impl<T> From<&Vec2<T>> for (T, T)where
T: Clone,
impl<T> From<&Vec2<T>> for (T, T)where T: Clone,
use gfxmath_vec2::Vec2;
let v = Vec2::new(3.0, 2.0);
let v: (f32, f32) = (&v).into();
assert_eq!(3.0, v.0);
assert_eq!(2.0, v.1);
source§impl<T> From<(T, T)> for Vec2<T>
impl<T> From<(T, T)> for Vec2<T>
use gfxmath_vec2::Vec2;
let v: Vec2<f32> = (3.0, 2.0).into();
assert_eq!(3.0, v.x);
assert_eq!(2.0, v.y);
source§impl<T> From<Vec2<T>> for (T, T)
impl<T> From<Vec2<T>> for (T, T)
use gfxmath_vec2::Vec2;
let v = Vec2::new(3.0, 2.0);
let v: (f32, f32) = v.into();
assert_eq!(3.0, v.0);
assert_eq!(2.0, v.1);
source§impl<T> Mul<Vec2<T>> for Vec2<T>where
T: Mul<Output = T> + Copy,
impl<T> Mul<Vec2<T>> for Vec2<T>where T: Mul<Output = T> + Copy,
source§impl<T> MulAssign<&Vec2<T>> for Vec2<T>where
T: MulAssign<T> + Copy,
impl<T> MulAssign<&Vec2<T>> for Vec2<T>where T: MulAssign<T> + Copy,
source§fn mul_assign(&mut self, rhs: &Vec2<T>)
fn mul_assign(&mut self, rhs: &Vec2<T>)
Performs the
*=
operation. Read moresource§impl<T> MulAssign<(T, T)> for Vec2<T>where
T: MulAssign,
impl<T> MulAssign<(T, T)> for Vec2<T>where T: MulAssign,
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = (2.0, 5.0);
v1 *= v2;
assert_eq!(2.0, v1.x);
assert_eq!(15.0, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = (3.5, 2.0);
*(&mut v1) *= v2;
assert_eq!(31.5, v1.x);
assert_eq!(10.0, v1.y);
source§fn mul_assign(&mut self, rhs: (T, T))
fn mul_assign(&mut self, rhs: (T, T))
Performs the
*=
operation. Read moresource§impl<T> MulAssign<T> for Vec2<T>where
T: MulAssign<T> + Copy,
impl<T> MulAssign<T> for Vec2<T>where T: MulAssign<T> + Copy,
source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(9.0, 5.0);
v1 *= 2.0;
assert_eq!(18.0, v1.x);
assert_eq!(10.0, v1.y);
source§impl<T> MulAssign<Vec2<T>> for Vec2<T>where
T: MulAssign<T> + Copy,
impl<T> MulAssign<Vec2<T>> for Vec2<T>where T: MulAssign<T> + Copy,
source§fn mul_assign(&mut self, rhs: Vec2<T>)
fn mul_assign(&mut self, rhs: Vec2<T>)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = Vec2::new(2.0, 5.0);
v1 *= v2;
assert_eq!(2.0, v1.x);
assert_eq!(15.0, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = Vec2::new(3.5, 2.0);
*(&mut v1) *= v2;
assert_eq!(31.5, v1.x);
assert_eq!(10.0, v1.y);
source§impl<T: PartialEq> PartialEq<Vec2<T>> for Vec2<T>
impl<T: PartialEq> PartialEq<Vec2<T>> for Vec2<T>
source§impl<T: Sub<Output = T> + Copy> Sub<Vec2<T>> for Vec2<T>
impl<T: Sub<Output = T> + Copy> Sub<Vec2<T>> for Vec2<T>
source§fn sub(self, rhs: Vec2<T>) -> Self::Output
fn sub(self, rhs: Vec2<T>) -> Self::Output
use gfxmath_vec2::Vec2;
let mut a = Vec2::<f32>::new(0.5, 2.5);
let b = Vec2::<f32>::new(1.5, 2.5);
let c = Vec2::from(&a - &b);
a.x = 1.0;
assert_eq!(-1.0, c.x);
assert_eq!( 0.0, c.y);
let c2 = Vec2::from(a - b);
assert_eq!(-0.5, c2.x);
assert_eq!( 0.0, c2.y);
source§impl<T> SubAssign<&Vec2<T>> for Vec2<T>where
T: SubAssign<T> + Copy,
impl<T> SubAssign<&Vec2<T>> for Vec2<T>where T: SubAssign<T> + Copy,
source§fn sub_assign(&mut self, rhs: &Vec2<T>)
fn sub_assign(&mut self, rhs: &Vec2<T>)
Performs the
-=
operation. Read moresource§impl<T> SubAssign<(T, T)> for Vec2<T>where
T: SubAssign,
impl<T> SubAssign<(T, T)> for Vec2<T>where T: SubAssign,
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = (2.0, 5.0);
v1 -= v2;
assert_eq!(-1.0, v1.x);
assert_eq!(-2.0, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = (3.5, 2.0);
*(&mut v1) -= v2;
assert_eq!(5.5, v1.x);
assert_eq!(3.0, v1.y);
source§fn sub_assign(&mut self, rhs: (T, T))
fn sub_assign(&mut self, rhs: (T, T))
Performs the
-=
operation. Read moresource§impl<T> SubAssign<T> for Vec2<T>where
T: SubAssign<T> + Copy,
impl<T> SubAssign<T> for Vec2<T>where T: SubAssign<T> + Copy,
source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
v1 -= 2.0;
assert_eq!(-1.0, v1.x);
assert_eq!( 1.0, v1.y);
source§impl<T> SubAssign<Vec2<T>> for Vec2<T>where
T: SubAssign<T> + Copy,
impl<T> SubAssign<Vec2<T>> for Vec2<T>where T: SubAssign<T> + Copy,
source§fn sub_assign(&mut self, rhs: Vec2<T>)
fn sub_assign(&mut self, rhs: Vec2<T>)
use gfxmath_vec2::Vec2;
let mut v1 = Vec2::new(1.0, 3.0);
let v2 = Vec2::new(2.0, 5.0);
v1 -= v2;
assert_eq!(-1.0, v1.x);
assert_eq!(-2.0, v1.y);
let mut v1 = Vec2::new(9.0, 5.0);
let v2 = Vec2::new(3.5, 2.0);
*(&mut v1) -= v2;
assert_eq!(5.5, v1.x);
assert_eq!(3.0, v1.y);
impl<T> Eq for Vec2<T>where T: PartialEq,
impl<T> StructuralPartialEq for Vec2<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Vec2<T>where T: RefUnwindSafe,
impl<T> Send for Vec2<T>where T: Send,
impl<T> Sync for Vec2<T>where T: Sync,
impl<T> Unpin for Vec2<T>where T: Unpin,
impl<T> UnwindSafe for Vec2<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more