Dir2

Enum Dir2 

Source
pub enum Dir2 {
    X,
    Y,
    NegX,
    NegY,
}
Expand description

A 2d cardinal direction.

Variants§

§

X

§

Y

§

NegX

§

NegY

Implementations§

Source§

impl Dir2

Source

pub const ALL: [Dir2; 4]

Source

pub fn choose(rng: &mut impl RngExt) -> Dir2

Source

pub fn from_vec2(vec: Vec2<i32>) -> Dir2

Source

pub fn to_dir3(self) -> Dir3

Source

pub fn opposite(self) -> Dir2

Source

pub fn rotated_ccw(self) -> Dir2

Rotate the direction anti clock wise

Source

pub fn rotated_cw(self) -> Dir2

Rotate the direction clock wise

Source

pub fn orthogonal(self) -> Dir2

Source

pub fn abs(self) -> Dir2

Source

pub fn signum(self) -> i32

Source

pub fn to_vec2(self) -> Vec2<i32>

Source

pub fn diagonal(self) -> Vec2<i32>

The diagonal to the left of self, this is equal to this dir plus this dir rotated counter clockwise.

Source

pub fn to_vec3(self) -> Vec3<i32>

Source

pub fn vec2(self, x: i32, y: i32) -> Vec2<i32>

Create a vec2 where x is in the direction of self, and y is anti clockwise of self.

Source

pub fn vec2_abs<T>(self, x: T, y: T) -> Vec2<T>

Create a vec2 where x is in the direction of self, and y is orthogonal version of self.

Source

pub fn to_mat3(self) -> Mat3<i32>

Returns a 3x3 matrix that rotates Vec3(1, 0, 0) to the direction you get in to_vec3. Inteded to be used with Primitive::Rotate.

Example:

use vek::Vec3;
use veloren_common::util::Dir2;
let dir = Dir2::X;

assert_eq!(dir.to_mat3() * Vec3::new(1, 0, 0), dir.to_vec3());

let dir = Dir2::NegX;

assert_eq!(dir.to_mat3() * Vec3::new(1, 0, 0), dir.to_vec3());

let dir = Dir2::Y;

assert_eq!(dir.to_mat3() * Vec3::new(1, 0, 0), dir.to_vec3());

let dir = Dir2::NegY;

assert_eq!(dir.to_mat3() * Vec3::new(1, 0, 0), dir.to_vec3());
Source

pub fn from_z_mat3(self) -> Mat3<i32>

Creates a matrix that tranforms an upwards facing vector to this direction.

Source

pub fn relative_to(self, other: Dir2) -> Dir2

Translates this direction to worldspace as if it was relative to the other direction

Source

pub fn is_x(self) -> bool

Is this direction parallel to x

Source

pub fn is_y(self) -> bool

Is this direction parallel to y

Source

pub fn is_positive(self) -> bool

Source

pub fn is_negative(self) -> bool

Source

pub fn select(self, vec: impl Into<Vec2<i32>>) -> i32

Returns the component that the direction is parallell to

Source

pub fn select_with( self, vec: impl Into<Vec2<i32>>, other: impl Into<Vec2<i32>>, ) -> Vec2<i32>

Select one component the direction is parallel to from vec and select the other component from other

Source

pub fn select_aabr<T>(self, aabr: Aabr<T>) -> T

Returns the side of an aabr that the direction is pointing to

Source

pub fn select_aabr_with<T>( self, aabr: Aabr<T>, other: impl Into<Vec2<T>>, ) -> Vec2<T>

Select one component from the side the direction is pointing to from aabr and select the other component from other

Source

pub fn sprite_ori(self) -> u8

The equivelant sprite direction of the direction

Source

pub fn from_sprite_ori(ori: u8) -> Option<(Dir2, u8)>

Returns (Dir, rest)

Returns None if ori isn’t a valid sprite Ori.

Source

pub fn sprite_ori_legacy(self) -> u8

Legacy version of sprite_ori, so prefer using that over this.

Source

pub fn split_aabr_offset<T>(self, aabr: Aabr<T>, offset: T) -> [Aabr<T>; 2]
where T: Copy + PartialOrd + Add<T, Output = T> + Sub<T, Output = T>,

Source

