makepad_math/
math_usize.rs1use std::ops::{Add, Sub};
2
3#[derive(Clone, Copy, Debug)]
4pub struct RectUsize {
5 pub origin: PointUsize,
6 pub size: SizeUsize,
7}
8
9impl RectUsize {
10 pub const fn new(origin: PointUsize, size: SizeUsize) -> Self {
11 Self { origin, size }
12 }
13
14 pub const fn min(self) -> PointUsize {
15 self.origin
16 }
17
18 pub fn max(self) -> PointUsize {
19 self.origin + self.size
20 }
21
22 pub fn union(self, other: Self) -> Self {
23 let min = self.min().min(other.min());
24 let max = self.max().max(other.max());
25 Self::new(min, max - min)
26 }
27}
28
29#[derive(Clone, Copy, Debug)]
30pub struct PointUsize {
31 pub x: usize,
32 pub y: usize,
33}
34
35impl PointUsize {
36 pub const fn new(x: usize, y: usize) -> Self {
37 Self { x, y }
38 }
39
40 pub fn min(self, other: Self) -> Self {
41 Self {
42 x: self.x.min(other.x),
43 y: self.y.min(other.y),
44 }
45 }
46
47 pub fn max(self, other: Self) -> Self {
48 Self {
49 x: self.x.max(other.x),
50 y: self.y.max(other.y),
51 }
52 }
53}
54
55impl Add<SizeUsize> for PointUsize {
56 type Output = Self;
57
58 fn add(self, other: SizeUsize) -> Self::Output {
59 PointUsize::new(self.x + other.width, self.y + other.height)
60 }
61}
62
63impl Sub for PointUsize {
64 type Output = SizeUsize;
65
66 fn sub(self, other: Self) -> Self::Output {
67 SizeUsize::new(self.x - other.x, self.y - other.y)
68 }
69}
70
71#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
72pub struct SizeUsize {
73 pub width: usize,
74 pub height: usize,
75}
76
77impl SizeUsize {
78 pub const fn new(width: usize, height: usize) -> Self {
79 Self { width, height }
80 }
81}