@@ -75,6 +75,12 @@ pub fn draw_line<DB: DrawingBackend, S: BackendStyle>(
7575 ( from, to)
7676 } ;
7777
78+ let mut size_limit = back. get_size ( ) ;
79+
80+ if steep {
81+ size_limit = ( size_limit. 1 , size_limit. 0 ) ;
82+ }
83+
7884 let grad = f64:: from ( to. 1 - from. 1 ) / f64:: from ( to. 0 - from. 0 ) ;
7985
8086 let mut put_pixel = |( x, y) : BackendCoord , b : f64 | {
@@ -87,12 +93,24 @@ pub fn draw_line<DB: DrawingBackend, S: BackendStyle>(
8793
8894 let mut y = f64:: from ( from. 1 ) ;
8995
90- for x in from. 0 ..=to. 0 {
96+ let y_step_limit = ( f64:: from ( to. 1 . min ( size_limit. 1 as i32 - 1 ) - from. 1 ) / grad) . ceil ( ) as i32 ;
97+
98+ for x in from. 0 ..=to. 0 . min ( size_limit. 0 as i32 - 2 ) . min ( from. 0 + y_step_limit) {
9199 check_result ! ( put_pixel( ( x, y as i32 ) , 1.0 + y. floor( ) - y) ) ;
92100 check_result ! ( put_pixel( ( x, y as i32 + 1 ) , y - y. floor( ) ) ) ;
93101
94102 y += grad;
95103 }
96104
105+ if to. 0 >= ( size_limit. 0 as i32 ) - 1 && y < f64:: from ( to. 1 ) {
106+ let x = size_limit. 0 as i32 - 1 ;
107+ if 1.0 + y. floor ( ) - y > 1e-5 {
108+ check_result ! ( put_pixel( ( x, y as i32 ) , 1.0 + y. floor( ) - y) ) ;
109+ }
110+ if y - y. floor ( ) > 1e-5 && y + 1.0 < f64:: from ( to. 1 ) {
111+ check_result ! ( put_pixel( ( x, y as i32 + 1 ) , y - y. floor( ) ) ) ;
112+ }
113+ }
114+
97115 Ok ( ( ) )
98116}
0 commit comments