building_blocks_core::point

Struct PointN

Source
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§

Source§

impl<T> PointN<[T; 2]>

Source

pub fn x_mut(&mut self) -> &mut T

Source

pub fn y_mut(&mut self) -> &mut T

Source

pub fn axis_component_mut(&mut self, axis: Axis2) -> &mut T

Source§

impl<T> PointN<[T; 2]>
where T: Copy,

Source

pub fn axis_component(self, axis: Axis2) -> T

Source

pub fn x(self) -> T

Source

pub fn y(self) -> T

Source

pub fn yx(self) -> Self

Source§

impl PointN<[i32; 2]>

Source

pub const SQUARE_CORNER_OFFSETS: [Self; 4] = _

Source

pub const VON_NEUMANN_OFFSETS: [Self; 4] = _

Source

pub const MOORE_OFFSETS: [Self; 8] = _

Source§

impl PointN<[f32; 2]>

Source

pub fn in_pixel(self) -> Point2i

Returns the coordinates of the pixel containing self.

Source§

impl<T> PointN<[T; 3]>

Source

pub fn x_mut(&mut self) -> &mut T

Source

pub fn y_mut(&mut self) -> &mut T

Source

pub fn z_mut(&mut self) -> &mut T

Source

pub fn axis_component_mut(&mut self, axis: Axis3) -> &mut T

Source§

impl<T> PointN<[T; 3]>
where T: Copy,

Source

pub fn axis_component(self, axis: Axis3) -> T

Source

pub fn x(self) -> T

Source

pub fn y(self) -> T

Source

pub fn z(self) -> T

Source

pub fn xy(self) -> Point2<T>

Source

pub fn yx(self) -> Point2<T>

Source

pub fn yz(self) -> Point2<T>

Source

pub fn zy(self) -> Point2<T>

Source

pub fn zx(self) -> Point2<T>

Source

pub fn xz(self) -> Point2<T>

Source

pub fn yzx(self) -> Self

Source

pub fn zxy(self) -> Self

Source

pub fn zyx(self) -> Self

Source§

impl<T> PointN<[T; 3]>
where T: Copy + Mul<Output = T> + Sub<Output = T>,

Source

pub fn cross(self, other: Self) -> Self

Source§

impl PointN<[i32; 3]>

Source

pub const CUBE_CORNER_OFFSETS: [Self; 8] = _

Source

pub const VON_NEUMANN_OFFSETS: [Self; 6] = _

Source

pub const MOORE_OFFSETS: [Self; 26] = _

Source§

impl PointN<[f32; 3]>

Source

pub fn in_voxel(self) -> Point3i

Returns the coordinates of the voxel containing self.

Source§

impl<N> PointN<N>
where Self: MapComponents,

Source

pub fn signum(self) -> Self
where <Self as MapComponents>::Scalar: Signed,

Trait Implementations§

Source§

impl<N> Abs for PointN<N>
where Self: MapComponents, <Self as MapComponents>::Scalar: Signed,

Source§

fn abs(self) -> Self

Source§

impl<T> Add<PointN<T>> for ExtentN<T>
where PointN<T>: Add<Output = PointN<T>>,

Source§

type Output = ExtentN<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: PointN<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<N, T> Add for PointN<N>
where Self: MapComponents<Scalar = T>, T: Add<Output = T>,

Source§

type Output = PointN<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> AddAssign<PointN<T>> for ExtentN<T>
where Self: Copy + Add<PointN<T>, Output = ExtentN<T>>,

Source§

fn add_assign(&mut self, rhs: PointN<T>)

Performs the += operation. Read more
Source§

impl<N> AddAssign for PointN<N>
where Self: Copy + Add<Output = Self>,

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<N: Clone> Clone for PointN<N>

Source§

fn clone(&self) -> PointN<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<N: Debug> Debug for PointN<N>

Source§

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

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

impl<N: Default> Default for PointN<N>

Source§

fn default() -> PointN<N>

Returns the “default value” for a type. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<N> FloatPoint<N> for PointN<N>
where Self: IntoIntegerPoint + Point<Scalar = f32>,

Source§

fn round(self) -> Self

Source§

fn floor(self) -> Self

Source§

fn ceil(self) -> Self

Source§

fn fract(self) -> Self

Source§

fn floor_int(self) -> Self::IntPoint

Ensures that you floor before casting to integers, since this is not the default behavior for negative integers.
Source§

