mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2026-02-21 18:49:04 +01:00
This commit is contained in:
parent
b7b1055fbc
commit
4fa5d74fa2
26 changed files with 1550 additions and 1548 deletions
|
|
@ -41,6 +41,32 @@ pub trait Out: Send + Sync + Sized {
|
|||
}
|
||||
}
|
||||
|
||||
/// A numeric type that can be used as coordinate.
|
||||
///
|
||||
/// FIXME: Replace this ad-hoc trait with `num` crate.
|
||||
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>
|
||||
{
|
||||
fn plus (self, other: Self) -> Self;
|
||||
fn minus (self, other: Self) -> Self {
|
||||
if self >= other { self - other } else { 0.into() }
|
||||
}
|
||||
fn atomic (self) -> AtomicUsize {
|
||||
AtomicUsize::new(self.into())
|
||||
}
|
||||
fn zero () -> Self {
|
||||
0.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Drawable with dynamic dispatch.
|
||||
pub trait Draw<O: Out> {
|
||||
fn draw (&self, to: &mut O);
|
||||
|
|
@ -93,32 +119,6 @@ pub trait HasContent<O: Out> {
|
|||
// TODO DOCUMENTME
|
||||
pub trait Content<O: Out>: Draw<O> + Layout<O> {}
|
||||
|
||||
/// A numeric type that can be used as coordinate.
|
||||
///
|
||||
/// FIXME: Replace this ad-hoc trait with `num` crate.
|
||||
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>
|
||||
{
|
||||
fn plus (self, other: Self) -> Self;
|
||||
fn minus (self, other: Self) -> Self {
|
||||
if self >= other { self - other } else { 0.into() }
|
||||
}
|
||||
fn atomic (self) -> AtomicUsize {
|
||||
AtomicUsize::new(self.into())
|
||||
}
|
||||
fn zero () -> Self {
|
||||
0.into()
|
||||
}
|
||||
}
|
||||
|
||||
// Something that has an origin point (X, Y).
|
||||
pub trait HasXY<N: Coord> {
|
||||
fn x (&self) -> N;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue