pub const trait RotateDirections: [const] RotateDirectionsHelper {
#[must_use]
fn rotate_clockwise_90(&self) -> Self;
#[must_use]
fn rotate_counterclockwise_90(&self) -> Self;
}
pub const trait RotateDirectionsHelper: Sized {
#[must_use]
fn rotate_180(&self) -> Self;
#[must_use]
fn rotate_clockwise_270(&self) -> Self;
#[must_use]
fn rotate_counterclockwise_270(&self) -> Self;
}
impl<T: [const] RotateDirections + [const] core::marker::Destruct> const
RotateDirectionsHelper for T
{
fn rotate_180(&self) -> Self {
self.rotate_clockwise_90().rotate_clockwise_90()
}
fn rotate_clockwise_270(&self) -> Self {
self.rotate_counterclockwise_90()
}
fn rotate_counterclockwise_270(&self) -> Self {
self.rotate_clockwise_90()
}
}
pub const trait RotatePrecise: [const] RotatePreciseHelper {
#[must_use]
fn rotate_clockwise_45(&self) -> Self;
#[must_use]
fn rotate_counterclockwise_45(&self) -> Self;
}
pub const trait RotatePreciseHelper: [const] RotateDirections {
#[must_use]
fn rotate_clockwise_135(&self) -> Self;
#[must_use]
fn rotate_counterclockwise_135(&self) -> Self;
}
impl<T: [const] RotatePrecise + [const] core::marker::Destruct> const
RotatePreciseHelper for T
{
fn rotate_clockwise_135(&self) -> Self {
self.rotate_clockwise_90().rotate_clockwise_45()
}
fn rotate_counterclockwise_135(&self) -> Self {
self.rotate_counterclockwise_90().rotate_counterclockwise_45()
}
}
mod all;
mod cardinal;
mod direction;
mod directions_with_none;
mod extended;
mod special;
pub use all::*;
pub use cardinal::*;
pub use direction::*;
pub use directions_with_none::*;
pub use extended::*;
pub use special::*;
pub mod misc;
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
#[cfg_attr(
feature = "wincode",
derive(wincode::SchemaWrite, wincode::SchemaRead)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::struct_excessive_bools, missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
#[cfg_attr(feature = "c_compatible", repr(C))]
pub struct NormalDirections {
pub top: bool,
pub bottom: bool,
pub left: bool,
pub right: bool,
pub top_left: bool,
pub top_right: bool,
pub bottom_left: bool,
pub bottom_right: bool,
}
impl NormalDirections {
#[must_use]
#[allow(clippy::fn_params_excessive_bools)] pub const fn new(top: bool, bottom: bool, left: bool, right: bool) -> Self {
Self {
top,
bottom,
left,
right,
top_left: top && left,
top_right: top && right,
bottom_left: bottom && left,
bottom_right: bottom && right,
}
}
#[must_use]
pub const fn all_true() -> Self {
Self {
top: true,
bottom: true,
left: true,
right: true,
top_left: true,
top_right: true,
bottom_left: true,
bottom_right: true,
}
}
#[must_use]
pub const fn all_false() -> Self {
Self {
top: false,
bottom: false,
left: false,
right: false,
top_left: false,
top_right: false,
bottom_left: false,
bottom_right: false,
}
}
#[must_use]
pub fn is_direction_true<T: IsDirectionTrue>(&self, direction: &T) -> bool {
direction.is_direction_true(self)
}
}
pub const trait IsDirectionTrue {
fn is_direction_true(&self, directions: &NormalDirections) -> bool;
}
impl const IsDirectionTrue for u8 {
fn is_direction_true(&self, directions: &NormalDirections) -> bool {
match self {
0 => directions.top_left,
1 => directions.top,
2 => directions.top_right,
3 => directions.right,
4 => directions.bottom_right,
5 => directions.bottom,
6 => directions.bottom_left,
7 => directions.left,
_ => false,
}
}
}
impl const IsDirectionTrue for Directions {
fn is_direction_true(&self, directions: &NormalDirections) -> bool {
match self {
Self::North => directions.top,
Self::South => directions.bottom,
Self::West => directions.left,
Self::East => directions.right,
}
}
}
pub const trait ShapeDirectionType {
fn top_left_direction() -> Self;
fn top_right_direction() -> Self;
fn bottom_left_direction() -> Self;
fn bottom_right_direction() -> Self;
fn top_direction() -> Self;
fn right_direction() -> Self;
fn left_direction() -> Self;
fn bottom_direction() -> Self;
fn none_directional() -> Self;
}
use crate::math::{Bounded, ConstNumbers128, ConstOne, ConstZero};
impl<T: ConstNumbers128 + ConstOne + ConstZero + [const] Bounded> const
ShapeDirectionType for T
{
fn bottom_direction() -> Self {
Self::CONST_5
}
fn bottom_left_direction() -> Self {
Self::CONST_6
}
fn bottom_right_direction() -> Self {
Self::CONST_4
}
fn left_direction() -> Self {
Self::CONST_7
}
fn none_directional() -> Self {
Self::max_value()
}
fn right_direction() -> Self {
Self::CONST_3
}
fn top_direction() -> Self {
Self::ONE
}
fn top_left_direction() -> Self {
Self::ZERO
}
fn top_right_direction() -> Self {
Self::CONST_2
}
}