Skip to content

Commit

Permalink
find_cut: Skip absurd line rectangles
Browse files Browse the repository at this point in the history
This is a workaround for an awful bug in tesseract:
    tesseract-ocr/tesseract#1192
  • Loading branch information
baskerville committed Feb 18, 2019
1 parent 36ec823 commit 10c39c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,11 @@ impl Boundary {
self.min.x < rect.max.x && rect.min.x < self.max.x &&
self.min.y < rect.max.y && rect.min.y < self.max.y
}

pub fn contains(&self, rect: &Boundary) -> bool {
rect.min.x >= self.min.x && rect.max.x <= self.max.x &&
rect.min.y >= self.min.y && rect.max.y <= self.max.y
}
}

#[macro_export]
Expand Down
3 changes: 2 additions & 1 deletion src/view/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn find_cut(frame: &Rectangle, y_pos: i32, scale: f32, dir: LinearDir, lines: &[
let mut rect_a: Option<Boundary> = None;

for line in lines {
if frame_u.overlaps(&line.rect) && y_pos_u >= line.rect.min.y && y_pos_u < line.rect.max.y {
if frame_u.overlaps(&line.rect) && !line.rect.contains(&frame_u) && y_pos_u >= line.rect.min.y && y_pos_u < line.rect.max.y {
rect_a = Some(line.rect);
break;
}
Expand Down Expand Up @@ -498,6 +498,7 @@ impl Reader {
fn go_to_neighbor(&mut self, dir: CycleDir, hub: &Hub, context: &mut Context) {
let current_page = self.current_page;
let top_offset = self.view_port.top_offset;

let loc = {
let neighloc = if dir == CycleDir::Previous {
match self.view_port.zoom_mode {
Expand Down

0 comments on commit 10c39c6

Please sign in to comment.