pub enum Dir2 {
X,
Y,
NegX,
NegY,
}Expand description
A 2d cardinal direction.
Variants§
Implementations§
Source§impl Dir2
impl Dir2
pub const ALL: [Dir2; 4]
pub fn choose(rng: &mut impl RngExt) -> Dir2
pub fn from_vec2(vec: Vec2<i32>) -> Dir2
pub fn to_dir3(self) -> Dir3
pub fn opposite(self) -> Dir2
Sourcepub fn rotated_ccw(self) -> Dir2
pub fn rotated_ccw(self) -> Dir2
Rotate the direction anti clock wise
Sourcepub fn rotated_cw(self) -> Dir2
pub fn rotated_cw(self) -> Dir2
Rotate the direction clock wise
pub fn orthogonal(self) -> Dir2
pub fn abs(self) -> Dir2
pub fn signum(self) -> i32
pub fn to_vec2(self) -> Vec2<i32>
Sourcepub fn diagonal(self) -> Vec2<i32>
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.
pub fn to_vec3(self) -> Vec3<i32>
Sourcepub fn vec2(self, x: i32, y: i32) -> Vec2<i32>
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.
Sourcepub fn vec2_abs<T>(self, x: T, y: T) -> Vec2<T>
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.
Sourcepub fn to_mat3(self) -> Mat3<i32>
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());Sourcepub fn from_z_mat3(self) -> Mat3<i32>
pub fn from_z_mat3(self) -> Mat3<i32>
Creates a matrix that tranforms an upwards facing vector to this direction.
Sourcepub fn relative_to(self, other: Dir2) -> Dir2
pub fn relative_to(self, other: Dir2) -> Dir2
Translates this direction to worldspace as if it was relative to the other direction
pub fn is_positive(self) -> bool
pub fn is_negative(self) -> bool
Sourcepub fn select(self, vec: impl Into<Vec2<i32>>) -> i32
pub fn select(self, vec: impl Into<Vec2<i32>>) -> i32
Returns the component that the direction is parallell to
Sourcepub fn select_with(
self,
vec: impl Into<Vec2<i32>>,
other: impl Into<Vec2<i32>>,
) -> Vec2<i32>
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
Sourcepub fn select_aabr<T>(self, aabr: Aabr<T>) -> T
pub fn select_aabr<T>(self, aabr: Aabr<T>) -> T
Returns the side of an aabr that the direction is pointing to
Sourcepub fn select_aabr_with<T>(
self,
aabr: Aabr<T>,
other: impl Into<Vec2<T>>,
) -> Vec2<T>
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
Sourcepub fn sprite_ori(self) -> u8
pub fn sprite_ori(self) -> u8
The equivelant sprite direction of the direction
Sourcepub fn from_sprite_ori(ori: u8) -> Option<(Dir2, u8)>
pub fn from_sprite_ori(ori: u8) -> Option<(Dir2, u8)>
Returns (Dir, rest)
Returns None if ori isn’t a valid sprite Ori.
Sourcepub fn sprite_ori_legacy(self) -> u8
pub fn sprite_ori_legacy(self) -> u8
Legacy version of sprite_ori, so prefer using that over this.
pub fn split_aabr_offset<T>(self, aabr: Aabr<T>, offset: T) -> [Aabr<T>; 2]
pub fn trim_aabr(self, aabr: Aabr<i32>, amount: i32) -> Aabr<i32>
pub fn extend_aabr(self, aabr: Aabr<i32>, amount: i32) -> Aabr<i32>
Trait Implementations§
Source§impl EnumSetConstHelper for Dir2
impl EnumSetConstHelper for Dir2
Source§const CONST_INIT_HELPER: __EnumSetInitHelper = __EnumSetInitHelper
const CONST_INIT_HELPER: __EnumSetInitHelper = __EnumSetInitHelper
ConstInitHelper.Source§const CONST_OP_HELPER: __EnumSetOpHelper = __EnumSetOpHelper
const CONST_OP_HELPER: __EnumSetOpHelper = __EnumSetOpHelper
ConstOpHelper.Source§type ConstInitHelper = __EnumSetInitHelper
type ConstInitHelper = __EnumSetInitHelper
Source§type ConstOpHelper = __EnumSetOpHelper
type ConstOpHelper = __EnumSetOpHelper
Source§impl EnumSetTypePrivate for Dir2
impl EnumSetTypePrivate for Dir2
Source§const ALL_BITS: Self::Repr = {transmute(0x0f): <util::cardinal_directions::Dir2 as enumset::__internal::EnumSetTypePrivate>::Repr}
const ALL_BITS: Self::Repr = {transmute(0x0f): <util::cardinal_directions::Dir2 as enumset::__internal::EnumSetTypePrivate>::Repr}
Source§const VARIANT_COUNT: u32 = 4u32
const VARIANT_COUNT: u32 = 4u32
Source§fn enum_into_u32(self) -> u32
fn enum_into_u32(self) -> u32
Source§unsafe fn enum_from_u32(val: u32) -> Self
unsafe fn enum_from_u32(val: u32) -> Self
§unsafe fn enum_from_u32_checked(val: u32) -> Self
unsafe fn enum_from_u32_checked(val: u32) -> Self
impl Copy for Dir2
impl EnumSetType for Dir2
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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