#[repr(transparent)]pub struct Point<T, const N: usize = 2> {
pub array: [T; N],
}
Fields§
§array: [T; N]
Implementations§
source§impl<T, const N: usize> Point<T, N>
impl<T, const N: usize> Point<T, N>
pub const fn new(array: [T; N]) -> Point<T, N>
sourcepub fn new_nn(array: [T; N]) -> Point<NotNan<T>, N>where
T: FloatCore,
pub fn new_nn(array: [T; N]) -> Point<NotNan<T>, N>where
T: FloatCore,
§Panics
Panics if any of the inputs are NaN.
pub fn as_vec(&self) -> &Vector<T, N>
pub fn squared_euclidean_distance<F>(&self, rhs: &Point<T, N>) -> F
pub fn zero() -> Selfwhere
T: Sum,
pub fn map<U, F>(&self, f: F) -> Point<U, N>
pub fn cast<U>(&self) -> Point<U, N>
pub fn to_float(&self) -> Point<OrderedFloat<f64>, N>
source§impl<T: PolygonScalar> Point<T>
impl<T: PolygonScalar> Point<T>
pub fn cmp_distance_to(&self, p: &Point<T, 2>, q: &Point<T, 2>) -> Ordering
sourcepub fn orient(
p1: &Point<T, 2>,
p2: &Point<T, 2>,
p3: &Point<T, 2>,
) -> Orientation
pub fn orient( p1: &Point<T, 2>, p2: &Point<T, 2>, p3: &Point<T, 2>, ) -> Orientation
Determine the direction you have to turn if you walk from p1
to p2
to p3
.
For fixed-precision types (i8,i16,i32,i64,etc), this function is guaranteed to work for any input and never cause any arithmetic overflows.
§Examples
let p1 = Point::new([ 0, 0 ]);
let p2 = Point::new([ 0, 1 ]); // One unit above p1.
// (0,0) -> (0,1) -> (0,2) == Orientation::CoLinear
assert!(Point::orient(&p1, &p2, &Point::new([ 0, 2 ])).is_colinear());
// (0,0) -> (0,1) -> (-1,2) == Orientation::CounterClockWise
assert!(Point::orient(&p1, &p2, &Point::new([ -1, 2 ])).is_ccw());
// (0,0) -> (0,1) -> (1,2) == Orientation::ClockWise
assert!(Point::orient(&p1, &p2, &Point::new([ 1, 2 ])).is_cw());
pub fn orient_along_direction( p1: &Point<T, 2>, direction: Direction<'_, T, 2>, p2: &Point<T, 2>, ) -> Orientation
pub fn orient_along_vector( p1: &Point<T, 2>, vector: &Vector<T, 2>, p2: &Point<T, 2>, ) -> Orientation
pub fn orient_along_perp_vector( p1: &Point<T, 2>, vector: &Vector<T, 2>, p2: &Point<T, 2>, ) -> Orientation
pub fn all_colinear(pts: &[Point<T>]) -> bool
sourcepub fn ccw_cmp_around(&self, p: &Point<T, 2>, q: &Point<T, 2>) -> Ordering
pub fn ccw_cmp_around(&self, p: &Point<T, 2>, q: &Point<T, 2>) -> Ordering
Docs?
pub fn ccw_cmp_around_with( &self, z: &Vector<T, 2>, p: &Point<T, 2>, q: &Point<T, 2>, ) -> Ordering
Methods from Deref<Target = [T; N]>§
sourcepub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
🔬This is a nightly-only experimental API. (ascii_char
)
pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>
ascii_char
)Converts this array of bytes into an array of ASCII characters,
or returns None
if any of the characters is non-ASCII.
§Examples
sourcepub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
🔬This is a nightly-only experimental API. (ascii_char
)
pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]
ascii_char
)Converts this array of bytes into an array of ASCII characters, without checking whether they’re valid.
§Safety
Every byte in the array must be in 0..=127
, or else this is UB.
1.57.0 · sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the entire array. Equivalent to &s[..]
.
1.77.0 · sourcepub fn each_ref(&self) -> [&T; N]
pub fn each_ref(&self) -> [&T; N]
Borrows each element and returns an array of references with the same
size as self
.
§Example
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);
This method is particularly useful if combined with other methods, like
map
. This way, you can avoid moving the original
array if its elements are not Copy
.
sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬This is a nightly-only experimental API. (split_array
)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array
)Divides one array reference into two at an index.
The first will contain all indices from [0, M)
(excluding
the index M
itself) and the second will contain all
indices from [M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬This is a nightly-only experimental API. (split_array
)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array
)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M)
(excluding
the index N - M
itself) and the second will contain all
indices from [N - M, N)
(excluding the index N
itself).
§Panics
Panics if M > N
.
§Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
Trait Implementations§
source§impl<T, const N: usize> AddAssign<&Vector<T, N>> for Point<T, N>
impl<T, const N: usize> AddAssign<&Vector<T, N>> for Point<T, N>
source§fn add_assign(&mut self, other: &Vector<T, N>)
fn add_assign(&mut self, other: &Vector<T, N>)
+=
operation. Read moresource§impl<T, const N: usize> AddAssign<Vector<T, N>> for Point<T, N>
impl<T, const N: usize> AddAssign<Vector<T, N>> for Point<T, N>
source§fn add_assign(&mut self, other: Vector<T, N>)
fn add_assign(&mut self, other: Vector<T, N>)
+=
operation. Read moresource§impl<T, const N: usize> Distribution<Point<T, N>> for Standardwhere
Standard: Distribution<T>,
impl<T, const N: usize> Distribution<Point<T, N>> for Standardwhere
Standard: Distribution<T>,
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Point<T, N>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Point<T, N>
T
, using rng
as the source of randomness.source§fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
T
, using rng
as
the source of randomness. Read moresource§impl<'a, T, const N: usize> From<&'a Point<T, N>> for VectorView<'a, T, N>
impl<'a, T, const N: usize> From<&'a Point<T, N>> for VectorView<'a, T, N>
source§fn from(point: &Point<T, N>) -> VectorView<'_, T, N>
fn from(point: &Point<T, N>) -> VectorView<'_, T, N>
source§impl<T: TotalOrd, const N: usize> Ord for Point<T, N>
impl<T: TotalOrd, const N: usize> Ord for Point<T, N>
source§impl<T: TotalOrd, const N: usize> PartialOrd for Point<T, N>
impl<T: TotalOrd, const N: usize> PartialOrd for Point<T, N>
impl<T: Copy, const N: usize> Copy for Point<T, N>
impl<T: TotalOrd, const N: usize> Eq for Point<T, N>
Auto Trait Implementations§
impl<T, const N: usize> Freeze for Point<T, N>where
T: Freeze,
impl<T, const N: usize> RefUnwindSafe for Point<T, N>where
T: RefUnwindSafe,
impl<T, const N: usize> Send for Point<T, N>where
T: Send,
impl<T, const N: usize> Sync for Point<T, N>where
T: Sync,
impl<T, const N: usize> Unpin for Point<T, N>where
T: Unpin,
impl<T, const N: usize> UnwindSafe for Point<T, N>where
T: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)