#[repr(C)]pub struct Vec2(pub f32, pub f32);Expand description
2D vector
Usually used as either a coordinate or a difference of coordinates, but may have some other uses.
Vec2 implements PartialOrd such that the comparison must be true of
all components: for example a < b == a.0 < b.0 && a.1 < b.1.
If c == Vec2(0, 1) and d == Vec2(1, 0) then
c != d && !(c < d) && !(c > d). Vec2 does not implement Ord.
Tuple Fields§
§0: f32§1: f32Implementations§
Source§impl Vec2
impl Vec2
Sourcepub const NEG_INFINITY: Vec2
pub const NEG_INFINITY: Vec2
Negative infinity
Sourcepub const fn splat(value: f32) -> Self
pub const fn splat(value: f32) -> Self
Constructs a new instance with each element initialized to value.
Sourcepub fn clamp(self, min: Self, max: Self) -> Self
pub fn clamp(self, min: Self, max: Self) -> Self
Restrict a value to a certain interval unless it is NaN
Returns max if self is greater than max, and min if
self is less than min. Otherwise this returns self.
Note that this function returns NaN if the initial value was NaN as well.
§Panics
Panics if min > max, min is NaN, or max is NaN.
Sourcepub fn complex_mul(self, rhs: Self) -> Self
pub fn complex_mul(self, rhs: Self) -> Self
Multiply two vectors as if they are complex numbers
Sourcepub fn complex_div(self, rhs: Self) -> Self
pub fn complex_div(self, rhs: Self) -> Self
Divide by a second vector as if they are complex numbers
Sourcepub fn complex_inv(self) -> Self
pub fn complex_inv(self) -> Self
Take the complex reciprocal
If both components are zero then the result will not be finite.
Sourcepub fn sum_square(self) -> f32
pub fn sum_square(self) -> f32
Return the sum of the square of the terms
Sourcepub fn distance_l1(self) -> f32
pub fn distance_l1(self) -> f32
Return the L1 (rectilinear / taxicab) distance
Sourcepub fn distance_l_inf(self) -> f32
pub fn distance_l_inf(self) -> f32
Return the L-inf (max) distance
Sourcepub fn extract<D: Directional>(self, dir: D) -> f32
pub fn extract<D: Directional>(self, dir: D) -> f32
Extract one component, based on a direction
This merely extracts the horizontal or vertical component. It never negates it, even if the axis is reversed.
Trait Implementations§
Source§impl AddAssign<Vec2> for Quad
impl AddAssign<Vec2> for Quad
Source§fn add_assign(&mut self, rhs: Vec2)
fn add_assign(&mut self, rhs: Vec2)
+= operation. Read moreSource§impl AddAssign<f32> for Vec2
impl AddAssign<f32> for Vec2
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
+= operation. Read moreSource§impl AddAssign for Vec2
impl AddAssign for Vec2
Source§fn add_assign(&mut self, rhs: Vec2)
fn add_assign(&mut self, rhs: Vec2)
+= operation. Read moreSource§impl ConvApprox<DVec2> for Vec2
impl ConvApprox<DVec2> for Vec2
Source§impl ConvApprox<Vec2> for Coord
impl ConvApprox<Vec2> for Coord
Source§fn try_conv_approx(arg: Vec2) -> Result<Self>
fn try_conv_approx(arg: Vec2) -> Result<Self>
Source§fn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Source§impl ConvApprox<Vec2> for Offset
impl ConvApprox<Vec2> for Offset
Source§fn try_conv_approx(arg: Vec2) -> Result<Self>
fn try_conv_approx(arg: Vec2) -> Result<Self>
Source§fn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Source§impl ConvApprox<Vec2> for Size
impl ConvApprox<Vec2> for Size
Source§fn try_conv_approx(arg: Vec2) -> Result<Self>
fn try_conv_approx(arg: Vec2) -> Result<Self>
Source§fn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Source§impl ConvFloat<Vec2> for Coord
impl ConvFloat<Vec2> for Coord
Source§fn try_conv_trunc(x: Vec2) -> Result<Self>
fn try_conv_trunc(x: Vec2) -> Result<Self>
Source§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Source§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Source§fn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Source§impl ConvFloat<Vec2> for Offset
impl ConvFloat<Vec2> for Offset
Source§fn try_conv_trunc(x: Vec2) -> Result<Self>
fn try_conv_trunc(x: Vec2) -> Result<Self>
Source§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Source§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Source§fn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Source§impl ConvFloat<Vec2> for Size
impl ConvFloat<Vec2> for Size
Source§fn try_conv_trunc(x: Vec2) -> Result<Self>
fn try_conv_trunc(x: Vec2) -> Result<Self>
Source§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Source§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Source§fn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Source§impl<'de> Deserialize<'de> for Vec2
impl<'de> Deserialize<'de> for Vec2
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign<f32> for Vec2
impl DivAssign<f32> for Vec2
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
/= operation. Read moreSource§impl From<LogicalSize> for Vec2
impl From<LogicalSize> for Vec2
Source§fn from(LogicalSize: LogicalSize) -> Self
fn from(LogicalSize: LogicalSize) -> Self
Source§impl From<PhysicalPosition<f32>> for Vec2
impl From<PhysicalPosition<f32>> for Vec2
Source§fn from(pos: PhysicalPosition<f32>) -> Self
fn from(pos: PhysicalPosition<f32>) -> Self
Source§impl From<PhysicalSize<f32>> for Vec2
impl From<PhysicalSize<f32>> for Vec2
Source§fn from(size: PhysicalSize<f32>) -> Self
fn from(size: PhysicalSize<f32>) -> Self
Source§impl From<Vec2> for LogicalSize
impl From<Vec2> for LogicalSize
Source§impl MulAssign<f32> for Vec2
impl MulAssign<f32> for Vec2
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*= operation. Read moreSource§impl MulAssign for Vec2
impl MulAssign for Vec2
Source§fn mul_assign(&mut self, rhs: Vec2)
fn mul_assign(&mut self, rhs: Vec2)
*= operation. Read moreSource§impl PartialOrd<Coord> for Vec2
impl PartialOrd<Coord> for Vec2
Source§impl PartialOrd for Vec2
impl PartialOrd for Vec2
Source§impl SubAssign<Vec2> for Quad
impl SubAssign<Vec2> for Quad
Source§fn sub_assign(&mut self, rhs: Vec2)
fn sub_assign(&mut self, rhs: Vec2)
-= operation. Read moreSource§impl SubAssign<f32> for Vec2
impl SubAssign<f32> for Vec2
Source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
-= operation. Read moreSource§impl SubAssign for Vec2
impl SubAssign for Vec2
Source§fn sub_assign(&mut self, rhs: Vec2)
fn sub_assign(&mut self, rhs: Vec2)
-= operation. Read moreimpl Copy for Vec2
impl StructuralPartialEq for Vec2
Auto Trait Implementations§
impl Freeze for Vec2
impl RefUnwindSafe for Vec2
impl Send for Vec2
impl Sync for Vec2
impl Unpin for Vec2
impl UnwindSafe for Vec2
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
Source§fn try_conv_approx(x: S) -> Result<T, Error>
fn try_conv_approx(x: S) -> Result<T, Error>
Source§fn conv_approx(x: S) -> T
fn conv_approx(x: S) -> T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().