Graphics/
Point.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use super::LVGL;

#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct Point_type {
    X: i16,
    Y: i16,
}

impl Point_type {
    pub const fn New(X: i16, Y: i16) -> Self {
        Self { X, Y }
    }

    pub const fn Get_x(&self) -> i16 {
        self.X
    }

    pub const fn Get_y(&self) -> i16 {
        self.Y
    }

    pub fn Split(self) -> (i16, i16) {
        (self.X, self.Y)
    }

    pub fn Set_x(mut self, Value: i16) -> Self {
        self.X = Value;
        self
    }

    pub fn Set_y(mut self, Value: i16) -> Self {
        self.Y = Value;
        self
    }

    pub fn Set(mut self, X: i16, Y: i16) -> Self {
        self.X = X;
        self.Y = Y;
        self
    }

    pub fn Get_distance(&self, Other: Point_type) -> f32 {
        let X = (self.X - Other.X) as f32;
        let Y = (self.Y - Other.Y) as f32;
        (X * X + Y * Y).sqrt()
    }
}

impl From<(i16, i16)> for Point_type {
    fn from((X, Y): (i16, i16)) -> Self {
        Self::New(X, Y)
    }
}

impl From<Point_type> for (i16, i16) {
    fn from(Point: Point_type) -> Self {
        Point.Split()
    }
}

impl From<Point_type> for LVGL::lv_point_t {
    fn from(Point: Point_type) -> Self {
        Self {
            x: Point.X as i32,
            y: Point.Y as i32,
        }
    }
}