rgeometry::data

Struct Point

source
#[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>

source

pub const fn new(array: [T; N]) -> Point<T, N>

source

pub fn new_nn(array: [T; N]) -> Point<NotNan<T>, N>
where T: FloatCore,

§Panics

Panics if any of the inputs are NaN.

source

pub fn as_vec(&self) -> &Vector<T, N>

source

pub fn squared_euclidean_distance<F>(&self, rhs: &Point<T, N>) -> F
where T: Clone + Into<F>, F: NumOps + Clone + Sum,

source

pub fn zero() -> Self
where T: Sum,

source

pub fn map<U, F>(&self, f: F) -> Point<U, N>
where T: Clone, F: Fn(T) -> U,

source

pub fn cast<U>(&self) -> Point<U, N>
where T: Clone + Into<U>,

source

pub fn to_float(&self) -> Point<OrderedFloat<f64>, N>
where T: Clone + Into<f64>,

source§

impl<T: PolygonScalar> Point<T>

source

pub fn cmp_distance_to(&self, p: &Point<T, 2>, q: &Point<T, 2>) -> Ordering

source

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());
source

pub fn orient_along_direction( p1: &Point<T, 2>, direction: Direction<'_, T, 2>, p2: &Point<T, 2>, ) -> Orientation

source

pub fn orient_along_vector( p1: &Point<T, 2>, vector: &Vector<T, 2>, p2: &Point<T, 2>, ) -> Orientation

source

pub fn orient_along_perp_vector( p1: &Point<T, 2>, vector: &Vector<T, 2>, p2: &Point<T, 2>, ) -> Orientation

source

pub fn all_colinear(pts: &[Point<T>]) -> bool

source

pub fn ccw_cmp_around(&self, p: &Point<T, 2>, q: &Point<T, 2>) -> Ordering

Docs?

source

pub fn ccw_cmp_around_with( &self, z: &Vector<T, 2>, p: &Point<T, 2>, q: &Point<T, 2>, ) -> Ordering

source§

impl<T> Point<T, 1>

source

pub fn x_coord(&self) -> &T

source§

impl<T> Point<T, 2>

source

pub fn x_coord(&self) -> &T

source

pub fn y_coord(&self) -> &T

source§

impl<T> Point<T, 3>

source

pub fn x_coord(&self) -> &T

source

pub fn y_coord(&self) -> &T

source

pub fn z_coord(&self) -> &T

Methods from Deref<Target = [T; N]>§

source

pub fn as_ascii(&self) -> Option<&[AsciiChar; N]>

🔬This is a nightly-only experimental API. (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
#![feature(ascii_char)]

const HEX_DIGITS: [std::ascii::Char; 16] =
    *b"0123456789abcdef".as_ascii().unwrap();

assert_eq!(HEX_DIGITS[1].as_str(), "1");
assert_eq!(HEX_DIGITS[10].as_str(), "a");
source

pub unsafe fn as_ascii_unchecked(&self) -> &[AsciiChar; N]

🔬This is a nightly-only experimental API. (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 · source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire array. Equivalent to &s[..].

1.77.0 · source

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.

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
source

pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])

🔬This is a nightly-only experimental API. (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, &[]);
}
source

pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])

🔬This is a nightly-only experimental API. (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<'a, 'b, T, const N: usize> Add<&'a Vector<T, N>> for &'b Point<T, N>
where T: Add<Output = T> + Clone,

source§

type Output = Point<T, N>

The resulting type after applying the + operator.
source§

fn add(self: &'b Point<T, N>, other: &'a Vector<T, N>) -> Self::Output

Performs the + operation. Read more
source§

impl<T, const N: usize> Add<&Vector<T, N>> for Point<T, N>
where T: Add<Output = T> + Clone,

source§

type Output = Point<T, N>

The resulting type after applying the + operator.
source§

fn add(self: Point<T, N>, other: &Vector<T, N>) -> Self::Output

Performs the + operation. Read more
source§

impl<T, const N: usize> Add<Vector<T, N>> for Point<T, N>
where T: Add<Output = T> + Clone,

source§

type Output = Point<T, N>

The resulting type after applying the + operator.
source§

fn add(self: Point<T, N>, other: Vector<T, N>) -> Self::Output

Performs the + operation. Read more
source§

impl<T, const N: usize> AddAssign<&Vector<T, N>> for Point<T, N>
where T: NumOps + Clone + AddAssign,

source§

fn add_assign(&mut self, other: &Vector<T, N>)

Performs the += operation. Read more
source§

impl<T, const N: usize> AddAssign<Vector<T, N>> for Point<T, N>
where T: NumOps + Clone + AddAssign,

source§

fn add_assign(&mut self, other: Vector<T, N>)

Performs the += operation. Read more
source§

impl<T: Clone, const N: usize> Clone for Point<T, N>

source§

fn clone(&self) -> Point<T, N>

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<T: Debug, const N: usize> Debug for Point<T, N>

source§

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

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

impl<T, const N: usize> Deref for Point<T, N>

source§

type Target = [T; N]

The resulting type after dereferencing.
source§

fn deref(&self) -> &[T; N]

Dereferences the value.
source§

impl<T, const N: usize> Distribution<Point<T, N>> for Standard

source§

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

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

fn sample_iter<R>(self, rng: R) -> DistIter<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) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
source§

