Enum splashsurf_lib::topology::Direction
source · pub enum Direction {
Negative,
Positive,
}
Expand description
Direction on a number line/coordinate axis or identifiers for the end points of a line
Variants§
Implementations§
source§impl Direction
impl Direction
sourcepub const fn all_possible() -> &'static [Direction; 2]
pub const fn all_possible() -> &'static [Direction; 2]
Returns a reference to an array containing all possible directions
use crate::splashsurf_lib::topology::Direction;
assert!(Direction::all_possible().iter().any(|d| d.is_positive()));
assert!(Direction::all_possible().iter().any(|d| d.is_negative()));
assert_eq!(Direction::all_possible().iter().count(), 2);
sourcepub const fn new_positive(is_positive: bool) -> Self
pub const fn new_positive(is_positive: bool) -> Self
Constructs a new positive or negative direction depending on the flag
use crate::splashsurf_lib::topology::Direction;
assert_eq!(Direction::new_positive(true), Direction::Positive);
assert_eq!(Direction::new_positive(false), Direction::Negative);
sourcepub fn apply_step<N: Add<Output = N> + Sub<Output = N>>(
&self,
n: N,
step: N
) -> N
pub fn apply_step<N: Add<Output = N> + Sub<Output = N>>( &self, n: N, step: N ) -> N
Adds or subtracts the given step from the value depending on the direction
use crate::splashsurf_lib::topology::Direction;
assert_eq!(Direction::Positive.apply_step(27, 3), 30);
assert_eq!(Direction::Negative.apply_step(27, 3), 24);
sourcepub fn checked_apply_step<N: CheckedAdd<Output = N> + CheckedSub<Output = N>>(
&self,
n: N,
step: N
) -> Option<N>
pub fn checked_apply_step<N: CheckedAdd<Output = N> + CheckedSub<Output = N>>( &self, n: N, step: N ) -> Option<N>
Same as apply_step
but uses checked_add
and checked_sub
, i.e. returns None
on overflow
use crate::splashsurf_lib::topology::Direction;
assert_eq!(Direction::Negative.checked_apply_step(0 as i32, 10), Some(-10));
assert_eq!(Direction::Negative.checked_apply_step(0 as u32, 10), None);
sourcepub fn checked_apply_step_ijk<N: CheckedAdd<Output = N> + CheckedSub<Output = N>>(
&self,
start: &[N; 3],
step: &[N; 3]
) -> Option<[N; 3]>
pub fn checked_apply_step_ijk<N: CheckedAdd<Output = N> + CheckedSub<Output = N>>( &self, start: &[N; 3], step: &[N; 3] ) -> Option<[N; 3]>
Adds or subtracts a 3D step from the array depending on the direction, returns None
on overflow
use crate::splashsurf_lib::topology::Direction;
assert_eq!(Direction::Negative.checked_apply_step_ijk(&[1, 2, 3], &[0, 1, 2]), Some([1, 1, 1]));
sourcepub const fn is_positive(&self) -> bool
pub const fn is_positive(&self) -> bool
Returns whether the direction is positive
use crate::splashsurf_lib::topology::Direction;
assert_eq!(Direction::Positive.is_positive(), true);
assert_eq!(Direction::Negative.is_positive(), false);
sourcepub const fn is_negative(&self) -> bool
pub const fn is_negative(&self) -> bool
Returns whether the direction is negative
use crate::splashsurf_lib::topology::Direction;
assert_eq!(Direction::Positive.is_negative(), false);
assert_eq!(Direction::Negative.is_negative(), true);
Trait Implementations§
source§impl Ord for Direction
impl Ord for Direction
source§impl PartialEq<Direction> for Direction
impl PartialEq<Direction> for Direction
source§impl PartialOrd<Direction> for Direction
impl PartialOrd<Direction> for Direction
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Direction
impl Eq for Direction
impl StructuralEq for Direction
impl StructuralPartialEq for Direction
Auto Trait Implementations§
impl RefUnwindSafe for Direction
impl Send for Direction
impl Sync for Direction
impl Unpin for Direction
impl UnwindSafe for Direction
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
Mutably borrows from an owned value. Read more
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.