From 450fbbf9c9553f37928310966a4bc427e8479690 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sun, 24 Nov 2024 18:58:36 +0100 Subject: [PATCH] geometry: simplify coord traits, add sized, clone, copy, etc --- src/geometry.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/geometry.rs b/src/geometry.rs index 540ef71..2ff1c1f 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -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, S: CoordinateSpace> { space: PhantomData, } -impl + Debug + PartialOrd, S: CoordinateSpace> Debug for Coordinates { +impl + Debug, S: CoordinateSpace> Debug for Coordinates { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { f.debug_tuple("@") .field(&self.x) @@ -20,8 +22,8 @@ impl + 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; pub type PhysicalCoordinates = Coordinates; #[derive(PartialEq, Eq, Copy, Clone, Debug, PartialOrd)] -pub struct Rectangle + Clone + Copy, Space: CoordinateSpace> { +pub struct Rectangle, Space: CoordinateSpace> { pub top_left: Coordinates, pub bottom_right: Coordinates } -impl + Sub + Clone + Copy, Space: CoordinateSpace> Rectangle { +impl + Sub, Space: CoordinateSpace> Rectangle { pub fn new(top_left: Coordinates, bottom_right: Coordinates) -> Self { debug_assert!(top_left.x <= bottom_right.x); debug_assert!(top_left.y <= bottom_right.y);