use std::ops::{Add, Range, RangeInclusive, Rem, Sub};
pub use buns;
use deki_macros::imp;
pub use maflow::*;
pub use paste;
pub use type_cell::*;
#[cfg(feature = "derive_more")]
pub use derive_more;
#[cfg(feature = "lerp")]
pub mod lerp;
#[cfg(feature="approx")]
pub mod math;
pub mod collections;
pub use std::marker::PhantomData as Ghost;
pub use derive_new::new as New;
pub use extension_traits::extension as ext;
pub use buns::compose;
pub type Str = &'static str;
pub trait Cycle {
fn cycle_next(&self) -> Self;
fn cycle_prev(&self) -> Self;
}
pub trait Syncable:'static+Send+Sync {}
impl <T:'static+Send+Sync> Syncable for T {}
pub trait DefaultClear: Default {
fn clear(&mut self){*self = Self::default();}
}
impl <A:Default> DefaultClear for A {}
pub trait CollectShort: Iterator {
fn into_vec(self) -> Vec<Self::Item>;
}
impl <A:Iterator> CollectShort for A {
fn into_vec(self) -> Vec<Self::Item> { self.collect() }
}
#[imp(RangeInclusive<Idx:Clone+Add<Output=Idx>>|*RangeOffset)]
fn offset(&self,rhs:Idx) -> Self {
self.start().clone()+rhs.clone()
..=self.end().clone()+rhs.clone()
}
#[imp(Range<Idx:Clone+Add<Output=Idx>>|RangeOffset<Idx>)]
fn offset(&self,rhs:Idx) -> Self {
self.start.clone()+rhs.clone()..self.end.clone()+rhs.clone()
}
compose!{paste!{
#[inline]
pub fn [<quick_cycle_ ^0>]<A>(cur:A,rhs:A,min:A,max:A) -> A
where A: Clone
+ Add<Output=A>
+ Sub<Output=A>
+ Rem<Output=A>
{
let len = max.sub(min.clone());
let bas = cur.sub(min.clone()).add(len.clone());
let unc = bas.^0(rhs.rem(len.clone()));
min.add(unc.rem(len))
}
} #sub #add }
pub trait CycleMath {
fn add_qucy(self,rhs:Self,min:Self,max:Self) -> Self;
fn sub_qucy(self,rhs:Self,min:Self,max:Self) -> Self;
}
compose!{
impl CycleMath for ^0 {
#[inline]
fn add_qucy(self,rhs:Self,min:Self,max:Self) -> Self {
quick_cycle_add(self,rhs,min,max)
}
#[inline]
fn sub_qucy(self,rhs:Self,min:Self,max:Self) -> Self {
quick_cycle_sub(self,rhs,min,max)
}
}
#f32 #f64
#i8 #i16 #i32 #i64 #i128 #isize
#u8 #u16 #u32 #u64 #u128 #usize
}
#[inline]
#[imp(f32 | *MulF32)]
fn mul_f32(self,rhs:f32) -> Self {self * rhs}
#[inline]
#[imp(f64 | MulF32)]
fn mul_f32(self,rhs:f32) -> Self {self * rhs as f64}
compose!{
impl MulF32 for ^0 {
#[inline]
fn mul_f32(self,rhs:f32) -> Self {
(self as f32 * rhs).round() as ^0
}
}
#i8 #i16 #i32 #i64 #i128 #isize
}
#[cfg(feature="random")]
pub mod random {
use std::ops::Range;
pub use fastrand::*;
#[inline]
pub fn f32r(range:Range<f32>) -> f32 {
range.start + f32() * (range.end - range.start)
}
}
#[cfg(feature="random")]
#[inline]
#[imp(Vec<T> | *)]
fn random(&self) -> &T {
exit![>if (self.len()==1) &self[0]];
&self[random::usize(0..self.len())]
}
#[inline]
#[imp(Vec<T> | *)]
fn get_cycling(&self, idx: usize) -> &T {
&self[idx % self.len()]
}
#[macro_export]
macro_rules! qonst {
($ty:ty: $($tt:tt)*) => {paste!{
pub const [<$ty:snake:upper>]: $ty = $ty {$($tt)*};
}};
($ty:ident::$($tt:tt)*) => {paste!{
pub const [<$ty:snake:upper>]: $ty = $ty::$($tt)*;
}};
}
#[macro_export]
macro_rules! trait_alias {($trait:ident:$($tt:tt)*)=>{
pub trait $trait: $($tt)* {}
impl <C:$($tt)*> $trait for C {}
}}
#[macro_export]
macro_rules! default {($name:ty = $($tt:tt)*) => {
impl Default for $name {
fn default() -> Self {$($tt)*}
}
}}