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<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) -> PointN<[T; 2]>
pub fn yx(self) -> PointN<[T; 2]>
pub fn yz(self) -> PointN<[T; 2]>
pub fn zy(self) -> PointN<[T; 2]>
pub fn zx(self) -> PointN<[T; 2]>
pub fn xz(self) -> PointN<[T; 2]>
pub fn yzx(self) -> PointN<[T; 3]>
pub fn zxy(self) -> PointN<[T; 3]>
pub fn zyx(self) -> PointN<[T; 3]>
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: PointN<N>)
fn add_assign(&mut self, rhs: PointN<N>)
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<PointN<N>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<PointN<N>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> Distance for PointN<[T; 2]>
impl<T> Distance for PointN<[T; 2]>
Source§fn l1_distance(self, other: PointN<[T; 2]>) -> T
fn l1_distance(self, other: PointN<[T; 2]>) -> T
The L1 distance between points.
Source§fn l2_distance_squared(self, other: PointN<[T; 2]>) -> T
fn l2_distance_squared(self, other: PointN<[T; 2]>) -> T
The square of the L2 (Euclidean) distance between points.
Source§impl<T> Distance for PointN<[T; 3]>
impl<T> Distance for PointN<[T; 3]>
Source§fn l1_distance(self, other: PointN<[T; 3]>) -> T
fn l1_distance(self, other: PointN<[T; 3]>) -> T
The L1 distance between points.
Source§fn l2_distance_squared(self, other: PointN<[T; 3]>) -> T
fn l2_distance_squared(self, other: PointN<[T; 3]>) -> T
The square of the L2 (Euclidean) distance between points.
Source§impl<T> DotProduct for PointN<[T; 2]>
impl<T> DotProduct for PointN<[T; 2]>
Source§impl<T> DotProduct for PointN<[T; 3]>
impl<T> DotProduct for PointN<[T; 3]>
Source§impl<N> FloatPoint<N> for PointN<N>
impl<N> FloatPoint<N> for PointN<N>
Source§impl<N, T> ForEach<N, PointN<N>> for AmbientExtent<N, T>
impl<N, T> ForEach<N, PointN<N>> for AmbientExtent<N, T>
Source§impl<Delegate, N, T, Bldr, Store> ForEach<N, PointN<N>> for ChunkMapLodView<Delegate>where
Delegate: Deref<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
Bldr: ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: ForEach<N, PointN<N>, Item = T>,
T: Clone,
Store: ChunkReadStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
impl<Delegate, N, T, Bldr, Store> ForEach<N, PointN<N>> for ChunkMapLodView<Delegate>where
Delegate: Deref<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
Bldr: ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: ForEach<N, PointN<N>, Item = T>,
T: Clone,
Store: ChunkReadStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
Source§impl<'a, N, Chan> ForEachMut<'a, N, PointN<N>> for Array<N, Chan>
impl<'a, N, Chan> ForEachMut<'a, N, PointN<N>> for Array<N, Chan>
Source§impl<'a, Delegate, N, Mut, MutPtr> ForEachMut<'a, N, PointN<N>> for ChunkMapLodView<Delegate>where
ChunkMapLodView<Delegate>: ForEachMutPtr<N, PointN<N>, Item = MutPtr>,
MutPtr: IntoMultiMut<'a, MultiMut = Mut>,
impl<'a, Delegate, N, Mut, MutPtr> ForEachMut<'a, N, PointN<N>> for ChunkMapLodView<Delegate>where
ChunkMapLodView<Delegate>: ForEachMutPtr<N, PointN<N>, Item = MutPtr>,
MutPtr: IntoMultiMut<'a, MultiMut = Mut>,
type Item = Mut
fn for_each_mut( &'a mut self, extent: &ExtentN<N>, f: impl FnMut(PointN<N>, <ChunkMapLodView<Delegate> as ForEachMut<'a, N, PointN<N>>>::Item), )
Source§impl From<Matrix<f32, Const<nalgebra::::base::dimension::U2::{constant#0}>, Const<1>, ArrayStorage<f32, 2, 1>>> for PointN<[f32; 2]>
impl From<Matrix<f32, Const<nalgebra::::base::dimension::U2::{constant#0}>, Const<1>, ArrayStorage<f32, 2, 1>>> for PointN<[f32; 2]>
Source§impl From<Matrix<f32, Const<nalgebra::::base::dimension::U3::{constant#0}>, Const<1>, ArrayStorage<f32, 3, 1>>> for PointN<[f32; 3]>
impl From<Matrix<f32, Const<nalgebra::::base::dimension::U3::{constant#0}>, Const<1>, ArrayStorage<f32, 3, 1>>> for PointN<[f32; 3]>
Source§impl From<Matrix<i32, Const<nalgebra::::base::dimension::U2::{constant#0}>, Const<1>, ArrayStorage<i32, 2, 1>>> for PointN<[i32; 2]>
impl From<Matrix<i32, Const<nalgebra::::base::dimension::U2::{constant#0}>, Const<1>, ArrayStorage<i32, 2, 1>>> for PointN<[i32; 2]>
Source§impl From<Matrix<i32, Const<nalgebra::::base::dimension::U3::{constant#0}>, Const<1>, ArrayStorage<i32, 3, 1>>> for PointN<[i32; 3]>
impl From<Matrix<i32, Const<nalgebra::::base::dimension::U3::{constant#0}>, Const<1>, ArrayStorage<i32, 3, 1>>> for PointN<[i32; 3]>
Source§impl<'a, Delegate, N, T, Bldr, Store> Get<PointN<N>> for ChunkMapLodView<Delegate>where
Delegate: Deref<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
T: Clone,
Bldr: ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: Get<PointN<N>, Item = T>,
Store: ChunkReadStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
impl<'a, Delegate, N, T, Bldr, Store> Get<PointN<N>> for ChunkMapLodView<Delegate>where
Delegate: Deref<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
T: Clone,
Bldr: ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: Get<PointN<N>, Item = T>,
Store: ChunkReadStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
Source§impl<'a, Delegate, N, T, Bldr, Store, Mut> GetMut<'a, PointN<N>> for ChunkMapLodView<Delegate>where
T: 'a,
Delegate: DerefMut<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
Bldr: 'a + ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: GetMut<'a, PointN<N>, Item = Mut>,
Store: 'a + ChunkWriteStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
impl<'a, Delegate, N, T, Bldr, Store, Mut> GetMut<'a, PointN<N>> for ChunkMapLodView<Delegate>where
T: 'a,
Delegate: DerefMut<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
Bldr: 'a + ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: GetMut<'a, PointN<N>, Item = Mut>,
Store: 'a + ChunkWriteStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
Source§impl<'a, Delegate, N, T, Bldr, Store, Ref> GetRef<'a, PointN<N>> for ChunkMapLodView<Delegate>where
T: 'a,
Delegate: Deref<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
Bldr: 'a + ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: GetRef<'a, PointN<N>, Item = Ref>,
Store: 'a + ChunkReadStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
Ref: MultiRef<'a, Data = T>,
impl<'a, Delegate, N, T, Bldr, Store, Ref> GetRef<'a, PointN<N>> for ChunkMapLodView<Delegate>where
T: 'a,
Delegate: Deref<Target = ChunkMap<N, T, Bldr, Store>>,
PointN<N>: IntegerPoint<N>,
Bldr: 'a + ChunkMapBuilder<N, T>,
<<Bldr as ChunkMapBuilder<N, T>>::Chunk as Chunk>::Array: GetRef<'a, PointN<N>, Item = Ref>,
Store: 'a + ChunkReadStorage<N, <Bldr as ChunkMapBuilder<N, T>>::Chunk>,
Ref: MultiRef<'a, Data = T>,
Source§impl<T> MapComponents for PointN<[T; 2]>where
T: Copy,
impl<T> MapComponents for PointN<[T; 2]>where
T: Copy,
type Scalar = T
Source§fn map_components_unary(
self,
f: impl Fn(<PointN<[T; 2]> as MapComponents>::Scalar) -> <PointN<[T; 2]> as MapComponents>::Scalar,
) -> PointN<[T; 2]>
fn map_components_unary( self, f: impl Fn(<PointN<[T; 2]> as MapComponents>::Scalar) -> <PointN<[T; 2]> as MapComponents>::Scalar, ) -> PointN<[T; 2]>
Returns the point after applying
f component-wise.Source§fn map_components_binary(
self,
other: PointN<[T; 2]>,
f: impl Fn(<PointN<[T; 2]> as MapComponents>::Scalar, <PointN<[T; 2]> as MapComponents>::Scalar) -> <PointN<[T; 2]> as MapComponents>::Scalar,
) -> PointN<[T; 2]>
fn map_components_binary( self, other: PointN<[T; 2]>, f: impl Fn(<PointN<[T; 2]> as MapComponents>::Scalar, <PointN<[T; 2]> as MapComponents>::Scalar) -> <PointN<[T; 2]> as MapComponents>::Scalar, ) -> PointN<[T; 2]>
Returns the point after applying
f component-wise to both self and other in parallel.Source§impl<T> MapComponents for PointN<[T; 3]>where
T: Copy,
impl<T> MapComponents for PointN<[T; 3]>where
T: Copy,
type Scalar = T
Source§fn map_components_unary(
self,
f: impl Fn(<PointN<[T; 3]> as MapComponents>::Scalar) -> <PointN<[T; 3]> as MapComponents>::Scalar,
) -> PointN<[T; 3]>
fn map_components_unary( self, f: impl Fn(<PointN<[T; 3]> as MapComponents>::Scalar) -> <PointN<[T; 3]> as MapComponents>::Scalar, ) -> PointN<[T; 3]>
Returns the point after applying
f component-wise.Source§fn map_components_binary(
self,
other: PointN<[T; 3]>,
f: impl Fn(<PointN<[T; 3]> as MapComponents>::Scalar, <PointN<[T; 3]> as MapComponents>::Scalar) -> <PointN<[T; 3]> as MapComponents>::Scalar,
) -> PointN<[T; 3]>
fn map_components_binary( self, other: PointN<[T; 3]>, f: impl Fn(<PointN<[T; 3]> as MapComponents>::Scalar, <PointN<[T; 3]> as MapComponents>::Scalar) -> <PointN<[T; 3]> as MapComponents>::Scalar, ) -> PointN<[T; 3]>
Returns the point after applying
f component-wise to both self and other in parallel.Source§impl MinMaxComponent for PointN<[f32; 2]>
impl MinMaxComponent for PointN<[f32; 2]>
type Scalar = f32
fn min_component(self) -> <PointN<[f32; 2]> as MinMaxComponent>::Scalar
fn max_component(self) -> <PointN<[f32; 2]> as MinMaxComponent>::Scalar
Source§impl MinMaxComponent for PointN<[f32; 3]>
impl MinMaxComponent for PointN<[f32; 3]>
type Scalar = f32
fn min_component(self) -> <PointN<[f32; 3]> as MinMaxComponent>::Scalar
fn max_component(self) -> <PointN<[f32; 3]> as MinMaxComponent>::Scalar
Source§impl MinMaxComponent for PointN<[i32; 2]>
impl MinMaxComponent for PointN<[i32; 2]>
type Scalar = i32
fn min_component(self) -> <PointN<[i32; 2]> as MinMaxComponent>::Scalar
fn max_component(self) -> <PointN<[i32; 2]> as MinMaxComponent>::Scalar
Source§impl MinMaxComponent for PointN<[i32; 3]>
impl MinMaxComponent for PointN<[i32; 3]>
type Scalar = i32
fn min_component(self) -> <PointN<[i32; 3]> as MinMaxComponent>::Scalar
fn max_component(self) -> <PointN<[i32; 3]> as MinMaxComponent>::Scalar
Source§impl Neighborhoods for PointN<[i32; 2]>
impl Neighborhoods for PointN<[i32; 2]>
Source§impl Neighborhoods for PointN<[i32; 3]>
impl Neighborhoods for PointN<[i32; 3]>
Source§impl<T> PartialOrd for PointN<[T; 2]>where
T: Copy + PartialOrd,
impl<T> PartialOrd for PointN<[T; 2]>where
T: Copy + PartialOrd,
Source§impl<T> PartialOrd for PointN<[T; 3]>where
T: Copy + PartialOrd,
impl<T> PartialOrd for PointN<[T; 3]>where
T: Copy + PartialOrd,
Source§impl<N> Serialize for PointN<N>where
N: Serialize,
impl<N> Serialize for PointN<N>where
N: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
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: PointN<N>)
fn sub_assign(&mut self, rhs: PointN<N>)
Performs the
-= operation. Read moreimpl<N> Copy for PointN<N>where
N: Copy,
impl<N> Eq for PointN<N>where
N: Eq,
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> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§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.