pub struct Vector2<T: CoordsFloat>(pub T, pub T);
Expand description
2D vector representation
§Generics
T: CoordsFloat
– Generic type for coordinates representation.
§Example
use honeycomb_core::prelude::Vector2;
let unit_x = Vector2::unit_x();
let unit_y = Vector2::unit_y();
assert_eq!(unit_x.dot(&unit_y), 0.0);
assert_eq!(unit_x.normal_dir()?, unit_y);
let two: f64 = 2.0;
let x_plus_y: Vector2<f64> = unit_x + unit_y;
assert_eq!(x_plus_y.norm(), two.sqrt());
assert_eq!(x_plus_y.unit_dir()?, Vector2(1.0 / two.sqrt(), 1.0 / two.sqrt()));
Tuple Fields§
§0: T
§1: T
Implementations§
Source§impl<T: CoordsFloat> Vector2<T>
impl<T: CoordsFloat> Vector2<T>
Sourcepub fn into_inner(self) -> (T, T)
pub fn into_inner(self) -> (T, T)
Sourcepub fn unit_dir(&self) -> Result<Self, CoordsError>
pub fn unit_dir(&self) -> Result<Self, CoordsError>
Sourcepub fn normal_dir(&self) -> Result<Vector2<T>, CoordsError>
pub fn normal_dir(&self) -> Result<Vector2<T>, CoordsError>
Compute the direction of the normal vector to self
.
§Return
Return a Vector2 indicating the direction of the normal to self
. The norm of the
returned struct is equal to one.
§Errors
This method will return an error if called on a Vector2
with a norm equal to zero,
i.e. a null Vector2
.
§Example
See Vector2 example.
Trait Implementations§
Source§impl<T: CoordsFloat> Add for Vector2<T>
impl<T: CoordsFloat> Add for Vector2<T>
Source§impl<T: CoordsFloat> AddAssign<&Vector2<T>> for Vertex2<T>
impl<T: CoordsFloat> AddAssign<&Vector2<T>> for Vertex2<T>
Source§fn add_assign(&mut self, rhs: &Vector2<T>)
fn add_assign(&mut self, rhs: &Vector2<T>)
Performs the
+=
operation. Read moreSource§impl<T: CoordsFloat> AddAssign<Vector2<T>> for Vertex2<T>
impl<T: CoordsFloat> AddAssign<Vector2<T>> for Vertex2<T>
Source§fn add_assign(&mut self, rhs: Vector2<T>)
fn add_assign(&mut self, rhs: Vector2<T>)
Performs the
+=
operation. Read moreSource§impl<T: CoordsFloat> AddAssign for Vector2<T>
impl<T: CoordsFloat> AddAssign for Vector2<T>
Source§fn add_assign(&mut self, rhs: Vector2<T>)
fn add_assign(&mut self, rhs: Vector2<T>)
Performs the
+=
operation. Read moreSource§impl<T: CoordsFloat> Div<T> for Vector2<T>
impl<T: CoordsFloat> Div<T> for Vector2<T>
Source§impl<T: CoordsFloat> DivAssign<T> for Vector2<T>
impl<T: CoordsFloat> DivAssign<T> for Vector2<T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the
/=
operation. Read moreSource§impl<T: CoordsFloat> Mul<T> for Vector2<T>
impl<T: CoordsFloat> Mul<T> for Vector2<T>
Source§impl<T: CoordsFloat> MulAssign<T> for Vector2<T>
impl<T: CoordsFloat> MulAssign<T> for Vector2<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*=
operation. Read moreSource§impl<T: CoordsFloat> Neg for Vector2<T>
impl<T: CoordsFloat> Neg for Vector2<T>
Source§impl<T: CoordsFloat> Sub for Vector2<T>
impl<T: CoordsFloat> Sub for Vector2<T>
Source§impl<T: CoordsFloat> SubAssign<&Vector2<T>> for Vertex2<T>
impl<T: CoordsFloat> SubAssign<&Vector2<T>> for Vertex2<T>
Source§fn sub_assign(&mut self, rhs: &Vector2<T>)
fn sub_assign(&mut self, rhs: &Vector2<T>)
Performs the
-=
operation. Read moreSource§impl<T: CoordsFloat> SubAssign<Vector2<T>> for Vertex2<T>
impl<T: CoordsFloat> SubAssign<Vector2<T>> for Vertex2<T>
Source§fn sub_assign(&mut self, rhs: Vector2<T>)
fn sub_assign(&mut self, rhs: Vector2<T>)
Performs the
-=
operation. Read moreSource§impl<T: CoordsFloat> SubAssign for Vector2<T>
impl<T: CoordsFloat> SubAssign for Vector2<T>
Source§fn sub_assign(&mut self, rhs: Vector2<T>)
fn sub_assign(&mut self, rhs: Vector2<T>)
Performs the
-=
operation. Read moreimpl<T: Copy + CoordsFloat> Copy for Vector2<T>
impl<T: CoordsFloat> Send for Vector2<T>
impl<T: CoordsFloat> StructuralPartialEq for Vector2<T>
impl<T: CoordsFloat> Sync for Vector2<T>
Auto Trait Implementations§
impl<T> Freeze for Vector2<T>where
T: Freeze,
impl<T> RefUnwindSafe for Vector2<T>where
T: RefUnwindSafe,
impl<T> Unpin for Vector2<T>where
T: Unpin,
impl<T> UnwindSafe for Vector2<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.