Splitting road implementation preparation

This commit is contained in:
2026-05-01 07:49:07 +02:00
parent 5040bbbe47
commit 680e07c976
6 changed files with 105 additions and 23 deletions

View File

@@ -50,11 +50,22 @@ pub const NodeManager = struct {
}
}
/// Tries to find a node which snapping radius covers the pos
///
/// If it does it returns a reference to it, otherwise null
pub fn getNodeIfExists(self: *const NodeManager, pos: Vector2) ?*Node {
for (self.nodes.items) |node| {
if (node.withinSnapRadius(pos)) return node;
}
return null;
}
/// Checks if there is a node pointer within the snap radius of pos coordinate;
/// otherwise creates a new node and returns its pointer
pub fn getSelectedNode(self: *NodeManager, allocator: std.mem.Allocator, pos: Vector2) !*Node {
for (self.nodes.items) |node| {
if (node.withinSnapRadius(pos)) return node;
if (self.getNodeIfExists(pos)) |node| {
return node;
}
// No node is within that position, so we must create a new one