1#[derive(Clone, Copy, Debug, Default, PartialEq)]
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4pub struct Point {
5 pub x: f32,
7 pub y: f32,
9}
10
11impl Point {
12 pub const ZERO: Point = Point { x: 0.0, y: 0.0 };
14
15 pub const fn new(x: f32, y: f32) -> Self {
17 Self { x, y }
18 }
19}
20
21impl From<(f32, f32)> for Point {
22 fn from((x, y): (f32, f32)) -> Self {
23 Self { x, y }
24 }
25}
26
27impl std::ops::Add for Point {
28 type Output = Point;
29 fn add(self, o: Point) -> Point {
30 Point::new(self.x + o.x, self.y + o.y)
31 }
32}
33
34impl std::ops::Sub for Point {
35 type Output = Point;
36 fn sub(self, o: Point) -> Point {
37 Point::new(self.x - o.x, self.y - o.y)
38 }
39}
40
41#[derive(Clone, Copy, Debug, Default, PartialEq)]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44pub struct Size {
45 pub width: f32,
47 pub height: f32,
49}
50
51impl Size {
52 pub const fn new(width: f32, height: f32) -> Self {
54 Self { width, height }
55 }
56
57 pub fn is_empty(&self) -> bool {
59 self.width <= 0.0 || self.height <= 0.0
60 }
61}