From 615b5ff36828206e54c84a8023c3e150c4327e82 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Tue, 19 Dec 2023 18:22:37 +0800 Subject: [PATCH] feat: return point and width as i32 --- libwaysip/src/lib.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/libwaysip/src/lib.rs b/libwaysip/src/lib.rs index da66ef8..d10289a 100644 --- a/libwaysip/src/lib.rs +++ b/libwaysip/src/lib.rs @@ -125,19 +125,29 @@ pub struct AreaInfo { } impl AreaInfo { - /// provide the width of the area - pub fn width(&self) -> f64 { + /// provide the width of the area as f64 + pub fn width_f64(&self) -> f64 { (self.end_x - self.start_x).abs() } - /// provide the height of the area - pub fn height(&self) -> f64 { + /// provide the width of the area as i32 + pub fn width(&self) -> i32 { + self.width_f64() as i32 + } + + /// provide the height of the area as f64 + pub fn height_f64(&self) -> f64 { (self.end_y - self.start_y).abs() } + /// provide the width of the area as i32 + pub fn height(&self) -> i32 { + self.height_f64() as i32 + } + /// caculate the real start position - pub fn left_top_point(&self) -> (f64, f64) { - (self.start_x.min(self.end_x), (self.start_y.min(self.end_y))) + pub fn left_top_point(&self) -> (i32, i32) { + (self.start_x.min(self.end_x) as i32, (self.start_y.min(self.end_y)) as i32) } }