rust_droid/common/
rect.rs

1use super::point::Point;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub struct Rect {
5    pub x: u32,
6    pub y: u32,
7    pub width: u32,
8    pub height: u32,
9}
10
11impl Rect {
12    pub fn new(x: u32, y: u32, width: u32, height: u32) -> Self {
13        Self {
14            x,
15            y,
16            width,
17            height,
18        }
19    }
20
21    /// 计算矩形的中心点
22    pub fn center(&self) -> Point {
23        Point {
24            x: self.x + self.width / 2,
25            y: self.y + self.height / 2,
26        }
27    }
28}