impl<T> From<PointN<[T; 2]>> for Point2<T>
where T: Clone,

Source§

fn from(p: Point2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<PointN<[T; 2]>> for Vector2<T>
where T: Clone,

Source§

fn from(p: Point2<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<PointN<[T; 3]>> for Point3<T>
where T: Clone,

Source§

fn from(p: Point3<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<PointN<[T; 3]>> for Vector3<T>
where T: Clone,

Source§

fn from(p: Point3<T>) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 2]>> for Vector2<f32>

Source§

fn from(p: Point2f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 2]>> for Point2<f32>

Source§

fn from(p: Point2f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 2]>> for Vec2

Source§

fn from(p: Point2f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 3]>> for Vector3<f32>

Source§

fn from(p: Point3f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 3]>> for Point3<f32>

Source§

fn from(p: Point3f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 3]>> for Vec3

Source§

fn from(p: Point3f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[f32; 3]>> for Vec3A

Source§

fn from(p: Point3f) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 2]>> for Vector2<f32>

Source§

fn from(p: Point2i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 2]>> for Vector2<i32>

Source§

fn from(p: Point2i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 2]>> for Point2<f32>

Source§

fn from(p: Point2i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 2]>> for Point2<i32>

Source§

fn from(p: Point2i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 2]>> for Point2f

Source§

fn from(p: Point2i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 3]>> for Vector3<f32>

Source§

fn from(p: Point3i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 3]>> for Vector3<i32>

Source§

fn from(p: Point3i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 3]>> for Point3<f32>

Source§

fn from(p: Point3i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 3]>> for Point3<i32>

Source§

fn from(p: Point3i) -> Self

Converts to this type from the input type.
Source§

impl From<PointN<[i32; 3]>> for Point3f

Source§

fn from(p: Point3i) -> Self

Converts to this type from the input type.
Source§

impl<N: Hash> Hash for PointN<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 Mul<PointN<[f32; 2]>> for f32

Source§

type Output = PointN<[f32; 2]>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Point2f) -> Point2f

Performs the * operation. Read more
Source§

impl Mul<PointN<[f32; 3]>> for f32

Source§

type Output = PointN<[f32; 3]>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Point3f) -> Point3f

Performs the * operation. Read more
Source§

impl Mul<PointN<[i32; 2]>> for i32

Source§

type Output = PointN<[i32; 2]>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Point2i) -> Point2i

Performs the * operation. Read more
Source§

impl Mul<PointN<[i32; 3]>> for i32

Source§

type Output = PointN<[i32; 3]>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Point3i) -> Point3i

Performs the * operation. Read more
Source§

impl<T> Mul<PointN<T>> for ExtentN<T>
where PointN<T>: Copy + Mul<Output = PointN<T>>,

Source§

type Output = ExtentN<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: PointN<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<N> Neg for PointN<N>
where Self: Copy + Sub<Output = Self> + Zero,

Source§

type Output = PointN<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<N: PartialEq> PartialEq for PointN<N>

Source§

fn eq(&self, other: &PointN<N>) -> 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<N> Serialize for PointN<N>
where N: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sub<PointN<T>> for ExtentN<T>
where PointN<T>: Sub<Output = PointN<T>>,

Source§

type Output = ExtentN<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: PointN<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<N, T> Sub for PointN<N>
where Self: MapComponents<Scalar = T>, T: Sub<Output = T>,

Source§

type Output = PointN<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> SubAssign<PointN<T>> for ExtentN<T>
where Self: Copy + Sub<PointN<T>, Output = ExtentN<T>>,

Source§

fn sub_assign(&mut self, rhs: PointN<T>)

Performs the -= operation. Read more
Source§

impl<N> SubAssign for PointN<N>
where Self: Copy + Sub<Output = Self>,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<N> Zero for PointN<N>
where Self: Point + ConstZero,

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<N: Copy> Copy for PointN<N>

Source§

impl<N: Eq> Eq for PointN<N>

Source§

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> 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 u8)

🔬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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Lerp for T
where T: Sub<Output = T> + Copy + Add<Output = T> + Mul<Output = T> + One,

Source§

fn lerp(&self, other: T, factor: T) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: Copy + PartialEq + Debug + Any,

Source§

fn inlined_clone(&self) -> T

Performance hack: Clone doesn’t get inlined for Copy types in debug mode, so make it inline anyway.
Source§

fn is<T>() -> bool
where T: Scalar,

Tests if Self the same as the type T Read more
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,