geometry: simplify coord traits, add sized, clone, copy, etc
This commit is contained in:
parent
35ccf20142
commit
450fbbf9c9
@ -1,6 +1,8 @@
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Sub;
|
||||
use std::ops::{Mul, Sub, Add};
|
||||
use num::{One, pow, integer::Roots};
|
||||
use std::cmp::{min, max};
|
||||
|
||||
pub trait CoordinateSpace {}
|
||||
|
||||
@ -11,7 +13,7 @@ pub struct Coordinates<T: CoordLimits<Data = T>, S: CoordinateSpace> {
|
||||
space: PhantomData<S>,
|
||||
}
|
||||
|
||||
impl<T: CoordLimits<Data = T> + Debug + PartialOrd, S: CoordinateSpace> Debug for Coordinates<T, S> {
|
||||
impl<T: CoordLimits<Data = T> + Debug, S: CoordinateSpace> Debug for Coordinates<T, S> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_tuple("@")
|
||||
.field(&self.x)
|
||||
@ -20,8 +22,8 @@ impl<T: CoordLimits<Data = T> + Debug + PartialOrd, S: CoordinateSpace> Debug fo
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CoordLimits: PartialOrd + PartialEq {
|
||||
type Data: Sized + PartialOrd + PartialEq;
|
||||
pub trait CoordLimits: PartialOrd + PartialEq + Sub + Clone + Mul + Copy + One + Add {
|
||||
type Data: CoordLimits;
|
||||
const MIN: Self::Data;
|
||||
const MAX: Self::Data;
|
||||
}
|
||||
@ -89,12 +91,12 @@ pub type VirtualCoordinates = Coordinates<u8, Virtual>;
|
||||
pub type PhysicalCoordinates = Coordinates<usize, Physical>;
|
||||
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Debug, PartialOrd)]
|
||||
pub struct Rectangle<CoordData: CoordLimits<Data = CoordData> + Clone + Copy, Space: CoordinateSpace> {
|
||||
pub struct Rectangle<CoordData: CoordLimits<Data = CoordData>, Space: CoordinateSpace> {
|
||||
pub top_left: Coordinates<CoordData, Space>,
|
||||
pub bottom_right: Coordinates<CoordData, Space>
|
||||
}
|
||||
|
||||
impl<CoordData: CoordLimits<Data = CoordData> + Sub<Output=CoordData> + Clone + Copy, Space: CoordinateSpace> Rectangle<CoordData, Space> {
|
||||
impl<CoordData: CoordLimits<Data = CoordData> + Sub<Output=CoordData>, Space: CoordinateSpace> Rectangle<CoordData, Space> {
|
||||
pub fn new(top_left: Coordinates<CoordData, Space>, bottom_right: Coordinates<CoordData, Space>) -> Self {
|
||||
debug_assert!(top_left.x <= bottom_right.x);
|
||||
debug_assert!(top_left.y <= bottom_right.y);
|
||||
|
Loading…
x
Reference in New Issue
Block a user