Intersection sorting implemented
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -57,12 +57,11 @@ pub const RoadManager = 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 RoadManager) usize {
|
||||
return if (self.getLastRef()) |ref| ref.*.id + 1 else 0;
|
||||
return if (self.roads.getLastOrNull()) |last| last.id + 1 else 0;
|
||||
}
|
||||
|
||||
/// Removes the road which reference is passed in; returns error if the road is invalid
|
||||
pub fn remove(self: *RoadManager, road_to_remove: *Road) !void {
|
||||
// todo fix leak
|
||||
try road_to_remove.unreferenceNodes();
|
||||
|
||||
for (self.roads.items, 0..) |*road, i| {
|
||||
|
||||
Reference in New Issue
Block a user