From 95b915d4291079601ccca81f3638a527b100e384 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sat, 27 Nov 2021 21:10:55 +0100 Subject: [PATCH] utils: Make Coordinate public --- CHANGELOG.md | 1 + src/utils/geometry.rs | 7 +++++++ src/utils/mod.rs | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fab971..0f7a992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,7 @@ - `Rectangle` can now also be converted from f64 to i32 variants - `Rectangle::contains_rect` can be used to check if a rectangle is contained within another +- `Coordinate` is now part of the public api, so it can be used for coordinate agnositic functions outside of the utils module or even out-of-tree ### Bugfixes diff --git a/src/utils/geometry.rs b/src/utils/geometry.rs index 8f3e97f..dd2f796 100644 --- a/src/utils/geometry.rs +++ b/src/utils/geometry.rs @@ -17,14 +17,21 @@ pub struct Buffer; #[derive(Debug)] pub struct Raw; +/// Trait for types serving as a coordinate for other geometry utils pub trait Coordinate: Sized + Add + Sub + PartialOrd + Default + Copy + fmt::Debug { + /// Downscale the coordinate fn downscale(self, scale: Self) -> Self; + /// Upscale the coordinate fn upscale(self, scale: Self) -> Self; + /// Convert the coordinate to a f64 fn to_f64(self) -> f64; + /// Convert to this coordinate from a f64 fn from_f64(v: f64) -> Self; + /// Test if the coordinate is not negative fn non_negative(self) -> bool; + /// Returns the absolute value of this coordinate fn abs(self) -> Self; } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 1732236..9b8edd3 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -8,7 +8,7 @@ pub mod x11rb; pub mod user_data; -pub use self::geometry::{Buffer, Logical, Physical, Point, Raw, Rectangle, Size}; +pub use self::geometry::{Buffer, Coordinate, Logical, Physical, Point, Raw, Rectangle, Size}; /// This resource is not managed by Smithay #[derive(Debug)]