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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! Structs for working with shapes as values.
//!
//! The [graphics] module provides functions for drawing shapes.
//! This modules provides useful struct for when you need to store
//! or manipulate a shape before it can be drawn.
use crate::*;

pub trait Shape {
    fn draw(&self);
}

/// A wrapper for [`draw_line`].
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct Line {
    pub a:     Point,
    pub b:     Point,
    pub style: LineStyle,
}

impl Shape for Line {
    fn draw(&self) {
        draw_line(self.a, self.b, self.style);
    }
}

/// A wrapper for [`draw_rect`].
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct Rect {
    pub point: Point,
    pub size:  Size,
    pub style: Style,
}

impl Shape for Rect {
    fn draw(&self) {
        draw_rect(self.point, self.size, self.style);
    }
}

impl From<RoundedRect> for Rect {
    fn from(value: RoundedRect) -> Self {
        Self {
            point: value.point,
            size:  value.size,
            style: value.style,
        }
    }
}

/// A wrapper for [`draw_rounded_rect`].
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct RoundedRect {
    pub point:  Point,
    pub size:   Size,
    pub corner: Size,
    pub style:  Style,
}

impl Shape for RoundedRect {
    fn draw(&self) {
        draw_rounded_rect(self.point, self.size, self.corner, self.style);
    }
}

impl From<Rect> for RoundedRect {
    fn from(value: Rect) -> Self {
        Self {
            point:  value.point,
            size:   value.size,
            corner: Size {
                width:  0,
                height: 0,
            },
            style:  value.style,
        }
    }
}

/// A wrapper for [`draw_circle`].
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct Circle {
    pub point:    Point,
    pub diameter: i32,
    pub style:    Style,
}

impl Shape for Circle {
    fn draw(&self) {
        draw_circle(self.point, self.diameter, self.style);
    }
}

/// A wrapper for [`draw_ellipse`].
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct Ellipse {
    pub point: Point,
    pub size:  Size,
    pub style: Style,
}

impl Shape for Ellipse {
    fn draw(&self) {
        draw_ellipse(self.point, self.size, self.style);
    }
}

impl From<Circle> for Ellipse {
    fn from(value: Circle) -> Self {
        Self {
            point: value.point,
            size:  Size {
                width:  value.diameter,
                height: value.diameter,
            },
            style: value.style,
        }
    }
}

/// A wrapper for [`draw_triangle`].
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
pub struct Triangle {
    pub a:     Point,
    pub b:     Point,
    pub c:     Point,
    pub style: Style,
}

impl Shape for Triangle {
    fn draw(&self) {
        draw_triangle(self.a, self.b, self.c, self.style);
    }
}

/// A wrapper for [`draw_arc`].
#[derive(Clone, Debug)]
pub struct Arc {
    pub point:    Point,
    pub diameter: i32,
    pub start:    Angle,
    pub sweep:    Angle,
    pub style:    Style,
}

impl Shape for Arc {
    fn draw(&self) {
        draw_arc(
            self.point,
            self.diameter,
            self.start,
            self.sweep,
            self.style,
        );
    }
}

impl From<Sector> for Arc {
    fn from(value: Sector) -> Self {
        Self {
            point:    value.point,
            diameter: value.diameter,
            start:    value.start,
            sweep:    value.sweep,
            style:    value.style,
        }
    }
}

/// A wrapper for [`draw_sector`].
#[derive(Clone, Debug)]
pub struct Sector {
    pub point:    Point,
    pub diameter: i32,
    pub start:    Angle,
    pub sweep:    Angle,
    pub style:    Style,
}

impl Shape for Sector {
    fn draw(&self) {
        draw_sector(
            self.point,
            self.diameter,
            self.start,
            self.sweep,
            self.style,
        );
    }
}

impl From<Arc> for Sector {
    fn from(value: Arc) -> Self {
        Self {
            point:    value.point,
            diameter: value.diameter,
            start:    value.start,
            sweep:    value.sweep,
            style:    value.style,
        }
    }
}