Struct Fvec2

Source
#[repr(C)]
pub struct Fvec2 { /* private fields */ }
Expand description

2D vector with single precision.

The components are laid out in this order: [x, y]. This struct is aligned to 4 bytes, not 8.

This struct is here for consistency and does not explicitly use SIMD instructions. Internally, it is just an array of two floats.

§Examples

use mafs::{Vec2, Fvec2};

// Construction
let a = Fvec2::new(2.0, 3.0);
let b = Fvec2::new(6.0, 9.0);
let c = Fvec2::splat(0.0); // Set all four components to the same value

// Arithmetics
assert_eq!(a + b, Fvec2::new(8.0, 12.0));
assert_eq!(a - b, Fvec2::new(-4.0, -6.0));
assert_eq!(a * b, Fvec2::new(12.0, 27.0));
assert_eq!(b / a, Fvec2::new(3.0, 3.0));

// Euclidian norm
assert_eq!(a.norm(), 13.0f32.sqrt());
assert_eq!(a.normalize().norm(), 1.0);

// Specialized operations
assert_eq!(a.dot(b), 39.0);
assert_eq!(b.dot(a), a.dot(b));
assert_eq!(Fvec2::new(-0.5, 0.5).floor(), Fvec2::new(-1.0, 0.0));

// Comparisons
assert_eq!(a.min_componentwise(b), Fvec2::new(2.0, 3.0));
assert_eq!(a.max_componentwise(b), Fvec2::new(6.0, 9.0));

// Reduction
assert_eq!(a.min_reduce(), 2.0);
assert_eq!(b.max_reduce(), 9.0);

Trait Implementations§

Source§

impl Add<Fvec2> for f32

Source§

type Output = Fvec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Fvec2) -> Fvec2

Performs the + operation. Read more
Source§

impl Add<f32> for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f32) -> Fvec2

Performs the + operation. Read more
Source§

impl Add for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Fvec2) -> Fvec2

Performs the + operation. Read more
Source§

impl AddAssign<f32> for Fvec2

Source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
Source§

impl AddAssign for Fvec2

Source§

fn add_assign(&mut self, rhs: Fvec2)

Performs the += operation. Read more
Source§

impl Clone for Fvec2

Source§

fn clone(&self) -> Fvec2

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fvec2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Fvec2

Source§

fn default() -> Fvec2

Returns the “default value” for a type. Read more
Source§

impl Div<Fvec2> for f32

Source§

type Output = Fvec2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Fvec2) -> Fvec2

Performs the / operation. Read more
Source§

impl Div<f32> for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Fvec2

Performs the / operation. Read more
Source§

impl Div for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Fvec2) -> Fvec2

Performs the / operation. Read more
Source§

impl DivAssign<f32> for Fvec2

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl DivAssign for Fvec2

Source§

fn div_assign(&mut self, rhs: Fvec2)

Performs the /= operation. Read more
Source§

impl Index<usize> for Fvec2

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, idx: usize) -> &f32

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for Fvec2

Source§

fn index_mut(&mut self, idx: usize) -> &mut f32

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Mul<Fvec2> for f32

Source§

type Output = Fvec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Fvec2) -> Fvec2

Performs the * operation. Read more
Source§

impl Mul<f32> for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Fvec2

Performs the * operation. Read more
Source§

impl Mul for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Fvec2) -> Fvec2

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Fvec2

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl MulAssign for Fvec2

Source§

fn mul_assign(&mut self, rhs: Fvec2)

Performs the *= operation. Read more
Source§

impl Neg for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Fvec2

Performs the unary - operation. Read more
Source§

impl PartialEq for Fvec2

Source§

fn eq(&self, rhs: &Fvec2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<Fvec2> for f32

Source§

type Output = Fvec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Fvec2) -> Fvec2

Performs the - operation. Read more
Source§

impl Sub<f32> for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f32) -> Fvec2

Performs the - operation. Read more
Source§

impl Sub for Fvec2

Source§

type Output = Fvec2

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Fvec2) -> Fvec2

Performs the - operation. Read more
Source§

impl SubAssign<f32> for Fvec2

Source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
Source§

impl SubAssign for Fvec2

Source§

fn sub_assign(&mut self, rhs: Fvec2)

Performs the -= operation. Read more
Source§

impl Vec2<f32> for Fvec2

Source§

fn new(x: f32, y: f32) -> Fvec2

Create a new two-dimensional vector.
Source§

fn as_array(&self) -> &[f32; 2]

Convert to an array. Can also use the indexing operator [].
Source§

fn as_mut_array(&mut self) -> &mut [f32; 2]

Convert to a mutable array. Can also use the indexing operator[].
Source§

fn add_componentwise(&self, rhs: Fvec2) -> Fvec2

Add component by component. Can also use the + operator.
Source§

fn sub_componentwise(&self, rhs: Fvec2) -> Fvec2

Subtract component by component. Can also use the - operator.
Source§

fn mul_componentwise(&self, rhs: Fvec2) -> Fvec2

Multiply component by component. Can also use the * operator.
Source§

fn div_componentwise(&self, rhs: Fvec2) -> Fvec2

Divide component by component. Can also use the / operator.
Source§

fn min_componentwise(&self, rhs: Fvec2) -> Fvec2

For each lane, select the smallest component of the two.
Source§

fn max_componentwise(&self, rhs: Fvec2) -> Fvec2

For each lane, select the largest component of the two.
Source§

fn floor(&self) -> Fvec2

Round down all components to an integer value.
Source§

fn min_reduce(&self) -> f32

Smallest of the four components.
Source§

fn max_reduce(&self) -> f32

Largest of the four components.
Source§

fn eq_reduce(&self, rhs: Fvec2) -> bool

Equality of a vector to another on all components.
Source§

fn dot(&self, rhs: Fvec2) -> f32

Dot product.
Source§

fn splat(value: S) -> Self

Create a two-dimensional vector all with equal components.
Source§

fn norm(&self) -> S

Norm of this vector.
Source§

fn normalize(&self) -> Self

Divide by the norm to obain a normalized vector.
Source§

impl Copy for Fvec2

Auto Trait Implementations§

§

impl Freeze for Fvec2

§

impl RefUnwindSafe for Fvec2

§

impl Send for Fvec2

§

impl Sync for Fvec2

§

impl Unpin for Fvec2

§

impl UnwindSafe for Fvec2

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.