pub struct PointN<N>(pub N);Expand description
An N-dimensional point (where N=2 or N=3), which is usually just a primitive array like
[i32; 2] or [i32; 3]. It is most convenient to construct points of any dimension as:
use building_blocks_core::PointN;
let p2 = PointN([1, 2]); // 2D
let p3 = PointN([1, 2, 3]); // 3DPoints support basic linear algebraic operations such as addition, subtraction, scalar multiplication, and scalar division.
let p1 = PointN([1, 2]);
let p2 = PointN([3, 4]);
assert_eq!(p1 + p2, PointN([4, 6]));
assert_eq!(p1 - p2, PointN([-2, -2]));
assert_eq!(p1 * 2, PointN([2, 4]));
assert_eq!(p1 / 2, PointN([0, 1]));
// Also some component-wise operations.
assert_eq!(p1 * p2, PointN([3, 8]));
assert_eq!(p1 / p2, PointN([0, 0]));
assert_eq!(p2 / p1, PointN([3, 2]));There is also a partial order defined on points which says that a point A is greater than a point B if and only if all of the components of point A are greater than point B. This is useful for easily checking is a point is inside of the extent between two other points:
let min = PointN([0, 0, 0]);
let least_upper_bound = PointN([3, 3, 3]);
let p = PointN([0, 1, 2]);
assert!(min <= p && p < least_upper_bound);Tuple Fields§
§0: NImplementations§
Source§impl PointN<[i32; 2]>
impl PointN<[i32; 2]>
pub const SQUARE_CORNER_OFFSETS: [Self; 4] = _
pub const VON_NEUMANN_OFFSETS: [Self; 4] = _
pub const MOORE_OFFSETS: [Self; 8] = _
Source§impl<T> PointN<[T; 3]>where
T: Copy,
impl<T> PointN<[T; 3]>where
T: Copy,
pub fn axis_component(self, axis: Axis3) -> T
pub fn x(self) -> T
pub fn y(self) -> T
pub fn z(self) -> T
pub fn xy(self) -> Point2<T>
pub fn yx(self) -> Point2<T>
pub fn yz(self) -> Point2<T>
pub fn zy(self) -> Point2<T>
pub fn zx(self) -> Point2<T>
pub fn xz(self) -> Point2<T>
pub fn yzx(self) -> Self
pub fn zxy(self) -> Self
pub fn zyx(self) -> Self
Source§impl PointN<[i32; 3]>
impl PointN<[i32; 3]>
pub const CUBE_CORNER_OFFSETS: [Self; 8] = _
pub const VON_NEUMANN_OFFSETS: [Self; 6] = _
pub const MOORE_OFFSETS: [Self; 26] = _
Trait Implementations§
Source§impl<T> AddAssign<PointN<T>> for ExtentN<T>
impl<T> AddAssign<PointN<T>> for ExtentN<T>
Source§fn add_assign(&mut self, rhs: PointN<T>)
fn add_assign(&mut self, rhs: PointN<T>)
Performs the
+= operation. Read moreSource§impl<N> AddAssign for PointN<N>
impl<N> AddAssign for PointN<N>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreSource§impl<'de, N> Deserialize<'de> for PointN<N>where
N: Deserialize<'de>,
impl<'de, N> Deserialize<'de> for PointN<N>where
N: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<N> FloatPoint<N> for PointN<N>
impl<N> FloatPoint<N> for PointN<N>
Source§impl<T> SubAssign<PointN<T>> for ExtentN<T>
impl<T> SubAssign<PointN<T>> for ExtentN<T>
Source§fn sub_assign(&mut self, rhs: PointN<T>)
fn sub_assign(&mut self, rhs: PointN<T>)
Performs the
-= operation. Read moreSource§impl<N> SubAssign for PointN<N>
impl<N> SubAssign for PointN<N>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreimpl<N: Copy> Copy for PointN<N>
impl<N: Eq> Eq for PointN<N>
impl<N> StructuralPartialEq for PointN<N>
Auto Trait Implementations§
impl<N> Freeze for PointN<N>where
N: Freeze,
impl<N> RefUnwindSafe for PointN<N>where
N: RefUnwindSafe,
impl<N> Send for PointN<N>where
N: Send,
impl<N> Sync for PointN<N>where
N: Sync,
impl<N> Unpin for PointN<N>where
N: Unpin,
impl<N> UnwindSafe for PointN<N>where
N: 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.