#[repr(u8)]pub enum Face7 {
Within = 0,
NX = 1,
NY = 2,
NZ = 3,
PX = 4,
PY = 5,
PZ = 6,
}Expand description
Identifies a face of a cube or an orthogonal unit vector, except for
Within meaning “zero distance and undefined direction”.
This is essentially Option<Face6>, except with Face-specific methods
provided. The two enums use the same discriminant numbering.
§Serialization stability warning
This type implements [serde::Serialize] and [serde::Deserialize], but serialization
support is still experimental (as is the game data model in general). We do not guarantee that future versions of all-is-cubes
will be able to deserialize data which is serialized by this version.
Additionally, the serialization schema is designed with serde_json in mind. It is not
guaranteed that using a different data format crate, which may use a different subset of
the information exposed via [serde::Serialize], will produce stable results.
Variants§
Within = 0
The interior volume of a cube, or an undefined direction. Corresponds to the vector (0, 0, 0).
NX = 1
Negative X; the face whose normal vector is (-1, 0, 0).
NY = 2
Negative Y; the face whose normal vector is (0, -1, 0); downward.
NZ = 3
Negative Z; the face whose normal vector is (0, 0, -1).
PX = 4
Positive X; the face whose normal vector is (1, 0, 0).
PY = 5
Positive Y; the face whose normal vector is (0, 1, 0); upward.
PZ = 6
Positive Z; the face whose normal vector is (0, 0, 1).
Implementations§
Source§impl Face7
impl Face7
Sourcepub const fn from_discriminant(d: u8) -> Option<Self>
pub const fn from_discriminant(d: u8) -> Option<Self>
Inverse function of face as u8, converting the number to Face7.
Sourcepub const fn axis(self) -> Option<Axis>
pub const fn axis(self) -> Option<Axis>
Returns which axis this face’s normal vector is parallel to,
or None if the face is Face7::Within.
Sourcepub fn is_positive(self) -> bool
pub fn is_positive(self) -> bool
Returns whether this face is a “positive” face: one whose unit vector’s nonzero coordinate is positive.
use all_is_cubes::math::Face7;
assert_eq!(Face7::PX.is_positive(), true);
assert_eq!(Face7::NX.is_positive(), false);
assert_eq!(Face7::Within.is_positive(), false);Sourcepub fn is_negative(self) -> bool
pub fn is_negative(self) -> bool
Returns whether this face is a negative face: one whose unit vector’s nonzero coordinate is negative.
use all_is_cubes::math::Face7;
assert_eq!(Face7::PX.is_negative(), false);
assert_eq!(Face7::NX.is_negative(), true);
assert_eq!(Face7::Within.is_negative(), false);Sourcepub const fn cross(self, other: Self) -> Self
pub const fn cross(self, other: Self) -> Self
Returns the face whose normal is the cross product of these faces’ normals.
Sourcepub fn normal_vector<S, U>(self) -> Vector3D<S, U>
pub fn normal_vector<S, U>(self) -> Vector3D<S, U>
Returns the vector normal to this face. Within is assigned the
zero vector.
If a vector of a different length is desired, use Face6::vector() instead of
multiplying this.
Sourcepub fn vector<S, U>(self, magnitude: S) -> Vector3D<S, U>
pub fn vector<S, U>(self, magnitude: S) -> Vector3D<S, U>
Returns an axis-aligned vector normal to this face, whose magnitude, and only nonzero
component, is magnitude unless self == Face7::Within.
This is mathematically equivalent to multiplying Face7::normal_vector() by magnitude,
but does not perform those multiplications, and may have better type inference.
§Example
use all_is_cubes::math::{Face7, GridVector};
assert_eq!(Face7::PY.vector(3), GridVector::new(0, 3, 0));
assert_eq!(Face7::Within.vector(3), GridVector::new(0, 0, 0));Sourcepub fn dot<S, U>(self, vector: Vector3D<S, U>) -> S
pub fn dot<S, U>(self, vector: Vector3D<S, U>) -> S
Dot product of this face as a unit vector and the given vector, implemented by selecting the relevant component.
use all_is_cubes::math::{Face7, FreeVector};
let sample_vector = FreeVector::new(1.0, 2.0, 5.0_f64);
for face in Face7::ALL {
assert_eq!(face.dot(sample_vector), face.normal_vector().dot(sample_vector));
}Trait Implementations§
impl Copy for Face7
impl Eq for Face7
Source§impl Exhaust for Face7
impl Exhaust for Face7
Source§type Iter = ExhaustFace7Iter
type Iter = ExhaustFace7Iter
Self::exhaust_factories().
See the trait documentation for what properties this iterator should have. Read moreSource§fn exhaust_factories() -> Self::Iter
fn exhaust_factories() -> Self::Iter
Source§fn from_factory(factory: Self::Factory) -> Self
fn from_factory(factory: Self::Factory) -> Self
Self::Factory value produced by
its Self::Iter. Read moreimpl StructuralPartialEq for Face7
Source§impl TryFrom<Vector3D<i32, Cube>> for Face7
impl TryFrom<Vector3D<i32, Cube>> for Face7
Source§type Error = Vector3D<i32, Cube>
type Error = Vector3D<i32, Cube>
Returns the original vector on failure. (An error message would probably be too lacking context to be helpful.)
Source§fn try_from(value: GridVector) -> Result<Self, Self::Error>
fn try_from(value: GridVector) -> Result<Self, Self::Error>
Recovers a Face7 from its corresponding unit normal vector. All other vectors
are rejected.
use all_is_cubes::math::{Face7, GridVector};
// A Face7 may be converted from its normal vector.
for face in Face7::ALL {
assert_eq!(Face7::try_from(face.normal_vector()), Ok(face));
}
// If the vector does not correspond to any Face7, it is returned.
let v = GridVector::new(1, 2, 3);
assert_eq!(Face7::try_from(v), Err(v));Auto Trait Implementations§
impl Freeze for Face7
impl RefUnwindSafe for Face7
impl Send for Face7
impl Sync for Face7
impl Unpin for Face7
impl UnsafeUnpin for Face7
impl UnwindSafe for Face7
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<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<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
key and return true if they are equal.