#[repr(u8)]pub enum Face6 {
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.
See also the similar type Face7, which adds a “zero” or “within the cube”
variant. 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§
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 Face6
impl Face6
Sourcepub const fn from_discriminant(d: u8) -> Option<Face6>
pub const fn from_discriminant(d: u8) -> Option<Face6>
Inverse function of face as u8, converting the number to Face6.
Sourcepub fn from_snapped_vector(vector: Vector3D<f64, Cube>) -> Option<Face6>
pub fn from_snapped_vector(vector: Vector3D<f64, Cube>) -> Option<Face6>
Returns the Face6 whose normal vector is closest in direction to the given
vector.
Edge cases:
- Ties are broken by preferring Z faces over Y faces, and Y faces over X faces.
- If all magnitudes are zero, the Z axis’s sign is used. (Remember that floating-point numbers include distinct positive and negative zeroes).
- If any coordinate is NaN, returns
None.
Sourcepub const fn is_positive(self) -> bool
pub const 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::Face6;
assert_eq!(Face6::PX.is_positive(), true);
assert_eq!(Face6::NX.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::Face6;
assert_eq!(Face6::PX.is_negative(), false);
assert_eq!(Face6::NX.is_negative(), true);Sourcepub const fn cross(self, other: Face6) -> Face7
pub const fn cross(self, other: Face6) -> Face7
Returns the face whose normal is the cross product of these faces’ normals.
Since cross products may be zero, the result is a Face7.
Sourcepub fn normal_vector<S, U>(self) -> Vector3D<S, U>
pub fn normal_vector<S, U>(self) -> Vector3D<S, U>
Returns the axis-aligned unit vector normal to this face.
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.
This is mathematically equivalent to multiplying Face6::normal_vector() by magnitude,
but does not perform those multiplications, and may have better type inference.
§Example
use all_is_cubes::math::{Face6, GridVector};
assert_eq!(Face6::PY.vector(3), GridVector::new(0, 3, 0));
assert_eq!(Face6::NY.vector(3), GridVector::new(0, -3, 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::{Face6, FreeVector};
let sample_vector = FreeVector::new(1.0, 2.0, 5.0_f64);
for face in Face6::ALL {
assert_eq!(face.dot(sample_vector), face.normal_vector().dot(sample_vector));
}Sourcepub const fn rotation_from_nz(self) -> GridRotation
pub const fn rotation_from_nz(self) -> GridRotation
Returns a rotation, without reflection, which will rotate Face6::NZ to be self.
The significance of this rotation is that it may be used to obtain a set of coordinate systems for all six faces of some cube. It is arbitrary, but convenient to have the arbitrary choice already made.
Sourcepub const fn face_transform(self, scale: i32) -> Gridgid
pub const fn face_transform(self, scale: i32) -> Gridgid
Returns a Gridgid transformation which, if given points on the square
with x ∈ [0, scale], y ∈ [0, scale], and z = 0, converts them to points that lie
on the faces of the cube with x ∈ [0, scale], y ∈ [0, scale], and z ∈ [0, scale].
Specifically, Face6::NZ.face_transform() is the identity and all others are
consistent with that. Note that there are arbitrary choices in the rotation
of all other faces. (TODO: Document those choices and test them.)
The rotations used are equal to Face6::rotation_from_nz(),
and this method is equivalent to
self.rotation_from_nz().to_positive_octant_transform(scale).
To work with floating-point coordinates, use .face_transform().to_matrix().to_free().
Sourcepub const fn clockwise(self) -> GridRotation
pub const fn clockwise(self) -> GridRotation
Returns the rotation which is clockwise,
when looking towards the face self of the rotated object.
§Example
use all_is_cubes::math::Face6::*;
assert_eq!(PY.clockwise().transform(PX), PZ);Sourcepub const fn counterclockwise(self) -> GridRotation
pub const fn counterclockwise(self) -> GridRotation
Returns the rotation which is counterclockwise (anticlockwise),
when looking towards the face self of the rotated object.
§Example
use all_is_cubes::math::Face6::*;
assert_eq!(PY.counterclockwise().transform(PZ), PX);Sourcepub const fn r180(self) -> GridRotation
pub const fn r180(self) -> GridRotation
Returns the rotation which is a half turn or 180º,
when looking towards the face self of the rotated object.
This result only depends on the axis, not the direction, but it is available here to
complete the set
[self, self.clockwise(), self.r180(), self.counterclockwise()],
which can also be expressed as
self.clockwise().iterate().
§Example
use all_is_cubes::math::Face6::*;
assert_eq!(PY.r180().transform(PX), NX);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<'arbitrary> Arbitrary<'arbitrary> for Face6
impl<'arbitrary> Arbitrary<'arbitrary> for Face6
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Face6, Error>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Face6, Error>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Face6, Error>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Face6, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for Face6
impl<'de> Deserialize<'de> for Face6
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Face6, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Face6, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Exhaust for Face6
impl Exhaust for Face6
Source§type Iter = ExhaustFace6Iter
type Iter = ExhaustFace6Iter
Self::exhaust_factories().
See the trait documentation for what properties this iterator should have. Read moreSource§fn from_factory(factory: <Face6 as Exhaust>::Factory) -> Face6
fn from_factory(factory: <Face6 as Exhaust>::Factory) -> Face6
Self::Factory value produced by
its Self::Iter. Read moreSource§impl Serialize for Face6
impl Serialize for Face6
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,
Source§impl TryFrom<Vector3D<i32, Cube>> for Face6
impl TryFrom<Vector3D<i32, Cube>> for Face6
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: Vector3D<i32, Cube>,
) -> Result<Face6, <Face6 as TryFrom<Vector3D<i32, Cube>>>::Error>
fn try_from( value: Vector3D<i32, Cube>, ) -> Result<Face6, <Face6 as TryFrom<Vector3D<i32, Cube>>>::Error>
Recovers a Face6 from its corresponding unit normal vector. All other vectors
are rejected.
use all_is_cubes::math::{Face6, GridVector};
// A Face6 may be converted from its normal vector.
for face in Face6::ALL {
assert_eq!(Face6::try_from(face.normal_vector()), Ok(face));
}
// If the vector does not correspond to any Face6, it is returned.
let v = GridVector::new(1, 2, 3);
assert_eq!(Face6::try_from(v), Err(v));impl Copy for Face6
impl Eq for Face6
impl StructuralPartialEq for Face6
Auto Trait Implementations§
impl Freeze for Face6
impl RefUnwindSafe for Face6
impl Send for Face6
impl Sync for Face6
impl Unpin for Face6
impl UnwindSafe for Face6
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.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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