Struct Point2d

Source
pub struct Point2d<T = i64> {
    pub x: T,
    pub y: T,
}
Expand description

A 2d point where you can choose the type and thus precision of the x and y indices. By default uses i64 which is the world coordinate type.

Fields§

§x: T

x position

§y: T

y position

Implementations§

Source§

impl<C: Chunk> Point2d<GridIndex<C>>

Source

pub fn into_same_chunk_size<D: Chunk>(self) -> GridPoint<D>

When two Chunks have the same size, all their coordinates are trivially the same and we can convert them with just a compile-time check.

Source§

impl<T: Copy> Point2d<T>

Source

pub const fn splat(arg: T) -> Self

Set x and y to the same value

Source

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

Basic constructor for when struct constructors are too inconvenient

Source

pub fn map<U>(&self, f: impl Fn(T) -> U) -> Point2d<U>

Apply a closure to both x and y

Source

pub fn to(self, other: Self) -> Line<T>

Connect a line segment from this point to the argument.

Source§

impl<T: Neg<Output = T>> Point2d<T>

Source

pub fn perp(self) -> Self

Return the perpendicular (right facing) vector of the same length.

Source§

impl<T: Copy + Sub<Output = T> + Mul<Output = T> + Add<Output = T> + Abs> Point2d<T>

Source

pub fn dist_squared(self, center: Point2d<T>) -> T

The square of the distance between two points

Source

pub fn len_squared(self) -> T

The square of the distance between the origin (0, 0) and this point.

Source

pub fn manhattan_dist(self, city: Point2d<T>) -> T

The manhattan distance between two points.

Source

pub fn manhattan_len(&self) -> T

The manhattan distance to the origin.

Source§

impl Point2d<i64>

Source

pub const fn sub(self, rhs: Point2d) -> Point2d

Subtract two points element wise.

Source

pub const fn mul(self, rhs: Point2d) -> Point2d

Multiply two points element wise.

Source

pub fn to_ne_bytes(&self) -> [u8; 16]

Get the bytes of this point in native byte order.

Trait Implementations§

Source§

impl<T: Add<Output = T>> Add for Point2d<T>

Source§

type Output = Point2d<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Point2d<T>) -> Point2d<T>

Performs the + operation. Read more
Source§

impl<T: AddAssign> AddAssign for Point2d<T>

Source§

fn add_assign(&mut self, rhs: Point2d<T>)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for Point2d<T>

Source§

fn clone(&self) -> Point2d<T>

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<T: Debug> Debug for Point2d<T>

Source§

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

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

impl<T: Default> Default for Point2d<T>

Source§

fn default() -> Point2d<T>

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

impl<T> Distribution<Point2d<T>> for StandardUniform

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Point2d<T>

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl<T: DivAssign + Copy> Div<Point2d<T>> for Bounds<T>

Source§

type Output = Bounds<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Point2d<T>) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: DivAssign + Copy> Div<T> for Point2d<T>

Source§

type Output = Point2d<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Div<Output = T>> Div for Point2d<T>

Source§

type Output = Point2d<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Point2d<T>) -> Point2d<T>

Performs the / operation. Read more
Source§

impl<T: DivAssign + Copy> DivAssign<T> for Point2d<T>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T: DivAssign> DivAssign for Point2d<T>

Source§

fn div_assign(&mut self, rhs: Point2d<T>)

Performs the /= operation. Read more
Source§

impl From<Point2d<NonZero<u16>>> for Point2d

Source§

fn from(value: Point2d<NonZeroU16>) -> Self

Converts to this type from the input type.
Source§

impl<T: MulAssign + Copy> Mul<T> for Point2d<T>

Source§

type Output = Point2d<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Mul<Output = T>> Mul for Point2d<T>

Source§

type Output = Point2d<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Point2d<T>) -> Point2d<T>

Performs the * operation. Read more
Source§

impl<T: MulAssign + Copy> MulAssign<T> for Point2d<T>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T: MulAssign> MulAssign for Point2d<T>

Source§

fn mul_assign(&mut self, rhs: Point2d<T>)

Performs the *= operation. Read more
Source§

impl<T: Ord> Ord for Point2d<T>

Source§

fn cmp(&self, other: &Point2d<T>) -> 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<T: PartialEq> PartialEq for Point2d<T>

Source§

fn eq(&self, other: &Point2d<T>) -> 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<T: PartialOrd> PartialOrd for Point2d<T>

Source§

fn partial_cmp(&self, other: &Point2d<T>) -> 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<T: Sub<Output = T>> Sub for Point2d<T>

Source§

type Output = Point2d<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Point2d<T>) -> Point2d<T>

Performs the - operation. Read more
Source§

impl<T: SubAssign> SubAssign for Point2d<T>

Source§

fn sub_assign(&mut self, rhs: Point2d<T>)

Performs the -= operation. Read more
Source§

impl<T: Copy> Copy for Point2d<T>

Source§

impl<T: Eq> Eq for Point2d<T>

Source§

impl<T> StructuralPartialEq for Point2d<T>

Auto Trait Implementations§

§

impl<T> Freeze for Point2d<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Point2d<T>
where T: RefUnwindSafe,

§

impl<T> Send for Point2d<T>
where T: Send,

§

impl<T> Sync for Point2d<T>
where T: Sync,

§

impl<T> Unpin for Point2d<T>
where T: Unpin,

§

impl<T> UnwindSafe for Point2d<T>
where T: 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.