#[repr(C)]pub struct Cube {
pub x: i32,
pub y: i32,
pub z: i32,
}Expand description
“A cube”, in this documentation, is a unit cube whose corners’ coordinates are integers. This type identifies such a cube by the coordinates of its most negative corner.
The valid coordinate range is that of GridCoordinate.
Note, however, that in most applications, cubes with lower corner coordinates equal to
GridCoordinate::MAX will not be valid, because their other corners are out of
range. The Cube type does not enforce this, because it would be unergonomic to
require fallible conversions there. Instead, the conversion from Cube to its
bounding GridAab may panic. Generally, this should be avoided by checking
the cube with GridAab::contains_cube() on some existing GridAab.
Considered in continuous space (real, or floating-point, coordinates), the ranges of coordinates a cube contains are half-open intervals: lower inclusive and upper exclusive.
§Representation
This struct is guaranteed to be three i32 without padding, and so may be reinterpreted
as any type of identical layout such as [i32; 3].
§Why have a dedicated type for this?
- Primarily, to avoid confusion between points (zero size) and cubes (nonzero size) that causes off-by-one errors when rotating objects.
- To provide convenient methods for operations on cubes that aren’t natural operations on points.
- To reduce our dependence on external math libraries as part of our API.
Fields§
§x: i32§y: i32§z: i32Implementations§
Source§impl Cube
impl Cube
Sourcepub const ORIGIN: Self
pub const ORIGIN: Self
Equal to Cube::new(0, 0, 0).
Note that this is not a box centered on the coordinate origin.
Sourcepub const fn new(
x: GridCoordinate,
y: GridCoordinate,
z: GridCoordinate,
) -> Self
pub const fn new( x: GridCoordinate, y: GridCoordinate, z: GridCoordinate, ) -> Self
Construct Cube { x, y, z } from the given coordinates.
Sourcepub fn containing(point: FreePoint) -> Option<Self>
pub fn containing(point: FreePoint) -> Option<Self>
Convert a point in space to the unit cube that encloses it.
Such cubes are defined to be half-open intervals on each axis; that is, an integer coordinate is counted as part of the cube extending positively from that coordinate.
If the point coordinates are outside of the numeric range of GridCoordinate,
returns None.
use all_is_cubes::math::{FreePoint, Cube};
assert_eq!(Cube::containing(FreePoint::new(1.0, 1.5, -2.5)), Some(Cube::new(1, 1, -3)));Sourcepub fn lower_bounds(self) -> GridPoint
pub fn lower_bounds(self) -> GridPoint
Returns the corner of this cube with the most negative coordinates.
Sourcepub fn upper_bounds(self) -> GridPoint
pub fn upper_bounds(self) -> GridPoint
Returns the corner of this cube with the most positive coordinates.
Panics if self has any coordinates equal to GridCoordinate::MAX.
Generally, that should be avoided by checking the cube with
GridAab::contains_cube() on some existing GridAab before calling this
method.
Sourcepub fn grid_aab(self) -> GridAab
pub fn grid_aab(self) -> GridAab
Constructs a GridAab with a volume of 1, containing this cube.
Panics if self has any coordinates equal to GridCoordinate::MAX.
Generally, that should be avoided by checking the cube with
GridAab::contains_cube() on some existing GridAab before calling this
method.
Sourcepub fn aab(self) -> Aab
pub fn aab(self) -> Aab
Returns the bounding box in floating-point coordinates containing this cube.
use all_is_cubes::math::{Aab, Cube};
assert_eq!(
Cube::new(10, 20, -30).aab(),
Aab::new(10.0, 11.0, 20.0, 21.0, -30.0, -29.0)
);Sourcepub fn checked_add(self, v: GridVector) -> Option<Self>
pub fn checked_add(self, v: GridVector) -> Option<Self>
Componentwise GridCoordinate::checked_add().
Sourcepub fn map(self, f: impl FnMut(GridCoordinate) -> GridCoordinate) -> Self
pub fn map(self, f: impl FnMut(GridCoordinate) -> GridCoordinate) -> Self
Apply a function to each coordinate independently.
If a different return type is desired, use .lower_bounds().map(f) instead.
Trait Implementations§
Source§impl AddAssign<Face6> for Cube
impl AddAssign<Face6> for Cube
Source§fn add_assign(&mut self, rhs: Face6)
fn add_assign(&mut self, rhs: Face6)
+= operation. Read moreSource§impl AddAssign<Vector3D<i32, Cube>> for Cube
impl AddAssign<Vector3D<i32, Cube>> for Cube
Source§fn add_assign(&mut self, rhs: GridVector)
fn add_assign(&mut self, rhs: GridVector)
+= operation. Read moreSource§impl AsMut<[i32; 3]> for Cube
impl AsMut<[i32; 3]> for Cube
Source§fn as_mut(&mut self) -> &mut [GridCoordinate; 3]
fn as_mut(&mut self) -> &mut [GridCoordinate; 3]
Source§impl AsRef<[i32; 3]> for Cube
impl AsRef<[i32; 3]> for Cube
Source§fn as_ref(&self) -> &[GridCoordinate; 3]
fn as_ref(&self) -> &[GridCoordinate; 3]
Source§impl BorrowMut<[i32; 3]> for Cube
impl BorrowMut<[i32; 3]> for Cube
Source§fn borrow_mut(&mut self) -> &mut [GridCoordinate; 3]
fn borrow_mut(&mut self) -> &mut [GridCoordinate; 3]
Source§impl Fmt<ConciseDebug> for Cube
impl Fmt<ConciseDebug> for Cube
Source§impl From<[i32; 3]> for Cube
impl From<[i32; 3]> for Cube
Source§fn from([x, y, z]: [GridCoordinate; 3]) -> Self
fn from([x, y, z]: [GridCoordinate; 3]) -> Self
Source§impl SubAssign<Vector3D<i32, Cube>> for Cube
impl SubAssign<Vector3D<i32, Cube>> for Cube
Source§fn sub_assign(&mut self, rhs: GridVector)
fn sub_assign(&mut self, rhs: GridVector)
-= operation. Read moreimpl Copy for Cube
impl Eq for Cube
impl Pod for Cube
impl StructuralPartialEq for Cube
Auto Trait Implementations§
impl Freeze for Cube
impl RefUnwindSafe for Cube
impl Send for Cube
impl Sync for Cube
impl Unpin for Cube
impl UnwindSafe for Cube
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<F, T> Refmt<F> for T
impl<F, T> Refmt<F> for T
Source§fn refmt<'a>(&'a self, fopt: &'a F) -> Wrapper<'a, F, T>
fn refmt<'a>(&'a self, fopt: &'a F) -> Wrapper<'a, F, T>
fmt::Debug or fmt::Display, it uses
the given Fmt custom format type instead. Read more