Splitting function completed

This commit is contained in:
2026-05-01 17:44:30 +02:00
parent afd7aa50c4
commit dd64ec648a
2 changed files with 81 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
const rl = @import("raylib");
const c = @import("../common/constants.zig");
const e = @import("../errors.zig");
const st = @import("../common/structures.zig");
const ut = @import("../common/utils.zig");
const Node = @import("node.zig").Node;
@@ -79,6 +80,18 @@ pub const Road = struct {
pub fn collides(self: *const Road, pos: rl.Vector2) bool {
return rl.checkCollisionPointLine(pos, self.nodes[0].pos, self.nodes[1].pos, c.ROAD_SIZE);
}
/// Updates node reference old_node => new node; returns error if old_node does not exist
pub fn updateNodeReference(self: *Road, old_node: *Node, new_node: *Node) !void {
for (0..self.nodes.len) |i| {
if (self.nodes[i] != old_node) continue;
self.nodes[i] = new_node;
return;
}
return e.Entity.NotFound;
}
};
const std = @import("std");
@@ -109,4 +122,7 @@ test "valid road nodes" {
try expect(road.nodes[0].id == 34);
try expect(road.nodes[1].id == 227);
}
}
// TODO tests
// test every case error for every function that can return an error