@@ -100,22 +100,27 @@ fn draw_sweep_line<B: DrawingBackend, S: BackendStyle>(
100100 let vs = s. ceil ( ) - s;
101101 let ve = e - e. floor ( ) ;
102102
103+ let ( s1, s2) = if b. use_anti_aliasing ( ) {
104+ ( style. color ( ) . mix ( vs) , style. color ( ) . mix ( ve) )
105+ } else {
106+ ( style. color ( ) , style. color ( ) )
107+ } ;
103108 if dx == 0 {
104109 check_result ! ( b. draw_line(
105110 ( p0 + x0, s. ceil( ) as i32 + y0) ,
106111 ( p0 + x0, e. floor( ) as i32 + y0) ,
107112 & style. color( )
108113 ) ) ;
109- check_result ! ( b. draw_pixel( ( p0 + x0, s. ceil( ) as i32 + y0 - 1 ) , style . color ( ) . mix ( vs ) ) ) ;
110- check_result ! ( b. draw_pixel( ( p0 + x0, e. floor( ) as i32 + y0 + 1 ) , style . color ( ) . mix ( ve ) ) ) ;
114+ check_result ! ( b. draw_pixel( ( p0 + x0, s. ceil( ) as i32 + y0 - 1 ) , s1 ) ) ;
115+ check_result ! ( b. draw_pixel( ( p0 + x0, e. floor( ) as i32 + y0 + 1 ) , s2 ) ) ;
111116 } else {
112117 check_result ! ( b. draw_line(
113118 ( s. ceil( ) as i32 + x0, p0 + y0) ,
114119 ( e. floor( ) as i32 + x0, p0 + y0) ,
115120 & style. color( )
116121 ) ) ;
117- check_result ! ( b. draw_pixel( ( s. ceil( ) as i32 + x0 - 1 , p0 + y0) , style . color ( ) . mix ( vs ) ) ) ;
118- check_result ! ( b. draw_pixel( ( e. floor( ) as i32 + x0 + 1 , p0 + y0) , style . color ( ) . mix ( ve ) ) ) ;
122+ check_result ! ( b. draw_pixel( ( s. ceil( ) as i32 + x0 - 1 , p0 + y0) , s1 ) ) ;
123+ check_result ! ( b. draw_pixel( ( e. floor( ) as i32 + x0 + 1 , p0 + y0) , s2 ) ) ;
119124 }
120125
121126 Ok ( ( ) )
@@ -319,22 +324,28 @@ pub fn draw_circle<B: DrawingBackend, S: BackendStyle>(
319324 let top = center. 1 - lx. floor ( ) as i32 ;
320325 let bottom = center. 1 + lx. floor ( ) as i32 ;
321326
327+ // Do not use flat color but interpolate when using anti-aliasing
328+ let ( s1, s2) = if b. use_anti_aliasing ( ) {
329+ ( style. color ( ) . mix ( 1.0 - v) , style. color ( ) . mix ( v) )
330+ } else {
331+ ( style. color ( ) , style. color ( ) )
332+ } ;
322333 if fill {
323334 check_result ! ( b. draw_line( ( left, y) , ( right, y) , & style. color( ) ) ) ;
324335 check_result ! ( b. draw_line( ( x, top) , ( x, up - 1 ) , & style. color( ) ) ) ;
325336 check_result ! ( b. draw_line( ( x, down + 1 ) , ( x, bottom) , & style. color( ) ) ) ;
326337 } else {
327- check_result ! ( b. draw_pixel( ( left, y) , style . color ( ) . mix ( 1.0 - v ) ) ) ;
328- check_result ! ( b. draw_pixel( ( right, y) , style . color ( ) . mix ( 1.0 - v ) ) ) ;
338+ check_result ! ( b. draw_pixel( ( left, y) , s1 ) ) ;
339+ check_result ! ( b. draw_pixel( ( right, y) , s1 ) ) ;
329340
330- check_result ! ( b. draw_pixel( ( x, top) , style . color ( ) . mix ( 1.0 - v ) ) ) ;
331- check_result ! ( b. draw_pixel( ( x, bottom) , style . color ( ) . mix ( 1.0 - v ) ) ) ;
341+ check_result ! ( b. draw_pixel( ( x, top) , s1 ) ) ;
342+ check_result ! ( b. draw_pixel( ( x, bottom) , s1 ) ) ;
332343 }
333344
334- check_result ! ( b. draw_pixel( ( left - 1 , y) , style . color ( ) . mix ( v ) ) ) ;
335- check_result ! ( b. draw_pixel( ( right + 1 , y) , style . color ( ) . mix ( v ) ) ) ;
336- check_result ! ( b. draw_pixel( ( x, top - 1 ) , style . color ( ) . mix ( v ) ) ) ;
337- check_result ! ( b. draw_pixel( ( x, bottom + 1 ) , style . color ( ) . mix ( v ) ) ) ;
345+ check_result ! ( b. draw_pixel( ( left - 1 , y) , s2 ) ) ;
346+ check_result ! ( b. draw_pixel( ( right + 1 , y) , s2 ) ) ;
347+ check_result ! ( b. draw_pixel( ( x, top - 1 ) , s2 ) ) ;
348+ check_result ! ( b. draw_pixel( ( x, bottom + 1 ) , s2 ) ) ;
338349 }
339350
340351 Ok ( ( ) )
0 commit comments