begin cleanup

This commit is contained in:
Henry Schimke
2023-04-03 12:52:01 -05:00
parent 1ef262e967
commit 169db55a82
2 changed files with 15 additions and 4 deletions

View File

@@ -116,7 +116,11 @@ impl<'a> PatternView<'_> {
Some(*self.data.0.get(self.start)?) Some(*self.data.0.get(self.start)?)
} }
pub fn end(&self) -> Option<PatternType> { pub fn end(&self) -> Option<PatternType> {
Some(self.data.0[self.start + self.count]) if self.start + self.count < self.data.0.len() {
Some(self.data.0[self.start + self.count])
}else {
None
}
} }
// int sum(int n = 0) const { return std::accumulate(_data, _data + (n == 0 ? _size : n), 0); } // int sum(int n = 0) const { return std::accumulate(_data, _data + (n == 0 ? _size : n), 0); }
@@ -473,7 +477,7 @@ pub fn FindLeftGuardBy<'a, const LEN: usize, Pred: Fn(&PatternView, Option<f32>)
if window.isAtFirstBar() && isGuard(&window, None) { if window.isAtFirstBar() && isGuard(&window, None) {
return Ok(window); return Ok(window);
} }
let end = Into::<usize>::into(view.end().unwrap()) - minSize; let end = Into::<usize>::into(view.end().ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?) - minSize;
while window.start < end { while window.start < end {
if isGuard(&window, Some(Into::<f32>::into(window[PREV_IDX]))) { if isGuard(&window, Some(Into::<f32>::into(window[PREV_IDX]))) {
return Ok(window); return Ok(window);

View File

@@ -61,8 +61,15 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns
let mut next: PatternView = PatternView::new(&row); let mut next: PatternView = PatternView::new(&row);
while { while {
let next = FindLeftGuard(&next, 0, &PATTERN, 0.5).unwrap(); if let Ok(next) = FindLeftGuard(&next, 0, &PATTERN, 0.5) {
next.isValid() next.isValid()
}else {
false
}
// let Ok(next) = FindLeftGuard(&next, 0, &PATTERN, 0.5) else {
// break;
// };
// next.isValid()
} { } {
let p = point( let p = point(
next.pixelsInFront() as f32 next.pixelsInFront() as f32