Skip to content

Commit 86b56dc

Browse files
committed
Fix arbitrary radius calculation bug
1 parent 46c7fad commit 86b56dc

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/setup_topology.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function EnergySystemDesign(
3232
icon::String = "",
3333
parent::AbstractGUIObj = NothingDesign(),
3434
level::Int64 = 0,
35+
radius::Float32 = 0.1f0,
3536
)
3637
# Create the path to the file where existing design is stored (if any)
3738
file::String = design_file(system, design_path)
@@ -43,6 +44,28 @@ function EnergySystemDesign(
4344
Dict()
4445
end
4546

47+
if isa(system, SystemGeo)
48+
# Collect all (lon, lat) coordinates from elements that have them
49+
coords = [
50+
Point2f(element.lon, element.lat)
51+
for element in get_children(system)
52+
]
53+
54+
# Compute all pairwise distances
55+
min_dist = Inf
56+
for i in 1:length(coords)-1
57+
for j in i+1:length(coords)
58+
dist = l2_norm(coords[i] - coords[j])
59+
if dist < min_dist
60+
min_dist = dist
61+
end
62+
end
63+
end
64+
65+
# Set radius to a third of the minimal distance such that expanded nodes do not overlap
66+
radius = min_dist / 3
67+
end
68+
4669
# Complete the `id_to_color_map` if some products are lacking (this is done by choosing
4770
# colors for the lacking `Resource`s that are most distinct to the existing set of colors)
4871
if !issubset(get_products(system), keys(id_to_color_map))
@@ -98,7 +121,7 @@ function EnergySystemDesign(
98121
xy = xy_parent
99122
else # place nodes in a circle around the parents availability node
100123
xy = place_nodes_in_circle(
101-
nodes_count, current_node, 1.0f0, xy_parent,
124+
nodes_count, current_node, radius, xy_parent,
102125
)
103126
current_node += 1
104127
end
@@ -119,6 +142,7 @@ function EnergySystemDesign(
119142
icon = find_icon(this_sys, id_to_icon_map),
120143
parent = design,
121144
level = level + 1,
145+
radius = radius,
122146
),
123147
)
124148
end

0 commit comments

Comments
 (0)