#[repr(C)]pub struct Vector2<F: Float> {
pub x: F,
pub y: F,
}Expand description
2 Dimensional vector.
Fields§
§x: F§y: FImplementations§
Source§impl<F: Float> Vector2<F>
impl<F: Float> Vector2<F>
Sourcepub const fn to_complex(self) -> Complex<F>
pub const fn to_complex(self) -> Complex<F>
Converts a vector to a complex number with real = x, imag = y.
Sourcepub const fn from_complex(complex: Complex<F>) -> Self
pub const fn from_complex(complex: Complex<F>) -> Self
Converts a complex number to a vector with x = real, y = imag.
Sourcepub const fn extend(self, z: F) -> Vector3<F>
pub const fn extend(self, z: F) -> Vector3<F>
Extends the vector with z component to create a Vector3.
Sourcepub fn rotate_by(&mut self, angle: F)
pub fn rotate_by(&mut self, angle: F)
Rotates angle around origin by some angle angle in radians counter-clockwise.
Sourcepub fn rotated_by(self, angle: F) -> Self
pub fn rotated_by(self, angle: F) -> Self
Returns a rotated copy of a vector. See Self::rotate_by.
Sourcepub fn rotate_by_clockwise(&mut self, angle: F)
pub fn rotate_by_clockwise(&mut self, angle: F)
Rotates angle around origin by some angle angle in radians clockwise.
Sourcepub fn rotated_by_clockwise(self, angle: F) -> Self
pub fn rotated_by_clockwise(self, angle: F) -> Self
Returns a rotated copy of a vector. See Self::rotate_by_clockwise.
Sourcepub fn max_element(&self) -> F
pub fn max_element(&self) -> F
Returns maximum element of the vector.
Sourcepub fn min_element(&self) -> F
pub fn min_element(&self) -> F
Returns minumum element of the vector.
Sourcepub fn max_index(&self) -> usize
pub fn max_index(&self) -> usize
Returns index of the maximum element.
Index is in 0..=1 range.
Sourcepub fn min_index(&self) -> usize
pub fn min_index(&self) -> usize
Returns index of the minumum element.
Index is in 0..=1 range.
pub fn reflect(&self, axis: Self) -> Self
Source§impl<F: Float> Vector2<F>
impl<F: Float> Vector2<F>
Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
Normalizes vector, preserving directing and making its magnitude equal to 1.
Sourcepub fn normalized(&self) -> Self
pub fn normalized(&self) -> Self
Returns normalized copy of the vector. See Self::normalize.
Sourcepub fn from_array(array: [F; 2]) -> Self
pub fn from_array(array: [F; 2]) -> Self
Converts array to a vector.
Sourcepub fn as_array_mut<'a>(&'a mut self) -> &'a [F; 2]
pub fn as_array_mut<'a>(&'a mut self) -> &'a [F; 2]
Converts the vector to a mutable array slice.
Sourcepub fn dot(&self, other: Self) -> F
pub fn dot(&self, other: Self) -> F
Computes the dot(scalar) product between two vectors. Dot product for two normalized vector is equal to the cosine of the angle between them.
Sourcepub fn dot_normalized(&self, other: Self) -> F
pub fn dot_normalized(&self, other: Self) -> F
Computes the dot product between two vectors normalizing them beforehand.
Sourcepub fn angle_to(&self, other: Self) -> F
pub fn angle_to(&self, other: Self) -> F
Returns angle in radians between two vectors. Output range is: [0, pi].
Sourcepub fn arc_angle_to(&self, other: Self) -> F
pub fn arc_angle_to(&self, other: Self) -> F
Returns angle in radians between two vectors that goes along circle arc
counter-clockwise. Output range is: [0, 2pi].
let a = vector!(1, 1);
let b = vector!(-1, 1);
assert_eq!(a.arc_angle_to(b).to_degrees(), 90.0);
assert_eq!(b.arc_angle_to(a).to_degrees(), 270.0);
/* (B). -- ~~~ -- .(A)
.-~\ 90.0 / ~-.
/ \ / \
/ \ / \
| \ / |
| () |
| |
\ 270.0 /
\ /
`-. .-'
~- . ___ . -~ */Sourcepub fn project_onto(&mut self, axis: Self)
pub fn project_onto(&mut self, axis: Self)
Projects a vector onto another vector. Axis and the resulting vector are collinear.
Sourcepub fn projected_onto(&self, axis: Self) -> Self
pub fn projected_onto(&self, axis: Self) -> Self
Returns the projected copy of the vector onto another vector. See
Self::project_onto.
Sourcepub fn distance_to(&self, other: Self) -> F
pub fn distance_to(&self, other: Self) -> F
Computes the distance between two vectors.
Sourcepub fn sqr_distance_to(&self, other: Self) -> F
pub fn sqr_distance_to(&self, other: Self) -> F
Computes the squared distance between two vectors.
Sourcepub fn inv_lerp(self, end: Self, v: Self) -> F
pub fn inv_lerp(self, end: Self, v: Self) -> F
Inverse linear interpolation between two vectors.
Source§impl<F: Float> Vector2<F>
impl<F: Float> Vector2<F>
Sourcepub const fn into_parts(self) -> (F, F)
pub const fn into_parts(self) -> (F, F)
Splits into components.
Sourcepub const fn from_parts(parts: (F, F)) -> Self
pub const fn from_parts(parts: (F, F)) -> Self
Creates new from components.
Sourcepub fn scaled(self, factor: F) -> Self
pub fn scaled(self, factor: F) -> Self
Returns the scaled copy. See Self::scale.
Sourcepub fn sqr_magnitude(&self) -> F
pub fn sqr_magnitude(&self) -> F
Returns squared magnitude.
Trait Implementations§
Source§impl<F: Float> AddAssign for Vector2<F>
impl<F: Float> AddAssign for Vector2<F>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<F: Float> DivAssign<F> for Vector2<F>
impl<F: Float> DivAssign<F> for Vector2<F>
Source§fn div_assign(&mut self, rhs: F)
fn div_assign(&mut self, rhs: F)
/= operation. Read moreSource§impl<F: Float> MulAssign<F> for Vector2<F>
impl<F: Float> MulAssign<F> for Vector2<F>
Source§fn mul_assign(&mut self, rhs: F)
fn mul_assign(&mut self, rhs: F)
*= operation. Read moreSource§impl<F: PartialOrd + Float> PartialOrd for Vector2<F>
impl<F: PartialOrd + Float> PartialOrd for Vector2<F>
Source§impl<F: Float> SubAssign for Vector2<F>
impl<F: Float> SubAssign for Vector2<F>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreimpl<F: Copy + Float> Copy for Vector2<F>
impl<F: Float> Pod for Vector2<F>
impl<F: Float> StructuralPartialEq for Vector2<F>
Auto Trait Implementations§
impl<F> Freeze for Vector2<F>where
F: Freeze,
impl<F> RefUnwindSafe for Vector2<F>where
F: RefUnwindSafe,
impl<F> Send for Vector2<F>where
F: Send,
impl<F> Sync for Vector2<F>where
F: Sync,
impl<F> Unpin for Vector2<F>where
F: Unpin,
impl<F> UnwindSafe for Vector2<F>where
F: 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
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.