Merge branch 'main' into port_cpp_qrcode

This commit is contained in:
Henry Schimke
2023-03-21 10:19:25 -05:00
6 changed files with 143 additions and 8 deletions

View File

@@ -202,14 +202,17 @@ impl BitMatrix {
}
/**
* <p>Gets the requested bit, where true means black.</p>
* Gets the requested bit, where true means black.
*
* @param x The horizontal component (i.e. which column)
* @param y The vertical component (i.e. which row)
* @return value of given bit in matrix
* x The horizontal component (i.e. which column)
* y The vertical component (i.e. which row)
* returns the value of given bit in matrix, or false if the requested point is out of bounds of the image
*/
pub fn get(&self, x: u32, y: u32) -> bool {
let offset = self.get_offset(y, x);
if offset >= self.bits.len() {
return false;
}
((self.bits[offset] >> (x & 0x1f)) & 1) != 0
}
@@ -232,6 +235,10 @@ impl BitMatrix {
Some(((self.bits[offset] >> (x & 0x1f)) & 1) != 0)
}
pub fn try_get_point(&self, point: Point) -> Option<bool> {
self.try_get(point.x as u32, point.y as u32)
}
pub fn try_get_area(&self, x: u32, y: u32, box_size: u32) -> Option<bool> {
let mut matrix = Vec::with_capacity((box_size * box_size) as usize);
let start_x = (x as i32 - box_size as i32 / 2).max(0) as u32;
@@ -255,7 +262,12 @@ impl BitMatrix {
/// Confusingly returns true if the requested element is out of bounds
pub fn check_in_bounds(&self, x: u32, y: u32) -> bool {
(self.get_offset(y, x)) > self.bits.len()
(self.get_offset(y, x)) >= self.bits.len()
}
/// Confusingly returns true if the requested element is out of bounds
pub fn check_point_in_bounds(&self, point: Point) -> bool {
self.check_in_bounds(point.x as u32, point.y as u32)
}
/**

View File

@@ -281,7 +281,7 @@ impl Circle<'_> {
// count left
while {
let point = get_point(self.center, (x, y), rotation);
!self.image.get(point.x as u32, point.y as u32) && x > 0
!self.image.check_point_in_bounds(point) && !self.image.get_point(point) && x > 0
} {
x -= 1;
length += 1;
@@ -293,7 +293,7 @@ impl Circle<'_> {
// count right
while {
let point = get_point(self.center, (x, y), rotation);
!self.image.get(point.x as u32, point.y as u32)
!self.image.check_point_in_bounds(point) && !self.image.get_point(point)
} {
x += 1;
length += 1;