1#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
5pub struct Point {
6 pub x: i32,
7 pub y: i32,
8}
9
10impl Point {
11 pub fn new(x: i32, y: i32) -> Self {
13 Self { x, y }
14 }
15
16 pub const ZERO: Point = Point { x: 0, y: 0 };
18}
19
20impl From<(i32, i32)> for Point {
21 fn from((x, y): (i32, i32)) -> Self {
22 Self::new(x, y)
23 }
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Default)]
28pub struct PointF {
29 pub x: f32,
30 pub y: f32,
31}
32
33impl PointF {
34 pub fn new(x: f32, y: f32) -> Self {
36 Self { x, y }
37 }
38
39 pub const ZERO: PointF = PointF { x: 0.0, y: 0.0 };
41
42 pub fn to_point(&self) -> Point {
44 Point::new(self.x.round() as i32, self.y.round() as i32)
45 }
46}
47
48impl From<(f32, f32)> for PointF {
49 fn from((x, y): (f32, f32)) -> Self {
50 Self::new(x, y)
51 }
52}
53
54impl From<Point> for PointF {
55 fn from(p: Point) -> Self {
56 Self::new(p.x as f32, p.y as f32)
57 }
58}
59
60pub type IPoint = Point;