Intersection sorting implemented

This commit is contained in:
2026-04-08 21:41:08 +02:00
parent a9dd430cc7
commit 288cfd6b50
5 changed files with 65 additions and 20 deletions

View File

@@ -82,7 +82,7 @@ pub const NodeManager = struct {
/// generates finds the last element in the list and returns id + 1 or 0 if there are no elements in the list
fn getNewID(self: *const NodeManager) usize {
return if (self.getLastRef()) |ref| ref.*.id + 1 else 0;
return if (self.nodes.getLastOrNull()) |last| last.id + 1 else 0;
}
/// Iterates through all nodes and runs the deinit procedure on each of them
@@ -98,6 +98,11 @@ pub const NodeManager = struct {
// This also means we don't have to deinit it, since it has no elements
if (node_to_remove.roads.items.len > 0) return;
// TODO
// When a node gets removed the empty space left by now non-existant node will get swapped with another node
// In practice this however means that pointers to the node that gets swapped will be invalid
// causing fatal errors
for (self.nodes.items, 0..) |*node, i| {
if (node.id != node_to_remove.id) continue;