pub struct Coord {
pub x: Scalar,
pub y: Scalar,
}
Expand description
Point coordinate.
§Examples
use density_mesh_core::prelude::*;
let a = Coord::new(0.0, 0.0);
let b = Coord::new(2.0, 0.0);
assert_eq!((b - a).magnitude(), 2.0);
assert_eq!((b - a).sqr_magnitude(), 4.0);
assert_eq!((b - a).normalized(), Coord::new(1.0, 0.0));
assert_eq!((b - a).normalized().right(), Coord::new(0.0, -1.0));
assert_eq!(Coord::new(1.0, 0.0).dot(Coord::new(-1.0, 0.0)), -1.0);
Fields§
§x: Scalar
X value.
y: Scalar
Y value.
Implementations§
Source§impl Coord
impl Coord
Sourcepub fn sqr_magnitude(self) -> Scalar
pub fn sqr_magnitude(self) -> Scalar
Return squared length of the vector.
Sourcepub fn normalized(self) -> Self
pub fn normalized(self) -> Self
Return normalized vector (length equals to 1).
Sourcepub fn dot(self, other: Self) -> Scalar
pub fn dot(self, other: Self) -> Scalar
Returns dot product (cosinus of the angle between two vectors when both are normalized).
self 1 other
^
|
other 0 <---*---> 0 other
|
v
-1
other
§Arguments
other
- Other vector.
Sourcepub fn is_left_wrt_line(self, from: Self, to: Self) -> i8
pub fn is_left_wrt_line(self, from: Self, to: Self) -> i8
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Coord
impl<'de> Deserialize<'de> for Coord
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Coord
impl StructuralPartialEq for Coord
Auto Trait Implementations§
impl Freeze for Coord
impl RefUnwindSafe for Coord
impl Send for Coord
impl Sync for Coord
impl Unpin for Coord
impl UnwindSafe for Coord
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