Skip to main content

Face7

Enum Face7 

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

Source

pub const ALL: [Face7; 7]

All the values of Face7, with Face7::Within listed first.

Source

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

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

Source

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.

Source

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);
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::Face7;

assert_eq!(Face7::PX.is_negative(), false);
assert_eq!(Face7::NX.is_negative(), true);
assert_eq!(Face7::Within.is_negative(), false);
Source

pub const fn opposite(self) -> Face7

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

Source

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

Returns the face whose normal is the cross product of these faces’ normals.

Source

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

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.

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 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));
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::{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§

Source§

impl Clone for Face7

Source§

fn clone(&self) -> Face7

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Face7

Source§

impl Debug for Face7

Source§

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

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

impl Eq for Face7

Source§

impl Exhaust for Face7

Source§

type Iter = ExhaustFace7Iter

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

type Factory = ExhaustFace7Factory

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

fn exhaust_factories() -> Self::Iter

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

fn from_factory(factory: Self::Factory) -> Self

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

Converts to this type from the input type.
Source§

impl Hash for Face7

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 Neg for Face7

Source§

type Output = Face7

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Face7

Source§

fn eq(&self, other: &Face7) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for Face7

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, Self::Error>

Performs the conversion.
Source§

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

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