Splitting road implementation preparation
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user