1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// Represents a 2D size
#[derive(Debug, Copy, Clone)]
pub struct Size {
    pub width: f64,
    pub height: f64,
}

impl Size {
    /// scale the size uniformly by some value
    pub fn scaled(&self, scale: f64) -> Self {
        Self {
            width: self.width * scale,
            height: self.height * scale
        }
    }

    /// scale the size non-uniformly in x and y
    pub fn scaled_2d(&self, scale: (f64, f64)) -> Self {
        Self {
            width: self.width * scale.0,
            height: self.height * scale.1
        }
    }
}

/// Represents a 2D point
#[derive(Debug, Copy, Clone)]
pub struct Point {
    pub x: f64,
    pub y: f64,
}

impl Point {
    /// The point at (0, 0)
    pub const ZERO: Point = Point {
        x: 0.0, 
        y: 0.0
    };

    /// Scale the point uniformly by some value
    pub fn scaled(&self, scale: f64) -> Self {
        Self {
            x: self.x * scale,
            y: self.y * scale
        }
    }

    /// Scale the point non-uniformly in x and y
    pub fn scaled_2d(&self, scale: (f64, f64)) -> Self {
        Self {
            x: self.x * scale.0,
            y: self.y * scale.1
        }
    }
}

/// Represents an axis-aligned rectangle
#[derive(Debug, Copy, Clone)]
pub struct Rect {
    pub origin: Point,
    pub size: Size,
}

impl Rect {
    /// Scale the rectangle uniformly
    pub fn scaled(&self, scale: f64) -> Self {
        Self {
            origin: self.origin.scaled(scale),
            size: self.size.scaled(scale)
        }
    }

    /// Scale the rectangle non-uniformly in x and y
    pub fn scaled_2d(&self, scale: (f64, f64)) -> Self {
        Self {
            origin: self.origin.scaled_2d(scale),
            size: self.size.scaled_2d(scale)
        }
    }
}