Implemented function which gets all roads that get intersected by new road and returns them and the exact pos of intersection
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
|
||||
const st = @import("../common/structures.zig");
|
||||
const e = @import("../errors.zig");
|
||||
const Road = @import("road.zig").Road;
|
||||
const Node = @import("node.zig").Node;
|
||||
@@ -91,6 +93,25 @@ pub const RoadManager = struct {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
pub fn getIntersectingRoads(self: *const RoadManager, allocator: std.mem.Allocator, start: *const Node, end: *const Node) ![]st.IntersectionData {
|
||||
var intersections: std.ArrayList(st.IntersectionData) = .empty;
|
||||
const collision_point: rl.Vector2 = undefined;
|
||||
|
||||
for (self.roads.items) |road| {
|
||||
if (!rl.checkCollisionLines(start.pos, end.pos, road.nodes[0].pos, road.nodes[1].pos, &collision_point))
|
||||
continue;
|
||||
|
||||
const intersection = st.IntersectionData {
|
||||
.road = road,
|
||||
.pos = collision_point,
|
||||
};
|
||||
|
||||
try intersections.append(allocator, intersection);
|
||||
}
|
||||
|
||||
return intersections.toOwnedSlice(allocator);
|
||||
}
|
||||
};
|
||||
|
||||
const Vector2 = @import("raylib").Vector2;
|
||||
|
||||
Reference in New Issue
Block a user