Struct building_blocks_core::point::PointN [−][src]
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]); // 3D
Points 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: N
Implementations
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
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
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
Auto Trait Implementations
impl<N> RefUnwindSafe for PointN<N> where
N: RefUnwindSafe,
impl<N> UnwindSafe for PointN<N> where
N: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.