mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
convert to using point...
instead of vectors for finding corners in bitmatrix
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
use std::fmt;
|
||||
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, Point};
|
||||
use crate::{point, Exceptions, Point};
|
||||
|
||||
use super::BitArray;
|
||||
|
||||
@@ -561,7 +561,7 @@ impl BitMatrix {
|
||||
*
|
||||
* @return {@code x,y} coordinate of top-left-most 1 bit, or null if it is all white
|
||||
*/
|
||||
pub fn getTopLeftOnBit(&self) -> Option<Vec<u32>> {
|
||||
pub fn getTopLeftOnBit(&self) -> Option<Point> {
|
||||
let mut bitsOffset = 0;
|
||||
while bitsOffset < self.bits.len() && self.bits[bitsOffset] == 0 {
|
||||
bitsOffset += 1;
|
||||
@@ -578,10 +578,10 @@ impl BitMatrix {
|
||||
bit += 1;
|
||||
}
|
||||
x += bit;
|
||||
Some(vec![x as u32, y as u32])
|
||||
Some(point(x as f32, y as f32))
|
||||
}
|
||||
|
||||
pub fn getBottomRightOnBit(&self) -> Option<[u32; 2]> {
|
||||
pub fn getBottomRightOnBit(&self) -> Option<Point> {
|
||||
let mut bitsOffset = self.bits.len() as i64 - 1;
|
||||
while bitsOffset >= 0 && self.bits[bitsOffset as usize] == 0 {
|
||||
bitsOffset -= 1;
|
||||
@@ -600,7 +600,7 @@ impl BitMatrix {
|
||||
}
|
||||
x += bit;
|
||||
|
||||
Some([x as u32, y as u32])
|
||||
Some(point(x as f32, y as f32))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
// */
|
||||
// public final class BitMatrixTestCase extends Assert {
|
||||
|
||||
use crate::point;
|
||||
|
||||
use super::BitMatrix;
|
||||
|
||||
static BIT_MATRIX_POINTS: [u32; 6] = [1, 2, 2, 0, 3, 1];
|
||||
@@ -87,14 +89,14 @@ fn test_on_bit() {
|
||||
assert!(matrix.getTopLeftOnBit().is_none());
|
||||
assert!(matrix.getBottomRightOnBit().is_none());
|
||||
matrix.setRegion(1, 1, 1, 1).expect("must set");
|
||||
assert_eq!(vec![1, 1], matrix.getTopLeftOnBit().unwrap());
|
||||
assert_eq!(vec![1, 1], matrix.getBottomRightOnBit().unwrap());
|
||||
assert_eq!(point(1.0, 1.0), matrix.getTopLeftOnBit().unwrap());
|
||||
assert_eq!(point(1.0, 1.0), matrix.getBottomRightOnBit().unwrap());
|
||||
matrix.setRegion(1, 1, 3, 2).expect("must set");
|
||||
assert_eq!(vec![1, 1], matrix.getTopLeftOnBit().unwrap());
|
||||
assert_eq!(vec![3, 2], matrix.getBottomRightOnBit().unwrap());
|
||||
assert_eq!(point(1.0, 1.0), matrix.getTopLeftOnBit().unwrap());
|
||||
assert_eq!(point(3.0, 2.0), matrix.getBottomRightOnBit().unwrap());
|
||||
matrix.setRegion(0, 0, 5, 5).expect("must set");
|
||||
assert_eq!(vec![0, 0], matrix.getTopLeftOnBit().unwrap());
|
||||
assert_eq!(vec![4, 4], matrix.getBottomRightOnBit().unwrap());
|
||||
assert_eq!(point(0.0, 0.0), matrix.getTopLeftOnBit().unwrap());
|
||||
assert_eq!(point(4.0, 4.0), matrix.getBottomRightOnBit().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user