Intersection sorting implemented
This commit is contained in:
16
src/utils.zig
Normal file
16
src/utils.zig
Normal file
@@ -0,0 +1,16 @@
|
||||
const st = @import("structures.zig");
|
||||
const Node = @import("infrastructure/node.zig").Node;
|
||||
|
||||
pub fn compareIntersections(ctx: *const Node, inter_a: st.IntersectionData, inter_b: st.IntersectionData) bool {
|
||||
const distance_a = getRelativeInterDistance(ctx, inter_a);
|
||||
const distance_b = getRelativeInterDistance(ctx, inter_b);
|
||||
|
||||
return distance_a < distance_b;
|
||||
}
|
||||
|
||||
fn getRelativeInterDistance(ctx: *const Node, intersection: st.IntersectionData) f32 {
|
||||
const x_diff = intersection.point.x - ctx.pos.x;
|
||||
const y_diff = intersection.point.y - ctx.pos.y;
|
||||
|
||||
return x_diff * x_diff + y_diff * y_diff;
|
||||
}
|
||||
Reference in New Issue
Block a user