Skip to content

Commit

Permalink
added reviewed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sahil-Chhoker committed Jan 13, 2025
1 parent 70e37f1 commit b0849cf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions mesa/visualization/mpl_space_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import itertools
import warnings
from collections.abc import Callable
from itertools import pairwise
from typing import Any

import networkx as nx
Expand Down Expand Up @@ -346,7 +347,7 @@ def draw_hex_grid(

def setup_hexmesh(width, height):
"""Helper function for creating the hexmesh with unique edges."""
edges = set()
edges = []
size = 1.0
x_spacing = np.sqrt(3) * size
y_spacing = 1.5 * size
Expand Down Expand Up @@ -374,18 +375,15 @@ def get_hex_vertices(
vertices = get_hex_vertices(x, y)

# Edge logic, connecting each vertex to the next
for i in range(len(vertices)):
v1 = vertices[i]
v2 = vertices[(i + 1) % len(vertices)]

# Sort vertices to ensure consistent edge representation
for v1, v2 in pairwise(vertices + [vertices[0]]):
# Sort vertices to ensure consistent edge representation and avoid duplicates.
edge = tuple(sorted([tuple(np.round(v1, 6)), tuple(np.round(v2, 6))]))
edges.add(edge)
if edge not in edges:
edges.append(edge)

# Convert to LineCollection format
edges_list = [np.array(edge) for edge in edges]
# Return LineCollection for hexmesh
return LineCollection(
edges_list, linestyle=":", color="black", linewidth=1, alpha=1
edges, linestyle=":", color="black", linewidth=1, alpha=1
)

if draw_grid:
Expand Down

0 comments on commit b0849cf

Please sign in to comment.