Tweaked Rust code to use inclusive-range for-loops where appropriate.

This commit is contained in:
Project Nayuki 2019-09-13 03:44:56 +00:00
parent 9fdd05e64d
commit 2136d88ac8
1 changed files with 5 additions and 5 deletions

View File

@ -504,8 +504,8 @@ impl QrCode {
// Draws a 9*9 finder pattern including the border separator,
// with the center module at (x, y). Modules can be out of bounds.
fn draw_finder_pattern(&mut self, x: i32, y: i32) {
for dy in -4 .. 5 {
for dx in -4 .. 5 {
for dy in -4 ..= 4 {
for dx in -4 ..= 4 {
let xx: i32 = x + dx;
let yy: i32 = y + dy;
if 0 <= xx && xx < self.size && 0 <= yy && yy < self.size {
@ -520,8 +520,8 @@ impl QrCode {
// Draws a 5*5 alignment pattern, with the center module
// at (x, y). All modules must be in bounds.
fn draw_alignment_pattern(&mut self, x: i32, y: i32) {
for dy in -2 .. 3 {
for dx in -2 .. 3 {
for dy in -2 ..= 2 {
for dx in -2 ..= 2 {
self.set_function_module(x + dx, y + dy, std::cmp::max(dx.abs(), dy.abs()) != 1);
}
}
@ -570,7 +570,7 @@ impl QrCode {
// Interleave (not concatenate) the bytes from every block into a single sequence
let mut result = Vec::<u8>::with_capacity(rawcodewords);
for i in 0 .. shortblocklen + 1 {
for i in 0 ..= shortblocklen {
for (j, block) in blocks.iter().enumerate() {
// Skip the padding byte in short blocks
if i != shortblocklen - blockecclen || j >= numshortblocks {