impl<const N: usize> From<&Point<Ratio<BigInt>, N>> for Point<f64, N>

source§

fn from(point: &Point<BigRational, N>) -> Point<f64, N>

Converts to this type from the input type.
source§

impl<'a, T, const N: usize> From<&'a Point<T, N>> for &'a Vector<T, N>

source§

fn from(point: &Point<T, N>) -> &Vector<T, N>

Converts to this type from the input type.
source§

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>

Converts to this type from the input type.
source§

impl<const N: usize> From<&Point<f64, N>> for Point<BigRational, N>

source§

fn from(point: &Point<f64, N>) -> Point<BigRational, N>

Converts to this type from the input type.
source§

impl<T> From<(T, T)> for Point<T, 2>

source§

fn from(point: (T, T)) -> Point<T, 2>

Converts to this type from the input type.
source§

impl<const N: usize> From<Point<Ratio<BigInt>, N>> for Point<f64, N>

source§

fn from(point: Point<BigRational, N>) -> Point<f64, N>

Converts to this type from the input type.
source§

impl<T, const N: usize> From<Point<T, N>> for Vector<T, N>

source§

fn from(point: Point<T, N>) -> Vector<T, N>

Converts to this type from the input type.
source§

impl<const N: usize> From<Point<f64, N>> for Point<BigRational, N>

source§

fn from(point: Point<f64, N>) -> Point<BigRational, N>

Converts to this type from the input type.
source§

impl From<Point<i64>> for Point<BigInt, 2>

source§

fn from(point: Point<i64, 2>) -> Point<BigInt, 2>

Converts to this type from the input type.
source§

impl<T, const N: usize> From<Vector<T, N>> for Point<T, N>

source§

fn from(vector: Vector<T, N>) -> Point<T, N>

Converts to this type from the input type.
source§

impl<T: Hash, const N: usize> Hash for Point<T, N>

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<T, const N: usize> Index<usize> for Point<T, N>

source§

type Output = T

The returned type after indexing.
source§

fn index(&self, key: usize) -> &T

Performs the indexing (container[index]) operation. Read more
source§

impl<T, const N: usize> Mul<&Point<T, N>> for &Transform<T, N>
where T: TransformScalar,

source§

type Output = Point<T, N>

The resulting type after applying the * operator.
source§

fn mul(self, other: &Point<T, N>) -> Point<T, N>

Performs the * operation. Read more
source§

impl<T, const N: usize> Mul<Point<T, N>> for &Transform<T, N>
where T: TransformScalar,

source§

type Output = Point<T, N>

The resulting type after applying the * operator.
source§

fn mul(self, other: Point<T, N>) -> Point<T, N>

Performs the * operation. Read more
source§

impl<T, const N: usize> Mul<Point<T, N>> for Transform<T, N>
where T: TransformScalar,

source§

type Output = Point<T, N>

The resulting type after applying the * operator.
source§

fn mul(self, other: Point<T, N>) -> Point<T, N>

Performs the * operation. Read more
source§

impl<T: TotalOrd, const N: usize> Ord for Point<T, N>

source§

fn cmp(&self, other: &Self) -> 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: TotalOrd, const N: usize> PartialEq for Point<T, N>

source§

fn eq(&self, other: &Self) -> 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: TotalOrd, const N: usize> PartialOrd for Point<T, N>

source§

fn partial_cmp(&self, other: &Self) -> 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<'a, 'b, T, const N: usize> Sub<&'a Point<T, N>> for &'b Point<T, N>
where T: Sub<T, Output = T> + Clone,

source§

type Output = Vector<T, N>

The resulting type after applying the - operator.
source§

fn sub(self: &'b Point<T, N>, other: &'a Point<T, N>) -> Self::Output

Performs the - operation. Read more
source§

impl<T, const N: usize> Sub for Point<T, N>
where T: Sub<T, Output = T> + Clone,

source§

type Output = Vector<T, N>

The resulting type after applying the - operator.
source§

fn sub(self: Point<T, N>, other: Point<T, N>) -> Self::Output

Performs the - operation. Read more
source§

impl<T: TotalOrd, const N: usize> TotalOrd for Point<T, N>

source§

fn total_cmp(&self, other: &Self) -> Ordering

source§

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

source§

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

source§

impl<const N: usize> TryFrom<Point<f64, N>> for Point<NotNan<f64>, N>

source§

type Error = FloatIsNan

The type returned in the event of a conversion error.
source§

fn try_from(point: Point<f64, N>) -> Result<Point<NotNan<f64>, N>, FloatIsNan>

Performs the conversion.
source§

impl<T: Copy, const N: usize> Copy for Point<T, N>

source§

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> 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V