File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -91,19 +91,29 @@ pub fn draw_line<DB: DrawingBackend, S: BackendStyle>(
91
91
}
92
92
} ;
93
93
94
- let mut y = f64:: from ( from. 1 ) ;
94
+ let y_step_limit =
95
+ ( f64:: from ( to. 1 . min ( size_limit. 1 as i32 - 1 ) . max ( 0 ) - from. 1 ) / grad) . floor ( ) as i32 ;
95
96
96
- let y_step_limit = ( f64:: from ( to. 1 . min ( size_limit. 1 as i32 - 1 ) - from. 1 ) / grad) . ceil ( ) as i32 ;
97
+ let batch_start = ( f64:: from ( from. 1 . min ( size_limit. 1 as i32 - 2 ) . max ( 0 ) - from. 1 ) / grad)
98
+ . abs ( )
99
+ . ceil ( ) as i32
100
+ + from. 0 ;
97
101
98
- for x in from. 0 ..=to. 0 . min ( size_limit. 0 as i32 - 2 ) . min ( from. 0 + y_step_limit) {
102
+ let batch_limit =
103
+ to. 0 . min ( size_limit. 0 as i32 - 2 )
104
+ . min ( from. 0 + y_step_limit - 1 ) ;
105
+
106
+ let mut y = f64:: from ( from. 1 ) + f64:: from ( batch_start - from. 0 ) * grad;
107
+
108
+ for x in batch_start..=batch_limit {
99
109
check_result ! ( put_pixel( ( x, y as i32 ) , 1.0 + y. floor( ) - y) ) ;
100
110
check_result ! ( put_pixel( ( x, y as i32 + 1 ) , y - y. floor( ) ) ) ;
101
111
102
112
y += grad;
103
113
}
104
114
105
- if to. 0 >= ( size_limit . 0 as i32 ) - 1 && y < f64:: from ( to. 1 ) {
106
- let x = size_limit . 0 as i32 - 1 ;
115
+ if to. 0 >= batch_limit + 1 && y < f64:: from ( to. 1 ) {
116
+ let x = batch_limit as i32 + 1 ;
107
117
if 1.0 + y. floor ( ) - y > 1e-5 {
108
118
check_result ! ( put_pixel( ( x, y as i32 ) , 1.0 + y. floor( ) - y) ) ;
109
119
}
You can’t perform that action at this time.
0 commit comments