refactor to use exception helper factories

This commit is contained in:
Vukašin Stepanović
2023-02-15 10:46:13 +00:00
parent 3e27279dc8
commit 722ce78fd0
132 changed files with 966 additions and 1132 deletions

View File

@@ -53,9 +53,7 @@ impl<'a> Detector<'_> {
if let Some(point) = self.correctTopRight(&points) {
points[3] = point;
} else {
return Err(Exceptions::NotFoundException(Some(
"point 4 unfound".to_owned(),
)));
return Err(Exceptions::notFound("point 4 unfound".to_owned()));
}
// points[3] = self.correctTopRight(&points);
// if points[3] == null {

View File

@@ -254,7 +254,7 @@ fn Scan(
));
}
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFoundEmpty())
}
pub fn detect(
@@ -359,6 +359,6 @@ pub fn detect(
}
// #ifndef __cpp_impl_coroutine
Err(Exceptions::NotFoundException(None))
Err(Exceptions::notFoundEmpty())
// #endif
}

View File

@@ -76,7 +76,7 @@ impl RegressionLine for DMRegressionLine {
fn add(&mut self, p: &RXingResultPoint) -> Result<(), Exceptions> {
if self.direction_inward == RXingResultPoint::default() {
return Err(Exceptions::IllegalStateException(None));
return Err(Exceptions::illegalStateEmpty());
}
self.points.push(*p);
if self.points.len() == 1 {
@@ -241,7 +241,7 @@ impl DMRegressionLine {
end: &RXingResultPoint,
) -> Result<f64, Exceptions> {
if self.points.len() <= 3 {
return Err(Exceptions::IllegalStateException(None));
return Err(Exceptions::illegalStateEmpty());
}
// re-evaluate and filter out all points too far away. required for the gapSizes calculation.
@@ -267,11 +267,11 @@ impl DMRegressionLine {
&(*self
.points
.last()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
- *self
.points
.first()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
)) as f64;
// calculate the width of 2 modules (first black pixel to first black pixel)
@@ -297,7 +297,7 @@ impl DMRegressionLine {
&self.project(
self.points
.last()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
),
) as f64,
);

View File

@@ -199,7 +199,7 @@ impl<'a> EdgeTracer<'_> {
if self.whiteAt(&pEdge) {
// if we are not making any progress, we still have another endless loop bug
if self.p == RXingResultPoint::centered(&pEdge) {
return Err(Exceptions::IllegalStateException(None));
return Err(Exceptions::illegalStateEmpty());
}
self.p = RXingResultPoint::centered(&pEdge);
@@ -277,7 +277,7 @@ impl<'a> EdgeTracer<'_> {
.points()
.first()
.as_ref()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
) {
return Ok(false);
}
@@ -307,9 +307,9 @@ impl<'a> EdgeTracer<'_> {
.points()
.last()
.as_ref()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?)
.ok_or(Exceptions::indexOutOfBoundsEmpty())?)
{
return Err(Exceptions::IllegalStateException(None));
return Err(Exceptions::illegalStateEmpty());
}
if !line.points().is_empty()
&& &&self.p
@@ -317,7 +317,7 @@ impl<'a> EdgeTracer<'_> {
.points()
.last()
.as_ref()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
{
return Ok(false);
}
@@ -363,7 +363,7 @@ impl<'a> EdgeTracer<'_> {
line.points()
.last()
.as_ref()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
),
) < 1.0
{
@@ -380,7 +380,7 @@ impl<'a> EdgeTracer<'_> {
- line
.points()
.last()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?,
.ok_or(Exceptions::indexOutOfBoundsEmpty())?,
)
};
line.add(&self.p)?;
@@ -396,7 +396,7 @@ impl<'a> EdgeTracer<'_> {
+ *line
.points()
.first()
.ok_or(Exceptions::IndexOutOfBoundsException(None))?),
.ok_or(Exceptions::indexOutOfBoundsEmpty())?),
) {
return Ok(false);
}

View File

@@ -26,7 +26,7 @@ pub fn intersect(
l2: &DMRegressionLine,
) -> Result<RXingResultPoint, Exceptions> {
if !(l1.isValid() && l2.isValid()) {
return Err(Exceptions::IllegalStateException(None));
return Err(Exceptions::illegalStateEmpty());
}
let d = l1.a * l2.b - l1.b * l2.a;
let x = (l1.c * l2.b - l1.b * l2.c) / d;