Point

Struct Point 

Source
#[repr(C)]
pub struct Point<X, Y = X> { pub x: X, pub y: Y, }
Expand description

The Point implementation is designed a generic, 2-dimensional point object used to define coordinates, vectors, or positions in a 2D space.

Fields§

§x: X§y: Y

Implementations§

Source§

impl<X, Y> Point<X, Y>

Source

pub const fn new(x: X, y: Y) -> Self

Creates a new Point.

Source

pub fn from_tuple((x, y): (X, Y)) -> Self

create a new instance from the given 2-tuple

Source

pub const fn x(&self) -> &X

returns a reference to the x coordinate.

Source

pub const fn x_mut(&mut self) -> &mut X

returns a mutable reference to the x coordinate.

Source

pub const fn y(&self) -> &Y

returns a reference to the y coordinate.

Source

pub const fn y_mut(&mut self) -> &mut Y

returns a mutable reference to the y coordinate.

Source

pub const fn replace_x(&mut self, x: X) -> X

replace the x value, returning the old value.

Source

pub const fn replace_y(&mut self, y: Y) -> Y

replace the y value, returning the old value.

Source

pub fn set_x(&mut self, x: X)

set the x value

Source

pub fn set_y(&mut self, y: Y)

set the y value

Source

pub fn with_x<X2>(self, x: X2) -> Point<X2, Y>

consumes the current instance to create another with the given x value.

Source

pub fn with_y<Y2>(self, y: Y2) -> Point<X, Y2>

consumes the current instance to create another with the given y value.

Source

pub const fn as_view(&self) -> Point<&X, &Y>

returns an owned view of the point

Source

pub const fn as_mut_view(&mut self) -> Point<&mut X, &mut Y>

returns a view of the Point containing mutable references to the inner values.

Source

pub const fn as_tuple(&self) -> (&X, &Y)

returns a 2-tuple containing references to the inner values.

Source

pub fn into_tuple(self) -> (X, Y)

consumes the caller to convert the object into a 2-tuple.

Source§

impl<'a, X, Y> Point<&'a X, &'a Y>

Source

pub fn cloned(&self) -> Point<X, Y>
where X: Clone, Y: Clone,

returns an new instance of the Point with cloned values

Source

pub const fn copied(&self) -> Point<X, Y>
where X: Copy, Y: Copy,

return a new instance of the Point with copied values

Source§

impl<'a, X, Y> Point<&'a mut X, &'a mut Y>

Source

pub fn cloned(&self) -> Point<X, Y>
where X: Clone, Y: Clone,

returns an new instance of the Point with cloned values

Source

pub const fn copied(&self) -> Point<X, Y>
where X: Copy, Y: Copy,

return a new instance of the Point with copied values

Trait Implementations§

Source§

impl<X: Clone, Y: Clone> Clone for Point<X, Y>

Source§

fn clone(&self) -> Point<X, Y>

Returns a duplicate 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<X: Debug, Y: Debug> Debug for Point<X, Y>

Source§

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

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

impl<X: Default, Y: Default> Default for Point<X, Y>

Source§

fn default() -> Point<X, Y>

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

impl<X> From<[X; 2]> for Point<X, X>

Source§

fn from([x, y]: [X; 2]) -> Self

Converts to this type from the input type.
Source§

impl<X, Y> From<(X, Y)> for Point<X, Y>

Source§

fn from((x, y): (X, Y)) -> Self

Converts to this type from the input type.
Source§

impl<X> From<Point<X>> for [X; 2]

Source§

fn from(point: Point<X, X>) -> Self

Converts to this type from the input type.
Source§

impl<X, Y> From<Point<X, Y>> for (X, Y)

Source§

fn from(point: Point<X, Y>) -> Self

Converts to this type from the input type.
Source§

impl<X: Hash, Y: Hash> Hash for Point<X, Y>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<X: Ord, Y: Ord> Ord for Point<X, Y>

Source§

fn cmp(&self, other: &Point<X, Y>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<X, Y> PartialEq<(X, Y)> for Point<X, Y>
where X: PartialEq, Y: PartialEq,

Source§

fn eq(&self, (x, y): &(X, Y)) -> 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<X, Y> PartialEq<Point<X, Y>> for (X, Y)
where X: PartialEq, Y: PartialEq,

Source§

fn eq(&self, point: &Point<X, Y>) -> 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<X: PartialEq, Y: PartialEq> PartialEq for Point<X, Y>

Source§

fn eq(&self, other: &Point<X, Y>) -> 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<X: PartialOrd, Y: PartialOrd> PartialOrd for Point<X, Y>

Source§

fn partial_cmp(&self, other: &Point<X, Y>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<X: Copy, Y: Copy> Copy for Point<X, Y>

Source§

impl<X: Eq, Y: Eq> Eq for Point<X, Y>

Source§

impl<X, Y> StructuralPartialEq for Point<X, Y>

Auto Trait Implementations§

§

impl<X, Y> Freeze for Point<X, Y>
where X: Freeze, Y: Freeze,

§

impl<X, Y> RefUnwindSafe for Point<X, Y>

§

impl<X, Y> Send for Point<X, Y>
where X: Send, Y: Send,

§

impl<X, Y> Sync for Point<X, Y>
where X: Sync, Y: Sync,

§

impl<X, Y> Unpin for Point<X, Y>
where X: Unpin, Y: Unpin,

§

impl<X, Y> UnwindSafe for Point<X, Y>
where X: UnwindSafe, Y: UnwindSafe,

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.