1use super::lvgl;
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
4pub struct Point {
5 x: i16,
6 y: i16,
7}
8
9impl Point {
10 pub const fn new(x: i16, y: i16) -> Self {
11 Self { x, y }
12 }
13
14 pub const fn get_x(&self) -> i16 {
15 self.x
16 }
17
18 pub const fn get_y(&self) -> i16 {
19 self.y
20 }
21
22 pub fn split(self) -> (i16, i16) {
23 (self.x, self.y)
24 }
25
26 pub fn set_x(mut self, value: i16) -> Self {
27 self.x = value;
28 self
29 }
30
31 pub fn set_y(mut self, value: i16) -> Self {
32 self.y = value;
33 self
34 }
35
36 pub fn set(mut self, x: i16, y: i16) -> Self {
37 self.x = x;
38 self.y = y;
39 self
40 }
41
42 pub fn get_distance(&self, other: Point) -> f32 {
43 let x = (self.x - other.x) as f32;
44 let y = (self.y - other.y) as f32;
45 (x * x + y * y).sqrt()
46 }
47}
48
49impl From<(i16, i16)> for Point {
50 fn from((x, y): (i16, i16)) -> Self {
51 Self::new(x, y)
52 }
53}
54
55impl From<Point> for (i16, i16) {
56 fn from(point: Point) -> Self {
57 point.split()
58 }
59}
60
61impl From<Point> for lvgl::lv_point_t {
62 fn from(point: Point) -> Self {
63 Self {
64 x: point.x as i32,
65 y: point.y as i32,
66 }
67 }
68}