Skip to main content

Coord2D

Struct Coord2D 

Source
pub struct Coord2D {
    pub x: f64,
    pub y: f64,
}
Expand description

A 2D point in continuous space.

Coord2D represents a position. Subtracting two points yields a CoordOffset (vector). Adding a vector to a point yields a new point.

use optic_core::*;

let a = Coord2D::from(100.0, 200.0);
let b = Coord2D::from(150.0, 180.0);
let d: CoordOffset = b - a;
let mid = a.lerp(b, 0.5);

Implements Components<f64, 2>.

Fields§

§x: f64§y: f64

Implementations§

Source§

impl Coord2D

Source

pub fn empty() -> Coord2D

The origin point (0, 0).

Source

pub fn from(x: f64, y: f64) -> Self

Construct from x, y coordinates.

Source

pub fn from_tup((x, y): (f64, f64)) -> Self

Construct from a tuple.

Source

pub fn is_inside(&self, size: Size2D) -> bool

True if the point lies within the rectangle (0, 0) to (size.w, size.h).

Source

pub fn distance_to(&self, other: Coord2D) -> f64

Euclidean distance to another point.

Source

pub fn midpoint(&self, other: Coord2D) -> Coord2D

Midpoint between two points.

Source

pub fn lerp(&self, other: Coord2D, t: f64) -> Coord2D

Linearly interpolate toward other by factor t (clamped 0..1).

Source

pub fn min(&self, other: Coord2D) -> Coord2D

Componentwise minimum.

Source

pub fn max(&self, other: Coord2D) -> Coord2D

Componentwise maximum.

Trait Implementations§

Source§

impl Add<CoordOffset> for Coord2D

Source§

type Output = Coord2D

The resulting type after applying the + operator.
Source§

fn add(self, rhs: CoordOffset) -> Coord2D

Performs the + operation. Read more
Source§

impl Clone for Coord2D

Source§

fn clone(&self) -> Coord2D

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Components<f64, 2> for Coord2D

Source§

fn to_array(self) -> [f64; 2]

Convert to an array of length N.
Source§

fn from_array(a: [f64; 2]) -> Self

Construct from an array of length N.
Source§

impl Copy for Coord2D

Source§

impl Debug for Coord2D

Source§

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

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

impl From<(f64, f64)> for Coord2D

Source§

fn from(t: (f64, f64)) -> Self

Converts to this type from the input type.
Source§

impl From<Coord2D> for [f64; 2]

Source§

fn from(c: Coord2D) -> Self

Converts to this type from the input type.
Source§

impl From<[f64; 2]> for Coord2D

Source§

fn from(a: [f64; 2]) -> Self

Converts to this type from the input type.
Source§

impl Sub for Coord2D

Source§

type Output = CoordOffset

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Coord2D) -> CoordOffset

Performs the - operation. Read more
Source§

impl Sub<CoordOffset> for Coord2D

Source§

type Output = Coord2D

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: CoordOffset) -> Coord2D

Performs the - operation. Read more

Auto Trait Implementations§

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.