pub struct Vector2 {
pub x: f64,
pub y: f64,
}Expand description
A two-dimensional vector.
§Examples
use use_vector::Vector2;
let vector = Vector2::new(3.0, 4.0);
assert_eq!(vector.magnitude(), 5.0);Fields§
§x: f64The x component.
y: f64The y component.
Implementations§
Source§impl Vector2
impl Vector2
Sourcepub fn dot(self, other: Self) -> f64
pub fn dot(self, other: Self) -> f64
Returns the dot product with other.
§Examples
use use_vector::Vector2;
let a = Vector2::new(1.0, 2.0);
let b = Vector2::new(3.0, 4.0);
assert_eq!(a.dot(b), 11.0);Sourcepub fn magnitude_squared(self) -> f64
pub fn magnitude_squared(self) -> f64
Returns the squared Euclidean magnitude.
Sourcepub fn normalize(self) -> Option<Self>
pub fn normalize(self) -> Option<Self>
Returns a normalized vector when the magnitude is finite and non-zero.
Returns None for zero vectors or vectors with non-finite magnitude.
§Examples
use use_vector::Vector2;
let unit = Vector2::new(3.0, 4.0)
.normalize()
.expect("non-zero finite vector should normalize");
assert!((unit.x - 0.6).abs() < 1.0e-12);
assert!((unit.y - 0.8).abs() < 1.0e-12);Sourcepub fn distance(self, other: Self) -> f64
pub fn distance(self, other: Self) -> f64
Returns the Euclidean distance to other.
§Examples
use use_vector::Vector2;
let start = Vector2::ZERO;
let end = Vector2::new(3.0, 4.0);
assert_eq!(start.distance(end), 5.0);Sourcepub fn distance_squared(self, other: Self) -> f64
pub fn distance_squared(self, other: Self) -> f64
Returns the squared Euclidean distance to other.
Trait Implementations§
impl Copy for Vector2
impl StructuralPartialEq for Vector2
Auto Trait Implementations§
impl Freeze for Vector2
impl RefUnwindSafe for Vector2
impl Send for Vector2
impl Sync for Vector2
impl Unpin for Vector2
impl UnsafeUnpin for Vector2
impl UnwindSafe for Vector2
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