pub fn trim_aabr(self, aabr: Aabr<i32>, amount: i32) -> Aabr<i32>

Source

pub fn extend_aabr(self, aabr: Aabr<i32>, amount: i32) -> Aabr<i32>

Trait Implementations§

Source§

impl<O: Into<EnumSet<Dir2>>> BitAnd<O> for Dir2

Source§

type Output = EnumSet<Dir2>

The resulting type after applying the & operator.
Source§

fn bitand(self, other: O) -> Self::Output

Performs the & operation. Read more
Source§

impl<O: Into<EnumSet<Dir2>>> BitOr<O> for Dir2

Source§

type Output = EnumSet<Dir2>

The resulting type after applying the | operator.
Source§

fn bitor(self, other: O) -> Self::Output

Performs the | operation. Read more
Source§

impl<O: Into<EnumSet<Dir2>>> BitXor<O> for Dir2

Source§

type Output = EnumSet<Dir2>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, other: O) -> Self::Output

Performs the ^ operation. Read more
Source§

impl Clone for Dir2

Source§

fn clone(&self) -> Self

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 Dir2

Source§

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

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

impl Enum for Dir2

Source§

const LENGTH: usize = 4usize

Length of the enum.
Source§

fn from_usize(value: usize) -> Self

Takes an usize, and returns an element matching into_usize function.
Source§

fn into_usize(self) -> usize

Returns an unique identifier for a value within range of 0..Array::LENGTH.
Source§

impl<V> EnumArray<V> for Dir2

Source§

type Array = [V; 4]

Representation of an enum map for type V.
Source§

impl EnumSetConstHelper for Dir2

Source§

const CONST_INIT_HELPER: __EnumSetInitHelper = __EnumSetInitHelper

The instance of the ConstInitHelper.
Source§

const CONST_OP_HELPER: __EnumSetOpHelper = __EnumSetOpHelper

The instance of the ConstOpHelper.
Source§

type ConstInitHelper = __EnumSetInitHelper

A helper type used to convert values to EnumSets at compile-time.
Source§

type ConstOpHelper = __EnumSetOpHelper

A helper type used to implement compile-time operations on enums.
Source§

impl EnumSetTypePrivate for Dir2

Source§

const ALL_BITS: Self::Repr = {transmute(0x0f): <util::cardinal_directions::Dir2 as enumset::__internal::EnumSetTypePrivate>::Repr}

A mask of bits that are valid in the bitset.
Source§

const BIT_WIDTH: u32 = 4u32

The largest bit used in the bitset.
Source§

const VARIANT_COUNT: u32 = 4u32

The number of variants in the bitset.
Source§

type Repr = u8

The underlying type used to store the bitset.
Source§

fn enum_into_u32(self) -> u32

Converts an enum of this type into its bit position.
Source§

unsafe fn enum_from_u32(val: u32) -> Self

Converts a bit position into an enum value.
§

unsafe fn enum_from_u32_checked(val: u32) -> Self

Converts a bit position into an enum value, with an debug_assert.
Source§

impl IntoEnumIterator for Dir2

Source§

impl Neg for Dir2

Source§

type Output = Dir2

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Not for Dir2

Source§

type Output = EnumSet<Dir2>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl PartialEq<EnumSet<Dir2>> for Dir2

Source§

fn eq(&self, other: &EnumSet<Dir2>) -> 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 PartialEq for Dir2

Source§

fn eq(&self, other: &Self) -> 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<O: Into<EnumSet<Dir2>>> Sub<O> for Dir2

Source§

type Output = EnumSet<Dir2>

The resulting type after applying the - operator.
Source§

fn sub(self, other: O) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for Dir2

Source§

impl EnumSetType for Dir2

Source§

impl Eq for Dir2

Auto Trait Implementations§

§

impl Freeze for Dir2

§

impl RefUnwindSafe for Dir2

§

impl Send for Dir2

§

impl Sync for Dir2

§

impl Unpin for Dir2

§

impl UnwindSafe for Dir2

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> 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<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
§

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

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Context> SubContext<Context> for Context

Source§

fn sub_context(self) -> Context

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Event for T
where T: Send + Sync + 'static,

§

impl<T> Resource for T
where T: Any + Send + Sync,

§

impl<T> Storable for T
where T: Send + Sync + 'static,