#[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 AddAssign<f32> for Fvec2
impl AddAssign<f32> for Fvec2
Source§fn add_assign(&mut self, rhs: f32)
fn add_assign(&mut self, rhs: f32)
Performs the
+=
operation. Read moreSource§impl AddAssign for Fvec2
impl AddAssign for Fvec2
Source§fn add_assign(&mut self, rhs: Fvec2)
fn add_assign(&mut self, rhs: Fvec2)
Performs the
+=
operation. Read moreSource§impl DivAssign<f32> for Fvec2
impl DivAssign<f32> for Fvec2
Source§fn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Performs the
/=
operation. Read moreSource§impl DivAssign for Fvec2
impl DivAssign for Fvec2
Source§fn div_assign(&mut self, rhs: Fvec2)
fn div_assign(&mut self, rhs: Fvec2)
Performs the
/=
operation. Read moreSource§impl MulAssign<f32> for Fvec2
impl MulAssign<f32> for Fvec2
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Performs the
*=
operation. Read moreSource§impl MulAssign for Fvec2
impl MulAssign for Fvec2
Source§fn mul_assign(&mut self, rhs: Fvec2)
fn mul_assign(&mut self, rhs: Fvec2)
Performs the
*=
operation. Read moreSource§impl SubAssign<f32> for Fvec2
impl SubAssign<f32> for Fvec2
Source§fn sub_assign(&mut self, rhs: f32)
fn sub_assign(&mut self, rhs: f32)
Performs the
-=
operation. Read moreSource§impl SubAssign for Fvec2
impl SubAssign for Fvec2
Source§fn sub_assign(&mut self, rhs: Fvec2)
fn sub_assign(&mut self, rhs: Fvec2)
Performs the
-=
operation. Read moreSource§impl Vec2<f32> for Fvec2
impl Vec2<f32> for Fvec2
Source§fn as_mut_array(&mut self) -> &mut [f32; 2]
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
fn add_componentwise(&self, rhs: Fvec2) -> Fvec2
Add component by component.
Can also use the
+
operator.Source§fn sub_componentwise(&self, rhs: Fvec2) -> Fvec2
fn sub_componentwise(&self, rhs: Fvec2) -> Fvec2
Subtract component by component.
Can also use the
-
operator.Source§fn mul_componentwise(&self, rhs: Fvec2) -> Fvec2
fn mul_componentwise(&self, rhs: Fvec2) -> Fvec2
Multiply component by component.
Can also use the
*
operator.Source§fn div_componentwise(&self, rhs: Fvec2) -> Fvec2
fn div_componentwise(&self, rhs: Fvec2) -> Fvec2
Divide component by component.
Can also use the
/
operator.Source§fn min_componentwise(&self, rhs: Fvec2) -> Fvec2
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
fn max_componentwise(&self, rhs: Fvec2) -> Fvec2
For each lane, select the largest component of the two.
Source§fn min_reduce(&self) -> f32
fn min_reduce(&self) -> f32
Smallest of the four components.
Source§fn max_reduce(&self) -> f32
fn max_reduce(&self) -> f32
Largest of the four components.
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> 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