Struct batbox::Vec2 [−][src]
2 dimensional vector.
Fields
x: T
x
coordinate of the vector
y: T
y
coordinate of the vector
Implementations
impl<T> Vec2<T>
[src]
impl<T: Num + Copy> Vec2<T>
[src]
pub fn dot(a: Self, b: Self) -> T
[src]
Calculate dot product of two vectors.
Examples
use batbox::*; assert_eq!(Vec2::dot(vec2(1, 2), vec2(3, 4)), 11);
pub fn skew(a: Self, b: Self) -> T
[src]
Calculate skew product of two vectors.
Examples
use batbox::*; assert_eq!(Vec2::skew(vec2(1, 2), vec2(3, 4)), -2);
impl<T: Neg<Output = T>> Vec2<T>
[src]
impl<T: Float> Vec2<T>
[src]
pub fn normalize(self) -> Self
[src]
Normalize a vector.
Examples
use batbox::*; let v: Vec2<f64> = vec2(1.0, 2.0); assert!((v.normalize().len() - 1.0).abs() < 1e-5);
pub fn len(self) -> T
[src]
Calculate length of a vector.
pub fn rotated(v: Self, angle: T) -> Self
[src]
Rotate a vector by a given angle.
pub fn clamp(self, max_len: T) -> Self
[src]
pub fn arg(self) -> T
[src]
Methods from Deref<Target = [T; 2]>
pub fn as_slice(&self) -> &[T]
[src]
array_methods
)Returns a slice containing the entire array. Equivalent to &s[..]
.
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
array_methods
)Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
pub fn each_ref(&self) -> [&T; N]
[src]
array_methods
)Borrows each element and returns an array of references with the same
size as self
.
Example
#![feature(array_methods)] let floats = [3.1, 2.7, -1.0]; let float_refs: [&f64; 3] = floats.each_ref(); assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
#![feature(array_methods, array_map)] let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()]; let is_ascii = strings.each_ref().map(|s| s.is_ascii()); assert_eq!(is_ascii, [true, false, true]); // We can still access the original array: it has not been moved. assert_eq!(strings.len(), 3);
pub fn each_mut(&mut self) -> [&mut T; N]
[src]
array_methods
)Borrows each element mutably and returns an array of mutable references
with the same size as self
.
Example
#![feature(array_methods)] let mut floats = [3.1, 2.7, -1.0]; let float_refs: [&mut f64; 3] = floats.each_mut(); *float_refs[0] = 0.0; assert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]); assert_eq!(floats, [0.0, 2.7, -1.0]);
Trait Implementations
impl<T: Add<Output = T>> Add<Vec2<T>> for Vec2<T>
[src]
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
impl<T: AddAssign> AddAssign<Vec2<T>> for Vec2<T>
[src]
fn add_assign(&mut self, rhs: Self)
[src]
impl<T: Clone> Clone for Vec2<T>
[src]
impl<T: Copy> Copy for Vec2<T>
[src]
impl<T: Debug> Debug for Vec2<T>
[src]
impl<T> Deref for Vec2<T>
[src]
impl<T> DerefMut for Vec2<T>
[src]
impl<'de, T> Deserialize<'de> for Vec2<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<T: Display> Display for Vec2<T>
[src]
impl Distribution<Vec2<f32>> for UnitCircleInside
[src]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Vec2<f32>
[src]
pub fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T> where
R: Rng,
[src]
R: Rng,
impl<T: Copy + Div<Output = T>> Div<T> for Vec2<T>
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: T) -> Self
[src]
impl<T: Div<Output = T>> Div<Vec2<T>> for Vec2<T>
[src]
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Self
[src]
impl<T: Copy + DivAssign> DivAssign<T> for Vec2<T>
[src]
fn div_assign(&mut self, rhs: T)
[src]
impl<T: DivAssign> DivAssign<Vec2<T>> for Vec2<T>
[src]
fn div_assign(&mut self, rhs: Self)
[src]
impl<T: Eq> Eq for Vec2<T>
[src]
impl<T> From<[T; 2]> for Vec2<T>
[src]
impl<T: Hash> Hash for Vec2<T>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: Copy + Mul<Output = T>> Mul<T> for Vec2<T>
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: T) -> Self
[src]
impl<T: Mul<Output = T>> Mul<Vec2<T>> for Vec2<T>
[src]
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self
[src]
impl<T: Copy + MulAssign> MulAssign<T> for Vec2<T>
[src]
fn mul_assign(&mut self, rhs: T)
[src]
impl<T: MulAssign> MulAssign<Vec2<T>> for Vec2<T>
[src]
fn mul_assign(&mut self, rhs: Self)
[src]
impl<T: Neg<Output = T>> Neg for Vec2<T>
[src]
impl<T: PartialEq> PartialEq<Vec2<T>> for Vec2<T>
[src]
impl<T> Serialize for Vec2<T> where
T: Serialize,
[src]
T: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<T> StructuralEq for Vec2<T>
[src]
impl<T> StructuralPartialEq for Vec2<T>
[src]
impl<T: Sub<Output = T>> Sub<Vec2<T>> for Vec2<T>
[src]
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
impl<T: SubAssign> SubAssign<Vec2<T>> for Vec2<T>
[src]
fn sub_assign(&mut self, rhs: Self)
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Vec2<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Vec2<T> where
T: Send,
T: Send,
impl<T> Sync for Vec2<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Vec2<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Vec2<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
pub fn __clone_box(&self, Private) -> *mut ()
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,