Struct Coord

Source
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

Source

pub fn new(x: Scalar, y: Scalar) -> Self

Create new point coordinate.

§Arguments
  • x - X value.
  • y - Y value.
Source

pub fn sqr_magnitude(self) -> Scalar

Return squared length of the vector.

Source

pub fn magnitude(self) -> Scalar

Return length of the vector.

Source

pub fn normalized(self) -> Self

Return normalized vector (length equals to 1).

Source

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.
Source

pub fn right(self) -> Self

Return right vector.

     ^
self |
     *---> right
Source

pub fn is_left_wrt_line(self, from: Self, to: Self) -> i8

Tells the side which this point occupy relative to the line.

§Arguments
  • from - Start point of the line.
  • to - End point of the line.
§Returns
  • 1 - Point lay on the left of the line.
  • 0 - Point lay on the line.
  • -1 - Point lay on the right of the line.

Trait Implementations§

Source§

impl Add<f32> for Coord

Source§

type Output = Coord

The resulting type after applying the + operator.
Source§

fn add(self, other: Scalar) -> Self

Performs the + operation. Read more
Source§

impl Add for Coord

Source§

type Output = Coord

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for Coord

Source§

fn clone(&self) -> Coord

Returns a copy 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 Coord

Source§

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

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

impl Default for Coord

Source§

fn default() -> Coord

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

impl<'de> Deserialize<'de> for Coord

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Div<f32> for Coord

Source§

type Output = Coord

The resulting type after applying the / operator.
Source§

fn div(self, other: Scalar) -> Self

Performs the / operation. Read more
Source§

impl Div for Coord

Source§

type Output = Coord

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
Source§

impl Mul<f32> for Coord

Source§

type Output = Coord

The resulting type after applying the * operator.
Source§

fn mul(self, other: Scalar) -> Self

Performs the * operation. Read more
Source§

impl Mul for Coord

Source§

type Output = Coord

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl Neg for Coord

Source§

type Output = Coord

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Coord

Source§

fn eq(&self, other: &Coord) -> 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 Serialize for Coord

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<f32> for Coord

Source§

type Output = Coord

The resulting type after applying the - operator.
Source§

fn sub(self, other: Scalar) -> Self

Performs the - operation. Read more
Source§

impl Sub for Coord

Source§

type Output = Coord

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl Copy for Coord

Source§

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> 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,