Skip to content

Commit

Permalink
Fix crash -- need to always use epsilon check for points
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jun 13, 2024
1 parent 1c5d839 commit 0a08bff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ pub fn find_widths(input: String, raw_cfg: JsValue) -> Result<String, JsValue> {
String::new()
};

for mut pavement in pavements {
let len = pavements.len();
for (idx, mut pavement) in pavements.into_iter().enumerate() {
log::info!("Working on input {idx} / {len}");
pavement.calculate(&cfg);

input_polygons.push(pavement.polygon);
Expand Down
15 changes: 11 additions & 4 deletions widths/src/join_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,25 @@ fn join_path(lines: Vec<LineString>, path: Vec<EdgeIdx>) -> Vec<LineString> {
let mut next = lines[idx.0].clone().into_inner();
if points.is_empty() {
points = next;
} else if points.first() == next.first() {
continue;
}
let pt1 = HashedPoint::new(*points.first().unwrap());
let pt2 = HashedPoint::new(*points.last().unwrap());
let pt3 = HashedPoint::new(*next.first().unwrap());
let pt4 = HashedPoint::new(*next.last().unwrap());

if pt1 == pt3 {
points.reverse();
points.pop();
points.extend(next);
} else if points.first() == next.last() {
} else if pt1 == pt4 {
next.pop();
next.extend(points);
points = next;
} else if points.last() == next.first() {
} else if pt2 == pt3 {
points.pop();
points.extend(next);
} else if points.last() == next.last() {
} else if pt2 == pt4 {
next.reverse();
points.pop();
points.extend(next);
Expand Down

0 comments on commit 0a08bff

Please sign in to comment.