mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 20:32:34 +00:00
code cleanup
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
use crate::qrcode::decoder::ErrorCorrectionLevel;
|
||||
|
||||
impl ErrorCorrectionLevel {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
use crate::qrcode::decoder::{
|
||||
ErrorCorrectionLevel, FormatInformation, FORMAT_INFO_DECODE_LOOKUP, FORMAT_INFO_MASK_QR,
|
||||
};
|
||||
|
||||
@@ -8,8 +8,6 @@ use crate::{
|
||||
point, Point,
|
||||
};
|
||||
|
||||
|
||||
|
||||
use super::{
|
||||
BitMatrixCursorTrait, EdgeTracer, FastEdgeToEdgeCounter, Pattern, RegressionLine,
|
||||
RegressionLineTrait, UpdateMinMax, UpdateMinMaxFloat,
|
||||
@@ -342,18 +340,11 @@ pub fn CollectRingPoints(
|
||||
}
|
||||
|
||||
pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Quadrilateral> {
|
||||
let _dist2Center = |a, b| Point::distance(a, center) < Point::distance(b, center);
|
||||
// rotate points such that the first one is the furthest away from the center (hence, a corner)
|
||||
|
||||
let max_by_pred = |a: &&Point, b: &&Point| {
|
||||
let da = Point::distance(**a, center);
|
||||
let db = Point::distance(**b, center);
|
||||
da.partial_cmp(&db).unwrap()
|
||||
// if dist2Center(**a, **b) {
|
||||
// std::cmp::Ordering::Greater
|
||||
// } else {
|
||||
// std::cmp::Ordering::Less
|
||||
// }
|
||||
};
|
||||
|
||||
let max = points.iter().max_by(max_by_pred)?;
|
||||
@@ -361,7 +352,6 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
|
||||
let pos = points.iter().position(|e| e == max)?;
|
||||
|
||||
points.rotate_left(pos);
|
||||
// std::rotate(points.begin(), std::max_element(points.begin(), points.end(), dist2Center), points.end());
|
||||
|
||||
let mut corners = [Point::default(); 4];
|
||||
corners[0] = points[0];
|
||||
@@ -372,17 +362,11 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
|
||||
// corners[2] = std::max_element(&points[Size(points) * 3 / 8], &points[Size(points) * 5 / 8], dist2Center);
|
||||
// find the two in between corners by looking for the points farthest from the long diagonal
|
||||
let l = RegressionLine::with_two_points(corners[0], corners[2]);
|
||||
let _dist2Diagonal = /*[l = RegressionLine(*corners[0], *corners[2])]*/| a, b| { l.distance_single(a) < l.distance_single(b) };
|
||||
|
||||
let diagonal_max_by_pred = |p1: &Point, p2: &Point| {
|
||||
let d1 = l.distance_single(*p1);
|
||||
let d2 = l.distance_single(*p2);
|
||||
d1.partial_cmp(&d2).unwrap()
|
||||
// if dist2Diagonal(*p1, *p2) {
|
||||
// std::cmp::Ordering::Greater
|
||||
// } else {
|
||||
// std::cmp::Ordering::Less
|
||||
// }
|
||||
};
|
||||
corners[1] = points[(points.len() / 8)..=(points.len() * 3 / 8)]
|
||||
.iter()
|
||||
@@ -417,14 +401,6 @@ pub fn FitQadrilateralToPoints(center: Point, points: &mut [Point]) -> Option<Qu
|
||||
RegressionLine::with_point_slice(try_get_range(corner_positions[3], points.len())?),
|
||||
];
|
||||
|
||||
// let lines = [
|
||||
// RegressionLine::with_point_slice(&points[corner_positions[0] + 1..corner_positions[1]]),
|
||||
// RegressionLine::with_point_slice(&points[corner_positions[1] + 1..corner_positions[2]]),
|
||||
// RegressionLine::with_point_slice(&points[corner_positions[2] + 1..corner_positions[3]]),
|
||||
// RegressionLine::with_point_slice(&points[corner_positions[3] + 1..points.len()]),
|
||||
// ];
|
||||
// std::array lines{RegressionLine{corners[0] + 1, corners[1]}, RegressionLine{corners[1] + 1, corners[2]},
|
||||
// RegressionLine{corners[2] + 1, corners[3]}, RegressionLine{corners[3] + 1, &points.back() + 1}};
|
||||
if lines.iter().any(|line| !line.isValid()) {
|
||||
return None;
|
||||
}
|
||||
@@ -515,15 +491,6 @@ pub fn FindConcentricPatternCorners(
|
||||
|
||||
let res = Quadrilateral::blend(&innerCorners, &outerCorners);
|
||||
|
||||
// for p in innerCorners{
|
||||
// log(p, 3);}
|
||||
|
||||
// for p in outerCorners{
|
||||
// log(p, 3);}
|
||||
|
||||
// for p in res{
|
||||
// log(p, 3);}
|
||||
|
||||
Some(res)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{rc::Rc};
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{common::ECIStringBuilder, Exceptions};
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ impl<'a> FastEdgeToEdgeCounter<'a> {
|
||||
stride,
|
||||
stepsToBorder,
|
||||
_arr: cur.p().y as isize * stride, //cur.img().getRow(cur.p().y as u32),
|
||||
under_arry: cur.img(), //.into(),
|
||||
under_arry: cur.img(), //.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -217,11 +217,6 @@ impl<'a> PatternView<'a> {
|
||||
|| Into::<f32>::into(self.data.0[self.count])
|
||||
>= Into::<f32>::into(self.sum(None)) * scale
|
||||
}
|
||||
// template<bool acceptIfAtFirstBar = false>
|
||||
// bool hasQuietZoneBefore(float scale) const
|
||||
// {
|
||||
// return (acceptIfAtFirstBar && isAtFirstBar()) || _data[-1] >= sum() * scale;
|
||||
// }
|
||||
|
||||
pub fn hasQuietZoneAfter(&self, scale: f32, acceptIfAtLastBar: Option<bool>) -> bool {
|
||||
(acceptIfAtLastBar.unwrap_or(true) && self.isAtLastBar())
|
||||
@@ -229,12 +224,6 @@ impl<'a> PatternView<'a> {
|
||||
>= Into::<f32>::into(self.sum(None)) * scale
|
||||
}
|
||||
|
||||
// template<bool acceptIfAtLastBar = true>
|
||||
// bool hasQuietZoneAfter(float scale) const
|
||||
// {
|
||||
// return (acceptIfAtLastBar && isAtLastBar()) || _data[_size] >= sum() * scale;
|
||||
// }
|
||||
|
||||
pub fn subView(&self, offset: usize, size: Option<usize>) -> PatternView<'a> {
|
||||
let mut size = size.unwrap_or(0);
|
||||
if size == 0 {
|
||||
@@ -251,28 +240,11 @@ impl<'a> PatternView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
// PatternView subView(int offset, int size = 0) const
|
||||
// {
|
||||
// // if(std::abs(size) > count())
|
||||
// // printf("%d > %d\n", std::abs(size), _count);
|
||||
// // assert(std::abs(size) <= count());
|
||||
// if (size == 0)
|
||||
// size = _size - offset;
|
||||
// else if (size < 0)
|
||||
// size = _size - offset + size;
|
||||
// return {begin() + offset, std::max(size, 0), _base, _end};
|
||||
// }
|
||||
|
||||
pub fn shift(&mut self, n: usize) -> bool {
|
||||
self.current += n;
|
||||
!self.data.0.is_empty() && self.start + self.count <= (self.start + self.count)
|
||||
}
|
||||
|
||||
// bool shift(int n)
|
||||
// {
|
||||
// return _data && ((_data += n) + _size <= _end);
|
||||
// }
|
||||
|
||||
pub fn skipPair(&mut self) -> bool {
|
||||
self.shift(2)
|
||||
}
|
||||
@@ -361,6 +333,16 @@ impl<'a> Into<Vec<PatternType>> for &PatternView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, const LEN: usize> Into<[PatternType; LEN]> for &PatternView<'a> {
|
||||
fn into(self) -> [PatternType; LEN] {
|
||||
let mut result = [PatternType::default(); LEN];
|
||||
for i in 0..self.count {
|
||||
result[i] = self[i];
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The BarAndSpace struct is a simple 2 element data structure to hold information about bar(s) and space(s).
|
||||
*
|
||||
@@ -407,7 +389,7 @@ impl<T: Default + std::cmp::PartialEq> std::ops::IndexMut<usize> for BarAndSpace
|
||||
// bool isValid() const { return bar != T{} && space != T{}; }
|
||||
// };
|
||||
|
||||
type BarAndSpaceI = BarAndSpace<PatternType>;
|
||||
// type BarAndSpaceI = BarAndSpace<PatternType>;
|
||||
|
||||
/**
|
||||
* @brief FixedPattern describes a compile-time constant (start/stop) pattern.
|
||||
@@ -488,7 +470,7 @@ pub fn IsPattern<const E2E: bool, const LEN: usize, const SUM: usize, const SPAR
|
||||
|
||||
if E2E {
|
||||
//using float_t = double;
|
||||
let v_src: Vec<PatternType> = view.into();
|
||||
let v_src: [PatternType; LEN] = view.into();
|
||||
let widths = BarAndSpaceSum::<LEN, PatternType, f64>(&v_src);
|
||||
let sums = pattern.sums();
|
||||
let modSize: BarAndSpace<f64> = BarAndSpace {
|
||||
@@ -627,13 +609,8 @@ pub fn FindLeftGuard<'a, const LEN: usize, const SUM: usize, const IS_SPARCE: bo
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IsPattern::<false, LEN, SUM, IS_SPARCE>(
|
||||
window,
|
||||
pattern,
|
||||
spaceInPixel,
|
||||
minQuietZone,
|
||||
0.0,
|
||||
) != 0.0
|
||||
IsPattern::<false, LEN, SUM, IS_SPARCE>(window, pattern, spaceInPixel, minQuietZone, 0.0)
|
||||
!= 0.0
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user