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