@@ -34,6 +34,14 @@ fn make_point_pair(a: BackendCoord, b: BackendCoord, scale: f64) -> [f64; 4] {
34
34
]
35
35
}
36
36
37
+ fn make_circle ( center : BackendCoord , radius : u32 , scale : f64 ) -> [ f64 ; 4 ] {
38
+ circle (
39
+ center. 0 as f64 * scale,
40
+ center. 1 as f64 * scale,
41
+ radius as f64 * scale,
42
+ )
43
+ }
44
+
37
45
impl < ' a , ' b > PistonBackend < ' a , ' b > {
38
46
pub fn new ( size : ( u32 , u32 ) , scale : f64 , context : Context , graphics : & ' b mut G2d < ' a > ) -> Self {
39
47
Self {
@@ -150,7 +158,7 @@ impl<'a, 'b> DrawingBackend for PistonBackend<'a, 'b> {
150
158
style : & S ,
151
159
fill : bool ,
152
160
) -> Result < ( ) , DrawingErrorKind < Self :: ErrorType > > {
153
- let rect = circle ( center. 0 as f64 , center . 1 as f64 , radius as f64 ) ;
161
+ let rect = make_circle ( center, radius , self . scale ) ;
154
162
if fill {
155
163
ellipse (
156
164
make_piston_rgba ( & style. as_color ( ) ) ,
@@ -204,3 +212,13 @@ pub fn draw_piston_window<F: FnOnce(PistonBackend) -> Result<(), Box<dyn std::er
204
212
}
205
213
None
206
214
}
215
+
216
+ #[ cfg( test) ]
217
+ mod test {
218
+ use super :: * ;
219
+ #[ test]
220
+ fn test_make_circle ( ) {
221
+ assert_eq ! ( make_circle( ( 1 , 1 ) , 0 , 1.0 ) , [ 1.0 , 1.0 , 0.0 , 0.0 ] ) ;
222
+ assert_eq ! ( make_circle( ( 1 , 2 ) , 3 , 4.0 ) , [ -8.0 , -4.0 , 24.0 , 24.0 ] ) ;
223
+ }
224
+ }
0 commit comments