mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
switch to using Point in one-d-derive macros
Also start updates to make point more generic, still not complete or fully implemented. Some code cleanup
This commit is contained in:
@@ -159,7 +159,7 @@ impl BitSource {
|
||||
let mask = (0xFF >> bits_to_not_read) << bits_to_not_read;
|
||||
result = (result << num_bits)
|
||||
| ((self.bytes[byte_offset] & mask) as u32 >> bits_to_not_read);
|
||||
bit_offset += num_bits;
|
||||
//bit_offset += num_bits; // Removed, this is a holdover from setting the actual values in c++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -228,9 +228,10 @@ impl<'a> PatternView<'a> {
|
||||
let mut size = size.unwrap_or(0);
|
||||
if size == 0 {
|
||||
size = self.count - offset;
|
||||
} else if size < 0 {
|
||||
size += self.count - offset;
|
||||
}
|
||||
}
|
||||
// else if size < 0 {
|
||||
// size += self.count - offset;
|
||||
// }
|
||||
|
||||
PatternView {
|
||||
data: self.data,
|
||||
|
||||
@@ -145,7 +145,7 @@ pub fn ToAlphaNumericChar(value: u32) -> Result<char> {
|
||||
' ', '$', '%', '*', '+', '-', '.', '/', ':',
|
||||
];
|
||||
|
||||
if value < 0 || value >= (ALPHANUMERIC_CHARS.len()) {
|
||||
if value >= (ALPHANUMERIC_CHARS.len()) {
|
||||
return Err(Exceptions::index_out_of_bounds_with(
|
||||
"oAlphaNumericChar: out of range",
|
||||
));
|
||||
|
||||
@@ -590,20 +590,23 @@ pub fn SampleQR(image: &BitMatrix, fp: &FinderPatternSet) -> Result<QRCodeDetect
|
||||
// #if 1
|
||||
let apM = version.as_ref().unwrap().getAlignmentPatternCenters(); // alignment pattern positions in modules
|
||||
let mut apP = Matrix::new(apM.len(), apM.len())?; // found/guessed alignment pattern positions in pixels
|
||||
// let apP = Matrix<std::optional<PointF>>(Size(apM), Size(apM)); // found/guessed alignment pattern positions in pixels
|
||||
let N = (apM.len()) - 1;
|
||||
|
||||
// project the alignment pattern at module coordinates x/y to pixel coordinate based on current mod2Pix
|
||||
let projectM2P = /*[&mod2Pix, &apM]*/| x, y, mod2Pix: &PerspectiveTransform| { mod2Pix.transform_point(Point::centered(point_i(apM[x], apM[y]))) };
|
||||
let projectM2P = |x, y, mod2Pix: &PerspectiveTransform| {
|
||||
mod2Pix.transform_point(Point::centered(point_i(apM[x], apM[y])))
|
||||
};
|
||||
|
||||
let mut findInnerCornerOfConcentricPattern = /*[&image, &apP, &projectM2P]*/| x, y, fp:ConcentricPattern| {
|
||||
let pc = apP.set(x, y, projectM2P(x, y, &mod2Pix));
|
||||
if let Some(fpQuad) = FindConcentricPatternCorners(image, fp.p, fp.size, 2)
|
||||
// if (auto fpQuad = FindConcentricPatternCorners(image, fp, fp.size, 2))
|
||||
{for c in fpQuad .0
|
||||
{if Point::distance(c, pc) < (fp.size as f32) / 2.0
|
||||
{apP.set(x, y, c);}}}
|
||||
};
|
||||
let mut findInnerCornerOfConcentricPattern = |x, y, fp: ConcentricPattern| {
|
||||
let pc = apP.set(x, y, projectM2P(x, y, &mod2Pix));
|
||||
if let Some(fpQuad) = FindConcentricPatternCorners(image, fp.p, fp.size, 2) {
|
||||
for c in fpQuad.0 {
|
||||
if Point::distance(c, pc) < (fp.size as f32) / 2.0 {
|
||||
apP.set(x, y, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
findInnerCornerOfConcentricPattern(0, 0, fp.tl);
|
||||
findInnerCornerOfConcentricPattern(0, N, fp.bl);
|
||||
@@ -823,11 +826,10 @@ pub fn DetectPureQR(image: &BitMatrix) -> Result<QRCodeDetectorResult> {
|
||||
[tr, point(-1.0, 1.0)],
|
||||
[bl, point(1.0, -1.0)],
|
||||
] {
|
||||
// for (auto [p, d] : {std::pair(tl, PointI{1, 1}), {tr, {-1, 1}}, {bl, {1, -1}}}) {
|
||||
diagonal = EdgeTracer::new(image, p, d)
|
||||
.readPatternFromBlack(1, Some((width / 3 + 1) as i32))
|
||||
.ok_or(Exceptions::NOT_FOUND)?;
|
||||
// diagonal = BitMatrixCursorI(image, p, d).readPatternFromBlack<Pattern>(1, width / 3 + 1);
|
||||
|
||||
let diag_hld = diagonal.to_vec().into();
|
||||
let view = PatternView::new(&diag_hld);
|
||||
if !(IsPattern::<E2E, 5, 7, false>(&view, &PATTERN, None, 0.0, 0.0) != 0.0) {
|
||||
|
||||
@@ -15,9 +15,37 @@ use crate::ResultPoint;
|
||||
*/
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct Point {
|
||||
pub(crate) x: f32,
|
||||
pub(crate) y: f32,
|
||||
pub struct PointT<T> {
|
||||
pub x: T,
|
||||
pub y: T,
|
||||
}
|
||||
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
// #[derive(Debug, Clone, Copy, Default)]
|
||||
// pub struct Point {
|
||||
// pub(crate) x: f32,
|
||||
// pub(crate) y: f32,
|
||||
// }
|
||||
|
||||
pub type PointF = PointT<f32>;
|
||||
pub type PointI = PointT<u32>;
|
||||
pub type Point = PointF;
|
||||
|
||||
impl Into<PointI> for Point {
|
||||
fn into(self) -> PointI {
|
||||
PointI{
|
||||
x: self.x.floor() as u32,
|
||||
y: self.y.floor() as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Point> for PointI {
|
||||
fn into(self) -> Point {
|
||||
Point {
|
||||
x: self.x as f32,
|
||||
y: self.y as f32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** An alias for `Point::new`. */
|
||||
@@ -33,9 +61,6 @@ pub fn point_i<T: Into<i64>>(x: T, y: T) -> Point {
|
||||
Point::new(x.into() as f32, y.into() as f32)
|
||||
}
|
||||
|
||||
/** Currently necessary because the external OneDReader proc macro uses it. */
|
||||
pub type RXingResultPoint = Point;
|
||||
|
||||
impl Hash for Point {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.x.to_string().hash(state);
|
||||
|
||||
Reference in New Issue
Block a user