Skip to content

Commit

Permalink
minor style changes, cleanup and added test for heap
Browse files Browse the repository at this point in the history
  • Loading branch information
harisankar95 committed Jan 19, 2024
1 parent ad53707 commit 1fa33a9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/03_view_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
elif isinstance(node, tuple):
path.append([node[0], node[1], node[2]])
print(f"path: {path}")


# visualize path in open3d
if USE_OPEN3D:
Expand All @@ -51,16 +51,16 @@
xyz_pt = np.stack(obstacle_indices, axis=-1).astype(float)
colors = np.zeros((xyz_pt.shape[0], 3))
colors[:, 2] = obstacle_indices[2] / np.max(obstacle_indices[2])

# Prepare start and end colors
start_color = np.array([[1.0, 0, 0]]) # Red
end_color = np.array([[0, 1.0, 0]]) # Green
end_color = np.array([[0, 1.0, 0]]) # Green
path_colors = np.full((len(path) - 2, 3), [0.7, 0.7, 0.7]) # Grey for the path

# Combine points and colors
xyz_pt = np.concatenate((xyz_pt, [start_pt], [end_pt], path[1:-1]))
colors = np.concatenate((colors, start_color, end_color, path_colors))

# Create and visualize the point cloud
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(xyz_pt)
Expand Down
6 changes: 3 additions & 3 deletions test/test_connect_grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

PATH = [
(2, 0, 0, 0),
(2, 0, 1, 0),
(2, 0, 2, 0),
(2, 1, 2, 0),
(2, 1, 0, 0),
(2, 2, 0, 0),
(2, 2, 1, 0),
(2, 2, 2, 0),
# move to grid 1
(2, 2, 2, 1),
Expand Down
26 changes: 26 additions & 0 deletions test/test_heap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pathfinding3d.core.grid import Grid
from pathfinding3d.core.heap import SimpleHeap


def test_heap():
grid = Grid(width=10, height=10, depth=10)
start = grid.node(0, 0, 0)
open_list = SimpleHeap(start, grid)

# Test pop
assert open_list.pop_node() == start
assert len(open_list) == 0

# Test push
open_list.push_node(grid.node(1, 1, 1))
open_list.push_node(grid.node(1, 1, 2))
open_list.push_node(grid.node(1, 1, 3))

# Test removal and pop
assert len(open_list) == 3
open_list.remove_node(grid.node(1, 1, 2), 0)
assert len(open_list) == 3

assert open_list.pop_node() == grid.node(1, 1, 1)
assert open_list.pop_node() == grid.node(1, 1, 3)
assert len(open_list) == 0
4 changes: 1 addition & 3 deletions test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pathfinding3d.finder.ida_star import IDAStarFinder
from pathfinding3d.finder.msp import MinimumSpanningTree

# test scenarios from Pathfinding.JS
finders = [
AStarFinder,
BestFirst,
Expand All @@ -31,7 +30,6 @@
DijkstraFinder,
MinimumSpanningTree,
]
TIME_LIMIT = 10 # give it a 10 second limit

SIMPLE_MATRIX = np.zeros((5, 5, 5))
SIMPLE_MATRIX[0, 0, 0] = 1
Expand Down Expand Up @@ -60,7 +58,7 @@

def test_path():
"""
test scenarios defined in json file
test if we can find a path
"""
grid = Grid(matrix=SIMPLE_MATRIX)
start = grid.node(0, 0, 0)
Expand Down

0 comments on commit 1fa33a9

Please sign in to comment.