mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-07-17 07:56:56 +02:00
35 lines
951 B
Rust
35 lines
951 B
Rust
use super::*;
|
|
|
|
/// A numeric type that can be used as coordinate.
|
|
///
|
|
/// FIXME: Replace with `num` crate?
|
|
/// FIXME: Use AsRef/AsMut?
|
|
///
|
|
/// ```
|
|
/// use tengri::draw::Coord;
|
|
/// let a: u16 = Coord::zero();
|
|
/// let b: u16 = a.plus(1);
|
|
/// let c: u16 = a.minus(2);
|
|
/// let d = a.atomic();
|
|
/// ```
|
|
pub trait Coord: Send + Sync + Copy
|
|
+ Add<Self, Output=Self>
|
|
+ Sub<Self, Output=Self>
|
|
+ Mul<Self, Output=Self>
|
|
+ Div<Self, Output=Self>
|
|
+ Ord + PartialEq + Eq
|
|
+ Debug + Display + Default
|
|
+ From<u16> + Into<u16>
|
|
+ Into<usize>
|
|
+ Into<f64>
|
|
+ std::iter::Step
|
|
{
|
|
/// Zero in own type.
|
|
fn zero () -> Self { 0.into() }
|
|
/// Addition.
|
|
fn plus (self, other: Self) -> Self;
|
|
/// Saturating subtraction.
|
|
fn minus (self, other: Self) -> Self { if self >= other { self - other } else { 0.into() } }
|
|
/// Convert to [AtomicUsize].
|
|
fn atomic (self) -> AtomicUsize { AtomicUsize::new(self.into()) }
|
|
}
|