@@ -1163,38 +1163,42 @@ mod data_iter_tests {
11631163//------------------------------------------------------------------------------
11641164//{{{ Data placement
11651165
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 ;
11781188 }
11791189 }
11801190 }
1181- }
11821191
1183- impl Canvas {
11841192 /// Draws the encoded data and error correction codes to the empty modules.
11851193 pub fn draw_data ( & mut self , data : & [ u8 ] , ec : & [ u8 ] ) {
11861194 let is_half_codeword_at_end = match ( self . version , self . ec_level ) {
11871195 ( MicroVersion ( 1 ) , L ) | ( MicroVersion ( 3 ) , M ) => true ,
11881196 _ => false ,
11891197 } ;
11901198
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) ;
11981202 }
11991203}
12001204
0 commit comments