mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
remove FixedAxis and ScaledAxis
This commit is contained in:
parent
54057afad8
commit
286dec0f40
6 changed files with 223 additions and 290 deletions
|
|
@ -33,72 +33,6 @@ impl<T> Coordinate for T where T: Send + Sync + Copy
|
|||
+ Into<f64>
|
||||
{}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FixedAxis<T> {
|
||||
pub start: T,
|
||||
pub point: Option<T>,
|
||||
pub clamp: Option<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ScaledAxis<T> {
|
||||
pub start: T,
|
||||
pub scale: T,
|
||||
pub point: Option<T>,
|
||||
pub clamp: Option<T>,
|
||||
}
|
||||
|
||||
macro_rules! impl_axis_common { ($A:ident $T:ty) => {
|
||||
impl $A<$T> {
|
||||
#[inline] pub fn start_set (&mut self, n: $T) -> $T {
|
||||
self.start = n;
|
||||
self.start
|
||||
}
|
||||
#[inline] pub fn start_plus (&self, n: $T) -> $T {
|
||||
(self.start + n).min(self.clamp.unwrap_or(<$T>::MAX))
|
||||
}
|
||||
#[inline] pub fn start_inc (&mut self, n: $T) -> $T {
|
||||
self.start_set(self.start_plus(n))
|
||||
}
|
||||
#[inline] pub fn start_minus (&self, n: $T) -> $T {
|
||||
self.start.saturating_sub(n)
|
||||
}
|
||||
#[inline] pub fn start_dec (&mut self, n: $T) -> $T {
|
||||
self.start = self.start_minus(n);
|
||||
self.start
|
||||
}
|
||||
|
||||
#[inline] pub fn point_set (&mut self, n: Option<$T>) -> Option<$T> {
|
||||
self.point = n;
|
||||
self.point
|
||||
}
|
||||
#[inline] pub fn point_plus (&self, n: $T) -> Option<$T> {
|
||||
self.point.map(|p|(p + n).min(self.clamp.unwrap_or(<$T>::MAX)))
|
||||
}
|
||||
#[inline] pub fn point_inc (&mut self, n: $T) -> Option<$T> {
|
||||
self.point_set(self.point_plus(n))
|
||||
}
|
||||
#[inline] pub fn point_minus (&self, n: $T) -> Option<$T> {
|
||||
self.point.map(|p|p.saturating_sub(n))
|
||||
}
|
||||
#[inline] pub fn point_dec (&mut self, n: $T) -> Option<$T> {
|
||||
self.point_set(self.point_minus(n))
|
||||
}
|
||||
|
||||
}
|
||||
} }
|
||||
impl_axis_common!(FixedAxis u16);
|
||||
impl_axis_common!(FixedAxis usize);
|
||||
impl_axis_common!(ScaledAxis u16);
|
||||
impl_axis_common!(ScaledAxis usize);
|
||||
|
||||
impl<T: Copy> ScaledAxis<T> {
|
||||
#[inline] pub fn scale_set (&mut self, n: T) -> T {
|
||||
self.scale = n;
|
||||
n
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: return impl Point and impl Size instead of [N;x]
|
||||
// to disambiguate between usage of 2-"tuple"s
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue