small cleanup

This commit is contained in:
Henry Schimke
2023-01-14 12:01:30 -06:00
parent 89ed131f20
commit 0836d3f582
2 changed files with 7 additions and 7 deletions

View File

@@ -70,15 +70,15 @@ impl GridSampler for DefaultGridSampler {
return Err(Exceptions::NotFoundException(None)); return Err(Exceptions::NotFoundException(None));
} }
let mut bits = BitMatrix::new(dimensionX, dimensionY)?; let mut bits = BitMatrix::new(dimensionX, dimensionY)?;
let mut points = vec![0_f32; 2 * dimensionX as usize]; let mut points = vec![0.0; 2 * dimensionX as usize];
for y in 0..dimensionY { for y in 0..dimensionY {
// for (int y = 0; y < dimensionY; y++) { // for (int y = 0; y < dimensionY; y++) {
let max = points.len(); let max = points.len();
let i_value = y as f32 + 0.5f32; let i_value = y as f32 + 0.5;
let mut x = 0; let mut x = 0;
while x < max { while x < max {
// for (int x = 0; x < max; x += 2) { // for (int x = 0; x < max; x += 2) {
points[x] = (x as f32 / 2.0) + 0.5f32; points[x] = (x as f32 / 2.0) + 0.5;
points[x + 1] = i_value; points[x + 1] = i_value;
x += 2; x += 2;
} }
@@ -90,14 +90,14 @@ impl GridSampler for DefaultGridSampler {
let mut x = 0; let mut x = 0;
while x < max { while x < max {
// for (int x = 0; x < max; x += 2) { // for (int x = 0; x < max; x += 2) {
if points[x].floor() as u32 >= image.getWidth() if points[x] as u32 >= image.getWidth()
|| points[x + 1].floor() as u32 >= image.getHeight() || points[x + 1] as u32 >= image.getHeight()
{ {
return Err(Exceptions::NotFoundException(Some( return Err(Exceptions::NotFoundException(Some(
"index out of bounds, see documentation in file for explanation".to_owned(), "index out of bounds, see documentation in file for explanation".to_owned(),
))); )));
} }
if image.get(points[x].floor() as u32, points[x + 1].floor() as u32) { if image.get(points[x] as u32, points[x + 1] as u32) {
// Black(-ish) pixel // Black(-ish) pixel
bits.set(x as u32 / 2, y); bits.set(x as u32 / 2, y);
} }

View File

@@ -332,7 +332,7 @@ impl<'a> Detector<'_> {
dimensionX: u32, dimensionX: u32,
dimensionY: u32, dimensionY: u32,
) -> Result<BitMatrix, Exceptions> { ) -> Result<BitMatrix, Exceptions> {
let sampler = DefaultGridSampler {}; let sampler = DefaultGridSampler::default();
sampler.sample_grid_detailed( sampler.sample_grid_detailed(
image, image,