mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
refactor to use common result type
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
common::{detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler},
|
||||
common::{
|
||||
detector::WhiteRectangleDetector, BitMatrix, DefaultGridSampler, GridSampler, Result,
|
||||
},
|
||||
Exceptions, RXingResultPoint, ResultPoint,
|
||||
};
|
||||
|
||||
@@ -32,7 +34,7 @@ pub struct Detector<'a> {
|
||||
rectangleDetector: WhiteRectangleDetector<'a>,
|
||||
}
|
||||
impl<'a> Detector<'_> {
|
||||
pub fn new(image: &'a BitMatrix) -> Result<Detector<'a>, Exceptions> {
|
||||
pub fn new(image: &'a BitMatrix) -> Result<Detector<'a>> {
|
||||
Ok(Detector {
|
||||
rectangleDetector: WhiteRectangleDetector::new_from_image(image)?,
|
||||
image,
|
||||
@@ -45,7 +47,7 @@ impl<'a> Detector<'_> {
|
||||
* @return {@link DetectorRXingResult} encapsulating results of detecting a Data Matrix Code
|
||||
* @throws NotFoundException if no Data Matrix Code can be found
|
||||
*/
|
||||
pub fn detect(&self) -> Result<DatamatrixDetectorResult, Exceptions> {
|
||||
pub fn detect(&self) -> Result<DatamatrixDetectorResult> {
|
||||
let cornerPoints = self.rectangleDetector.detect()?;
|
||||
|
||||
let mut points = self.detectSolid1(cornerPoints);
|
||||
@@ -331,7 +333,7 @@ impl<'a> Detector<'_> {
|
||||
topRight: &RXingResultPoint,
|
||||
dimensionX: u32,
|
||||
dimensionY: u32,
|
||||
) -> Result<BitMatrix, Exceptions> {
|
||||
) -> Result<BitMatrix> {
|
||||
let sampler = DefaultGridSampler::default();
|
||||
|
||||
sampler.sample_grid_detailed(
|
||||
|
||||
@@ -14,7 +14,7 @@ macro_rules! CHECK {
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use crate::{
|
||||
common::{BitMatrix, DefaultGridSampler, GridSampler},
|
||||
common::{BitMatrix, DefaultGridSampler, GridSampler, Result},
|
||||
datamatrix::detector::{
|
||||
zxing_cpp_detector::{util::intersect, BitMatrixCursor, Quadrilateral, RegressionLine},
|
||||
DatamatrixDetectorResult,
|
||||
@@ -37,7 +37,7 @@ use super::{DMRegressionLine, EdgeTracer};
|
||||
fn Scan(
|
||||
startTracer: &mut EdgeTracer,
|
||||
lines: &mut [DMRegressionLine; 4],
|
||||
) -> Result<DatamatrixDetectorResult, Exceptions> {
|
||||
) -> Result<DatamatrixDetectorResult> {
|
||||
while startTracer.step(None) {
|
||||
//log(startTracer.p);
|
||||
|
||||
@@ -261,7 +261,7 @@ pub fn detect(
|
||||
image: &BitMatrix,
|
||||
tryHarder: bool,
|
||||
tryRotate: bool,
|
||||
) -> Result<DatamatrixDetectorResult, Exceptions> {
|
||||
) -> Result<DatamatrixDetectorResult> {
|
||||
// #ifdef PRINT_DEBUG
|
||||
// LogMatrixWriter lmw(log, image, 1, "dm-log.pnm");
|
||||
// // tryRotate = tryHarder = false;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, RXingResultPoint};
|
||||
|
||||
use super::{
|
||||
@@ -74,7 +75,7 @@ impl RegressionLine for DMRegressionLine {
|
||||
self.c = f32::NAN;
|
||||
}
|
||||
|
||||
fn add(&mut self, p: &RXingResultPoint) -> Result<(), Exceptions> {
|
||||
fn add(&mut self, p: &RXingResultPoint) -> Result<()> {
|
||||
if self.direction_inward == RXingResultPoint::default() {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
}
|
||||
@@ -235,11 +236,7 @@ impl DMRegressionLine {
|
||||
self.points.reverse();
|
||||
}
|
||||
|
||||
pub fn modules(
|
||||
&mut self,
|
||||
beg: &RXingResultPoint,
|
||||
end: &RXingResultPoint,
|
||||
) -> Result<f64, Exceptions> {
|
||||
pub fn modules(&mut self, beg: &RXingResultPoint, end: &RXingResultPoint) -> Result<f64> {
|
||||
if self.points.len() <= 3 {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
use crate::{common::BitMatrix, qrcode::encoder::ByteMatrix, Exceptions, RXingResultPoint};
|
||||
use crate::{
|
||||
common::{BitMatrix, Result},
|
||||
qrcode::encoder::ByteMatrix,
|
||||
Exceptions, RXingResultPoint,
|
||||
};
|
||||
|
||||
use super::{BitMatrixCursor, Direction, RegressionLine, StepResult, Value};
|
||||
|
||||
@@ -170,7 +174,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
dEdge: &RXingResultPoint,
|
||||
maxStepSize: i32,
|
||||
goodDirection: bool,
|
||||
) -> Result<StepResult, Exceptions> {
|
||||
) -> Result<StepResult> {
|
||||
let dEdge = RXingResultPoint::mainDirection(*dEdge);
|
||||
for breadth in 1..=(if maxStepSize == 1 {
|
||||
2
|
||||
@@ -262,7 +266,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
&mut self,
|
||||
dEdge: &RXingResultPoint,
|
||||
line: &mut T,
|
||||
) -> Result<bool, Exceptions> {
|
||||
) -> Result<bool> {
|
||||
line.setDirectionInward(dEdge);
|
||||
loop {
|
||||
// log(self.p);
|
||||
@@ -295,7 +299,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
line: &mut T,
|
||||
maxStepSize: i32,
|
||||
finishLine: &mut T,
|
||||
) -> Result<bool, Exceptions> {
|
||||
) -> Result<bool> {
|
||||
let mut maxStepSize = maxStepSize;
|
||||
line.setDirectionInward(dEdge);
|
||||
let mut gaps = 0;
|
||||
@@ -437,7 +441,7 @@ impl<'a> EdgeTracer<'_> {
|
||||
&mut self,
|
||||
dir: &mut RXingResultPoint,
|
||||
corner: &mut RXingResultPoint,
|
||||
) -> Result<bool, Exceptions> {
|
||||
) -> Result<bool> {
|
||||
self.step(None);
|
||||
// log(p);
|
||||
*corner = self.p;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::{Exceptions, RXingResultPoint};
|
||||
use crate::common::Result;
|
||||
use crate::RXingResultPoint;
|
||||
|
||||
pub trait RegressionLine {
|
||||
// points: Vec<RXingResultPoint>,
|
||||
@@ -76,12 +77,12 @@ pub trait RegressionLine {
|
||||
// a = b = c = NAN;
|
||||
// }
|
||||
|
||||
fn add(&mut self, p: &RXingResultPoint) -> Result<(), Exceptions>; //{
|
||||
// assert(_directionInward != PointF());
|
||||
// _points.push_back(p);
|
||||
// if (_points.size() == 1)
|
||||
// c = dot(normal(), p);
|
||||
// }
|
||||
fn add(&mut self, p: &RXingResultPoint) -> Result<()>; //{
|
||||
// assert(_directionInward != PointF());
|
||||
// _points.push_back(p);
|
||||
// if (_points.size() == 1)
|
||||
// c = dot(normal(), p);
|
||||
// }
|
||||
|
||||
fn pop_back(&mut self); // { _points.pop_back(); }
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::common::Result;
|
||||
use crate::{Exceptions, RXingResultPoint};
|
||||
|
||||
use super::{DMRegressionLine, Direction, RegressionLine};
|
||||
@@ -21,10 +22,7 @@ pub fn float_max<T: PartialOrd>(a: T, b: T) -> T {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn intersect(
|
||||
l1: &DMRegressionLine,
|
||||
l2: &DMRegressionLine,
|
||||
) -> Result<RXingResultPoint, Exceptions> {
|
||||
pub fn intersect(l1: &DMRegressionLine, l2: &DMRegressionLine) -> Result<RXingResultPoint> {
|
||||
if !(l1.isValid() && l2.isValid()) {
|
||||
return Err(Exceptions::IllegalStateException(None));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user