Face6

Enum Face6 

Source
#[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

Source

pub const ALL: [Face6; 6]

All the values of Face6.

Source

pub const fn from_discriminant(d: u8) -> Option<Face6>

Inverse function of face as u8, converting the number to Face6.

Source

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

pub const fn axis(self) -> Axis

Returns which axis this face’s normal vector is parallel to.

Source

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);
Source

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);
Source

pub const fn opposite(self) -> Face6

Returns the opposite face (maps PX to NX and so on).

Source

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.

Source

pub fn normal_vector<S, U>(self) -> Vector3D<S, U>
where S: Zero + One + Neg<Output = S>,

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.

Source

pub fn vector<S, U>(self, magnitude: S) -> Vector3D<S, U>
where S: Zero + Neg<Output = S>,

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));
Source

pub fn dot<S, U>(self, vector: Vector3D<S, U>) -> S
where S: Zero + Neg<Output = 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));
}
Source

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.

Source

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().

Source

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);
Source

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);
Source

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 Add<Face6> for Cube

Source§

type Output = Cube

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Face6) -> <Cube as Add<Face6>>::Output

Performs the + operation. Read more
Source§

impl AddAssign<Face6> for Cube

Source§

fn add_assign(&mut self, rhs: Face6)

Performs the += operation. Read more
Source§

impl<'arbitrary> Arbitrary<'arbitrary> for Face6

Source§

fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Face6, Error>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Face6, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for Face6

Source§

fn clone(&self) -> Face6

Returns a duplicate 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 Debug for Face6

Source§

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

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

impl<'de> Deserialize<'de> for Face6

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Face6, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Exhaust for Face6

Source§

type Iter = ExhaustFace6Iter

Iterator type returned by Self::exhaust_factories(). See the trait documentation for what properties this iterator should have. Read more
Source§

type Factory = ExhaustFace6Factory

Data which can be used to construct Self. Read more
Source§

fn exhaust_factories() -> <Face6 as Exhaust>::Iter

Returns an iterator over factories for all values of this type. Read more
Source§

fn from_factory(factory: <Face6 as Exhaust>::Factory) -> Face6

Construct a concrete value of this type from a Self::Factory value produced by its Self::Iter. Read more
Source§

fn exhaust() -> Iter<Self>

Returns an iterator over all values of this type. Read more
Source§

impl From<Face6> for Face7

Source§

fn from(value: Face6) -> Face7

Converts to this type from the input type.
Source§

impl Hash for Face6

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

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<V> Index<Face6> for FaceMap<V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, face: Face6) -> &V

Performs the indexing (container[index]) operation. Read more
Source§

impl<V> IndexMut<Face6> for FaceMap<V>

Source§

fn index_mut(&mut self, face: Face6) -> &mut V

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Neg for Face6

Source§

type Output = Face6

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Face6 as Neg>::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Face6

Source§

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

Source§

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

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

impl TryFrom<Face7> for Face6

Source§

type Error = Faceless

The type returned in the event of a conversion error.
Source§

fn try_from(value: Face7) -> Result<Face6, <Face6 as TryFrom<Face7>>::Error>

Performs the conversion.
Source§

impl TryFrom<Vector3D<i32, Cube>> for Face6

Source§

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>

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

impl Copy for Face6

Source§

impl Eq for Face6

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynEq for T
where T: Any + Eq,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts the type to dyn Any.
Source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

This method tests for self and other values to be equal. Read more
Source§

impl<T> DynHash for T
where T: DynEq + Hash,

Source§

fn as_dyn_eq(&self) -> &(dyn DynEq + 'static)

Casts the type to dyn Any.
Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Feeds this value into the given Hasher.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

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