Implement clippy suggestions

This commit is contained in:
Henry Schimke
2023-01-04 14:48:16 -06:00
parent c65eadf102
commit 48287631dd
196 changed files with 2465 additions and 2574 deletions

View File

@@ -31,7 +31,7 @@ use std::{f32, i32};
* @return nearest {@code int}
*/
pub fn round(d: f32) -> i32 {
return (d + (if d < 0.0f32 { -0.5f32 } else { 0.5f32 })) as i32;
(d + (if d < 0.0f32 { -0.5f32 } else { 0.5f32 })) as i32
}
/**
@@ -44,7 +44,7 @@ pub fn round(d: f32) -> i32 {
pub fn distance_float(aX: f32, aY: f32, bX: f32, bY: f32) -> f32 {
let xDiff: f64 = (aX - bX).into();
let yDiff: f64 = (aY - bY).into();
return (xDiff * xDiff + yDiff * yDiff).sqrt() as f32;
(xDiff * xDiff + yDiff * yDiff).sqrt() as f32
}
/**
@@ -57,7 +57,7 @@ pub fn distance_float(aX: f32, aY: f32, bX: f32, bY: f32) -> f32 {
pub fn distance_int(aX: i32, aY: i32, bX: i32, bY: i32) -> f32 {
let xDiff: f64 = (aX - bX).into();
let yDiff: f64 = (aY - bY).into();
return (xDiff * xDiff + yDiff * yDiff).sqrt() as f32;
(xDiff * xDiff + yDiff * yDiff).sqrt() as f32
}
/**
@@ -69,7 +69,7 @@ pub fn sum(array: &[i32]) -> i32 {
for a in array {
count += a;
}
return count;
count
}
#[cfg(test)]
@@ -120,7 +120,7 @@ mod tests {
#[test]
fn testSum() {
assert_eq!(0, MathUtils::sum(&vec![]));
assert_eq!(0, MathUtils::sum(&[]));
assert_eq!(1, MathUtils::sum(&[1]));
assert_eq!(4, MathUtils::sum(&[1, 3]));
assert_eq!(0, MathUtils::sum(&[-1, 1]));

View File

@@ -55,8 +55,8 @@ impl MonochromeRectangleDetector {
let width = self.image.getWidth() as i32;
let halfHeight = height / 2;
let halfWidth = width / 2;
let deltaY = 1.max(height as i32 / (MAX_MODULES * 8));
let deltaX = 1.max(width as i32 / (MAX_MODULES * 8));
let deltaY = 1.max(height / (MAX_MODULES * 8));
let deltaX = 1.max(width / (MAX_MODULES * 8));
let mut top = 0;
let mut bottom = height;
@@ -124,7 +124,7 @@ impl MonochromeRectangleDetector {
halfWidth / 4,
)?;
return Ok(vec![pointA, pointB, pointC, pointD]);
Ok(vec![pointA, pointB, pointC, pointD])
}
/**
@@ -161,14 +161,13 @@ impl MonochromeRectangleDetector {
let mut y: i32 = centerY;
let mut x: i32 = centerX;
while y < bottom && y >= top && x < right && x >= left {
let range: Option<Vec<i32>>;
if deltaX == 0 {
let range: Option<Vec<i32>> = if deltaX == 0 {
// horizontal slices, up and down
range = self.blackWhiteRange(y, maxWhiteRun, left, right, true);
self.blackWhiteRange(y, maxWhiteRun, left, right, true)
} else {
// vertical slices, left and right
range = self.blackWhiteRange(x, maxWhiteRun, top, bottom, false);
}
self.blackWhiteRange(x, maxWhiteRun, top, bottom, false)
};
if range.is_none() {
if let Some(lastRange) = lastRange_z {
// lastRange was found
@@ -178,7 +177,7 @@ impl MonochromeRectangleDetector {
if lastRange[1] > centerX {
// straddle, choose one or the other based on direction
return Ok(RXingResultPoint::new(
lastRange[if deltaY > 0 { 0 } else { 1 }] as f32,
lastRange[usize::from(deltaY <= 0)] as f32,
lastY as f32,
));
}
@@ -192,7 +191,7 @@ impl MonochromeRectangleDetector {
if lastRange[1] > centerY {
return Ok(RXingResultPoint::new(
lastX as f32,
lastRange[if deltaX < 0 { 0 } else { 1 }] as f32,
lastRange[usize::from(deltaX >= 0)] as f32,
));
}
return Ok(RXingResultPoint::new(lastX as f32, lastRange[0] as f32));
@@ -202,13 +201,13 @@ impl MonochromeRectangleDetector {
}
}
} else {
return Err(Exceptions::NotFoundException("".to_owned()));
return Err(Exceptions::NotFoundException(None));
}
lastRange_z = range;
y += deltaY;
x += deltaX
}
return Err(Exceptions::NotFoundException("".to_owned()));
Err(Exceptions::NotFoundException(None))
}
/**
@@ -243,10 +242,10 @@ impl MonochromeRectangleDetector {
} else {
self.image.get(fixedDimension as u32, start as u32)
} {
start = start - 1;
start -= 1;
} else {
let whiteRunStart = start;
start = start - 1;
start -= 1;
while start >= minDim
&& !(if horizontal {
self.image.get(start as u32, fixedDimension as u32)
@@ -254,7 +253,7 @@ impl MonochromeRectangleDetector {
self.image.get(fixedDimension as u32, start as u32)
})
{
start = start - 1;
start -= 1;
}
let whiteRunSize = whiteRunStart - start;
if start < minDim || whiteRunSize > maxWhiteRun {
@@ -263,7 +262,7 @@ impl MonochromeRectangleDetector {
}
}
}
start = start + 1;
start += 1;
// Then try right/down
let mut end = center;
@@ -273,10 +272,10 @@ impl MonochromeRectangleDetector {
} else {
self.image.get(fixedDimension as u32, end as u32)
} {
end = end + 1;
end += 1;
} else {
let whiteRunStart = end;
end = end + 1;
end += 1;
while end < maxDim
&& !(if horizontal {
self.image.get(end as u32, fixedDimension as u32)
@@ -284,7 +283,7 @@ impl MonochromeRectangleDetector {
self.image.get(fixedDimension as u32, end as u32)
})
{
end = end + 1;
end += 1;
}
let whiteRunSize = end - whiteRunStart;
if end >= maxDim || whiteRunSize > maxWhiteRun {
@@ -293,12 +292,12 @@ impl MonochromeRectangleDetector {
}
}
}
end = end - 1;
end -= 1;
return if end > start {
if end > start {
Some(vec![start, end])
} else {
None
};
}
}
}

View File

@@ -72,17 +72,17 @@ impl WhiteRectangleDetector {
|| downInit >= image.getHeight() as i32
|| rightInit >= image.getWidth() as i32
{
return Err(Exceptions::NotFoundException("".to_owned()));
return Err(Exceptions::NotFoundException(None));
}
Ok(Self {
image: image.clone(),
height: image.getHeight() as i32,
width: image.getWidth() as i32,
leftInit: leftInit,
rightInit: rightInit,
downInit: downInit,
upInit: upInit,
leftInit,
rightInit,
downInit,
upInit,
})
}
@@ -218,7 +218,7 @@ impl WhiteRectangleDetector {
}
if z.is_none() {
return Err(Exceptions::NotFoundException("".to_owned()));
return Err(Exceptions::NotFoundException(None));
}
let mut t: Option<RXingResultPoint> = None;
@@ -236,7 +236,7 @@ impl WhiteRectangleDetector {
}
if t.is_none() {
return Err(Exceptions::NotFoundException("".to_owned()));
return Err(Exceptions::NotFoundException(None));
}
let mut x: Option<RXingResultPoint> = None;
@@ -254,7 +254,7 @@ impl WhiteRectangleDetector {
}
if x.is_none() {
return Err(Exceptions::NotFoundException("".to_owned()));
return Err(Exceptions::NotFoundException(None));
}
let mut y: Option<RXingResultPoint> = None;
@@ -272,12 +272,12 @@ impl WhiteRectangleDetector {
}
if y.is_none() {
return Err(Exceptions::NotFoundException("".to_owned()));
return Err(Exceptions::NotFoundException(None));
}
return Ok(self.center_edges(&y.unwrap(), &z.unwrap(), &x.unwrap(), &t.unwrap()));
Ok(self.center_edges(&y.unwrap(), &z.unwrap(), &x.unwrap(), &t.unwrap()))
} else {
return Err(Exceptions::NotFoundException("".to_owned()));
Err(Exceptions::NotFoundException(None))
}
}
@@ -299,7 +299,7 @@ impl WhiteRectangleDetector {
return Some(RXingResultPoint::new(x as f32, y as f32));
}
}
return None;
None
}
/**
@@ -339,19 +339,19 @@ impl WhiteRectangleDetector {
let tj = t.getY();
if yi < self.width as f32 / 2.0f32 {
return vec![
vec![
RXingResultPoint::new(ti - CORR as f32, tj + CORR as f32),
RXingResultPoint::new(zi + CORR as f32, zj + CORR as f32),
RXingResultPoint::new(xi - CORR as f32, xj - CORR as f32),
RXingResultPoint::new(yi + CORR as f32, yj - CORR as f32),
];
]
} else {
return vec![
vec![
RXingResultPoint::new(ti + CORR as f32, tj + CORR as f32),
RXingResultPoint::new(zi + CORR as f32, zj - CORR as f32),
RXingResultPoint::new(xi - CORR as f32, xj + CORR as f32),
RXingResultPoint::new(yi - CORR as f32, yj - CORR as f32),
];
]
}
}
@@ -379,6 +379,6 @@ impl WhiteRectangleDetector {
}
}
return false;
false
}
}