@@ -1163,38 +1163,42 @@ mod data_iter_tests {
1163
1163
//------------------------------------------------------------------------------
1164
1164
//{{{ Data placement
1165
1165
1166
- fn draw_codewords < ' a , I > ( codewords : & [ u8 ] , is_half_codeword_at_end : bool , modules : & mut I )
1167
- where I : Iterator < & ' a mut Module >
1168
- {
1169
- let length = codewords. len ( ) ;
1170
- let last_word = if is_half_codeword_at_end { length-1 } else { length } ;
1171
- for ( i, b) in codewords. iter ( ) . enumerate ( ) {
1172
- let bits_end = if i == last_word { 4 } else { 0 } ;
1173
- for j in range_inclusive ( bits_end, 7 u) . rev ( ) {
1174
- let color = if ( * b & ( 1 << j) ) != 0 { DarkUnmasked } else { LightUnmasked } ;
1175
- match modules. next ( ) {
1176
- Some ( module) => { * module = color; }
1177
- None => { return ; }
1166
+ impl Canvas {
1167
+ fn draw_codewords < ' a , I > ( & mut self ,
1168
+ codewords : & [ u8 ] ,
1169
+ is_half_codeword_at_end : bool ,
1170
+ coords : & mut I )
1171
+ where I : Iterator < ( i16 , i16 ) >
1172
+ {
1173
+ let length = codewords. len ( ) ;
1174
+ let last_word = if is_half_codeword_at_end { length-1 } else { length } ;
1175
+ for ( i, b) in codewords. iter ( ) . enumerate ( ) {
1176
+ let bits_end = if i == last_word { 4 } else { 0 } ;
1177
+ ' outside:
1178
+ for j in range_inclusive ( bits_end, 7 u) . rev ( ) {
1179
+ let color = if ( * b & ( 1 << j) ) != 0 { DarkUnmasked } else { LightUnmasked } ;
1180
+ while let Some ( ( x, y) ) = coords. next ( ) {
1181
+ let r = self . get_mut ( x, y) ;
1182
+ if * r == Empty {
1183
+ * r = color;
1184
+ continue ' outside;
1185
+ }
1186
+ }
1187
+ return ;
1178
1188
}
1179
1189
}
1180
1190
}
1181
- }
1182
1191
1183
- impl Canvas {
1184
1192
/// Draws the encoded data and error correction codes to the empty modules.
1185
1193
pub fn draw_data ( & mut self , data : & [ u8 ] , ec : & [ u8 ] ) {
1186
1194
let is_half_codeword_at_end = match ( self . version , self . ec_level ) {
1187
1195
( MicroVersion ( 1 ) , L ) | ( MicroVersion ( 3 ) , M ) => true ,
1188
1196
_ => false ,
1189
1197
} ;
1190
1198
1191
- let mut coords = DataModuleIter :: new ( self . version )
1192
- . filter_map ( |( x, y) | {
1193
- let r = self . get_mut ( x, y) ;
1194
- if * r != Empty { None } else { Some ( r) }
1195
- } ) ;
1196
- draw_codewords ( data, is_half_codeword_at_end, & mut coords) ;
1197
- draw_codewords ( ec, false , & mut coords) ;
1199
+ let mut coords = DataModuleIter :: new ( self . version ) ;
1200
+ self . draw_codewords ( data, is_half_codeword_at_end, & mut coords) ;
1201
+ self . draw_codewords ( ec, false , & mut coords) ;
1198
1202
}
1199
1203
}
1200
1204
0 commit comments