Skip to content

Commit

Permalink
fix paths on overlapping layers
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jul 20, 2024
1 parent d6ad58e commit 2464675
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ impl<'m> SearchInstance<'m> {
root: from.0,
interval: (Vec2::new(0.0, 0.0), Vec2::new(0.0, 0.0)),
edge: (0, 0),
polygon_from: u32::MAX,
polygon_from: from.1,
polygon_to: from.1,
previous_polygon_layer: to.1.layer(),
previous_polygon_layer: from.1.layer(),
f: 0.0,
g: 0.0,
};
Expand Down Expand Up @@ -620,7 +620,7 @@ impl<'m> SearchInstance<'m> {
}
continue;
}
let vertex = self.mesh.layers[node.polygon_to.layer() as usize]
let vertex = self.mesh.layers[node.previous_polygon_layer as usize]
.vertices
.get(node.edge.0 as usize)
.unwrap();
Expand All @@ -645,7 +645,7 @@ impl<'m> SearchInstance<'m> {
}
continue;
}
let vertex = self.mesh.layers[node.polygon_to.layer() as usize]
let vertex = self.mesh.layers[node.previous_polygon_layer as usize]
.vertices
.get(node.edge.1 as usize)
.unwrap();
Expand Down
18 changes: 14 additions & 4 deletions src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,24 +436,34 @@ mod tests {
}

#[test]
fn take_long_way() {
fn shortcut_with_corner() {
let mesh = mesh_overlapping_layers();
for i in 7..15 {
let from = Vec2::new(i as f32 / 10.0, 2.1);
let to = Vec2::new(5.0 - i as f32 / 10.0, 0.9);
let path = dbg!(mesh.path(from, to).unwrap());
assert_eq!(path.path, vec![vec2(2.0, 2.0), vec2(3.0, 1.0), to]);
match i {
7 => assert_eq!(path.path, vec![vec2(1.0, 2.0), to]),
_ if i < 11 => assert_eq!(path.path, vec![vec2(1.0, 2.0), vec2(4.0, 1.0), to]),
_ if i < 15 => assert_eq!(path.path, vec![vec2(2.0, 2.0), vec2(3.0, 1.0), to]),
_ => unreachable!(),
}
}
}

#[test]
fn take_long_way_back() {
fn shortcut_with_corner_back() {
let mesh = mesh_overlapping_layers();
for i in 7..15 {
let from = Vec2::new(5.0 - i as f32 / 10.0, 0.9);
let to = Vec2::new(i as f32 / 10.0, 2.1);
let path = dbg!(mesh.path(from, to).unwrap());
assert_eq!(path.path, vec![vec2(3.0, 1.0), vec2(2.0, 2.0), to]);
match i {
7 => assert_eq!(path.path, vec![vec2(4.0, 1.0), to]),
_ if i < 11 => assert_eq!(path.path, vec![vec2(4.0, 1.0), vec2(1.0, 2.0), to]),
_ if i < 15 => assert_eq!(path.path, vec![vec2(3.0, 1.0), vec2(2.0, 2.0), to]),
_ => unreachable!(),
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Mesh {
queue: BinaryHeap::new(),
node_buffer: Vec::new(),
root_history: HashMap::new(),
from: Vec2::ZERO,
from: node.root,
to,
polygon_to: self.get_point_location(to),
mesh: self,
Expand Down

0 comments on commit 2464675

Please sign in to comment.