From 5d6f4b1d94976f951905d9e31f93d999e6cb4fc0 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Sun, 12 Mar 2023 11:53:52 -0500 Subject: [PATCH] clippy --fix --- .../cpp_essentials/concentric_finder.rs | 84 +++++++++---------- .../fast_edge_to_edge_counter.rs | 4 +- src/common/cpp_essentials/pattern.rs | 6 +- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/common/cpp_essentials/concentric_finder.rs b/src/common/cpp_essentials/concentric_finder.rs index 04cddd4..7758738 100644 --- a/src/common/cpp_essentials/concentric_finder.rs +++ b/src/common/cpp_essentials/concentric_finder.rs @@ -17,7 +17,7 @@ pub fn CenterFromEnd + std::iter::Sum + Copy>( pattern: &[T; N], end: f32, ) -> f32 { - if (N == 5) { + if N == 5 { let a: f32 = pattern[4].into() + pattern[3].into() + pattern[2].into() / 2.0; let b: f32 = pattern[4].into() + (pattern[3].into() + pattern[2].into() + pattern[1].into()) / 2.0; @@ -28,7 +28,7 @@ pub fn CenterFromEnd + std::iter::Sum + Copy>( + pattern[0].into()) / 2.0; end - (2.0 * a + b + c) / 4.0 - } else if (N == 3) { + } else if N == 3 { let a: f32 = pattern[2].into() + pattern[1].into() / 2.0; let b: f32 = (pattern[2].into() + pattern[1].into() + pattern[0].into()) / 2.0; end - (2.0 * a + b) / 3.0 @@ -59,7 +59,7 @@ pub fn ReadSymmetricPattern( let v = cur.stepToEdge(Some(1), Some(range), None); res[(s_2 + i) as usize] = (res[(s_2 + i) as usize] as i32 + v) as u16; // res[(s_2 + i) as usize] += v; - if (range != 0) { + if range != 0 { range -= v; } @@ -68,7 +68,7 @@ pub fn ReadSymmetricPattern( for i in 0..=s_2 { // for (int i = 0; i <= s_2; ++i) { - if (!next(cur, i) != 0 || !next(&mut cuo, -i) != 0) { + if !next(cur, i) != 0 || !next(&mut cuo, -i) != 0 { return None; } } @@ -95,11 +95,11 @@ pub fn CheckSymmetricPattern< let curBwd: FastEdgeToEdgeCounter = FastEdgeToEdgeCounter::new(&cur.turnedBack()); let centerFwd = curFwd.stepToNextEdge(range); - if (!(centerFwd != 0)) { + if centerFwd == 0 { return 0; } let centerBwd = curBwd.stepToNextEdge(range); - if (!(centerBwd != 0)) { + if centerBwd == 0 { return 0; } @@ -119,25 +119,25 @@ pub fn CheckSymmetricPattern< for i in 1..=s_2 { // for (int i = 1; i <= s_2; ++i) { - if (!(next(&curFwd, i as isize) != 0) || !(next(&curBwd, -(i as isize)) != 0)) { + if next(&curFwd, i as isize) == 0 || next(&curBwd, -(i as isize)) == 0 { return 0; } } - if (!(IsPattern( + if !(IsPattern( &PatternView::new(&res), &FixedPattern::::with_reference(pattern), None, 0.0, 0.0, Some(RELAXED_THRESHOLD), - ) != 0.0)) + ) != 0.0) { return 0; } - if (updatePosition) { - cur.step(Some((res[s_2] as i32 / 2 - (centerBwd as i32 - 1)) as f32)); + if updatePosition { + cur.step(Some((res[s_2] as i32 / 2 - (centerBwd - 1)) as f32)); } res.into_iter().sum::() as i32 @@ -150,9 +150,9 @@ pub fn AverageEdgePixels( ) -> Option { let mut sum = Point::default(); - for i in 0..numOfEdges { + for _i in 0..numOfEdges { // for (int i = 0; i < numOfEdges; ++i) { - if (!cur.isInSelf()) { + if !cur.isInSelf() { return None; } cur.stepToEdge(Some(1), Some(range), None); @@ -200,7 +200,7 @@ pub fn CenterOfRing( let nth = nth.abs(); // log(center, 3); let mut cur = EdgeTracer::new(image, center, point(0.0, 1.0)); - if (!(cur.stepToEdge(Some(nth), Some(radius), Some(inner)) != 0)) { + if cur.stepToEdge(Some(nth), Some(radius), Some(inner)) == 0 { return None; } cur.turnRight(); // move clock wise and keep edge on the right/left depending on backup @@ -220,18 +220,18 @@ pub fn CenterOfRing( n += 1; // find out if we come full circle around the center. 8 bits have to be set in the end. - neighbourMask |= (1 + neighbourMask |= 1 << (4.0 + Point::dot(Point::bresenhamDirection(cur.p() - center), point(1.0, 3.0))) - as u32); + as u32; - if (!cur.stepAlongEdge(edgeDir, None)) { + if !cur.stepAlongEdge(edgeDir, None) { return None; } // use L-inf norm, simply because it is a lot faster than L2-norm and sufficiently accurate - if (Point::maxAbsComponent(cur.p - center) > radius as f32 + if Point::maxAbsComponent(cur.p - center) > radius as f32 || center == cur.p - || n > 4 * 2 * range) + || n > 4 * 2 * range { return None; } @@ -241,7 +241,7 @@ pub fn CenterOfRing( } } //while (cur.p != start); - if (requireCircle && neighbourMask != 0b111101111) { + if requireCircle && neighbourMask != 0b111101111 { return None; } @@ -281,13 +281,13 @@ pub fn FinetuneConcentricPatternCenter( let mut res = CenterOfRings(image, center, range, finderPatternSize / 2); - if (res.is_none() || !image.get_point(res?)) { - res = CenterOfDoubleCross(image, (center), range, finderPatternSize / 2 + 1); + if res.is_none() || !image.get_point(res?) { + res = CenterOfDoubleCross(image, center, range, finderPatternSize / 2 + 1); } - if (res.is_none() || !image.get_point(res?)) { + if res.is_none() || !image.get_point(res?) { res = Some(center); } - if (res.is_none() || !image.get_point(res?)) { + if res.is_none() || !image.get_point(res?) { return None; } @@ -304,7 +304,7 @@ pub fn CollectRingPoints( let centerI = center.round(); let radius = range; let mut cur = EdgeTracer::new(image, centerI, point(0.0, 1.0)); - if (!(cur.stepToEdge(Some(edgeIndex), Some(radius), Some(backup)) != 0)) { + if cur.stepToEdge(Some(edgeIndex), Some(radius), Some(backup)) == 0 { return Vec::default(); } cur.turnRight(); // move clock wise and keep edge on the right/left depending on backup @@ -320,21 +320,21 @@ pub fn CollectRingPoints( loop { // log(cur.p, 4); - points.push((cur.p().centered())); + points.push(cur.p().centered()); // find out if we come full circle around the center. 8 bits have to be set in the end. - neighbourMask |= (1 + neighbourMask |= 1 << (4.0 + Point::dot(Point::bresenhamDirection(cur.p - centerI), point(1.0, 3.0))) - as u32); + as u32; - if (!cur.stepAlongEdge(edgeDir, None)) { + if !cur.stepAlongEdge(edgeDir, None) { return Vec::default(); } // use L-inf norm, simply because it is a lot faster than L2-norm and sufficiently accurate - if (Point::maxAbsComponent(cur.p - centerI) > radius as f32 + if Point::maxAbsComponent(cur.p - centerI) > radius as f32 || centerI == cur.p - || (points).len() > 4 * 2 * range as usize) + || (points).len() > 4 * 2 * range as usize { return Vec::default(); } @@ -344,7 +344,7 @@ pub fn CollectRingPoints( } } //while (cur.p != start); - if (neighbourMask != 0b111101111) { + if neighbourMask != 0b111101111 { return Vec::default(); } @@ -389,7 +389,7 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option Option Option { let mut points = CollectRingPoints(image, center, range, lineIndex, backup); - if (points.is_empty()) { + if points.is_empty() { return None; } let res = FitQadrilateralToPoints(center, &mut points)?; - if (!QuadrilateralIsPlausibleSquare(&res, (lineIndex - i32::from(backup)) as usize)) { + if !QuadrilateralIsPlausibleSquare(&res, (lineIndex - i32::from(backup)) as usize) { return None; } @@ -506,7 +506,7 @@ pub fn LocateConcentricPattern< cur.setDirection(d); // THIS COULD POSSIBLY BE WRONG, WE MIGHT MEAN TO CLONE cur EACH RUN? let spread = CheckSymmetricPattern::(&mut cur, pattern, range, true); - if (!(spread != 0)) { + if spread == 0 { return None; } UpdateMinMax(&mut minSpread, &mut maxSpread, spread); @@ -522,14 +522,14 @@ pub fn LocateConcentricPattern< range * 2, false, ); - if (!(spread != 0)) { + if spread == 0 { return None; } UpdateMinMax(&mut minSpread, &mut maxSpread, spread); } //#endif - if (maxSpread > 5 * minSpread) { + if maxSpread > 5 * minSpread { return None; } diff --git a/src/common/cpp_essentials/fast_edge_to_edge_counter.rs b/src/common/cpp_essentials/fast_edge_to_edge_counter.rs index cd0b7b3..406681a 100644 --- a/src/common/cpp_essentials/fast_edge_to_edge_counter.rs +++ b/src/common/cpp_essentials/fast_edge_to_edge_counter.rs @@ -7,7 +7,7 @@ pub struct FastEdgeToEdgeCounter { } impl FastEdgeToEdgeCounter { - pub fn new(cur: &T) -> Self { + pub fn new(_cur: &T) -> Self { todo!() // stride = cur.d.y * cur.img->width() + cur.d.x; // p = cur.img->row(cur.p.y).begin() + cur.p.x; @@ -17,7 +17,7 @@ impl FastEdgeToEdgeCounter { // stepsToBorder = std::min(maxStepsX, maxStepsY); } - pub fn stepToNextEdge(&self, range: i32) -> i32 { + pub fn stepToNextEdge(&self, _range: i32) -> i32 { todo!() // int maxSteps = std::min(stepsToBorder, range); // int steps = 0; diff --git a/src/common/cpp_essentials/pattern.rs b/src/common/cpp_essentials/pattern.rs index 3b6d82c..9198d1b 100644 --- a/src/common/cpp_essentials/pattern.rs +++ b/src/common/cpp_essentials/pattern.rs @@ -343,7 +343,7 @@ impl FixedPattern Self { - FixedPattern { data: data.clone() } + FixedPattern { data: *data } } fn as_slice(&self) -> &[PatternType] { @@ -655,9 +655,7 @@ mod tests { fn basic_pattern_view() { let mut p_row = PatternRow::default(); GetPatternRow( - &vec![ - 0_u16, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, - ], + &[0_u16, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1], &mut p_row, );