Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
version: 0.17.1

- name: Run tests
run: zig build test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.zig-cache/
zig-out/
zig-pkg/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ _ = qt.insert(Point.init(1, 10, 10));
_ = qt.insert(Point.fromPosition(2, Position{ .x = 50, .y = 50 }));

// Query rectangle
var results: std.ArrayListUnmanaged(Point) = .empty;
var results: std.ArrayList(Point) = .empty;
defer results.deinit(allocator);
try qt.queryRect(.{ .x = 0, .y = 0, .width = 30, .height = 30 }, &results);

Expand Down Expand Up @@ -114,7 +114,7 @@ try sap.add(2, Position{ .x = 5, .y = 5 }, 10, 10);
try sap.add(3, Position{ .x = 100, .y = 100 }, 10, 10);

// Find all collision pairs
var pairs: std.ArrayListUnmanaged(SAP.Pair) = .empty;
var pairs: std.ArrayList(SAP.Pair) = .empty;
defer pairs.deinit(allocator);
try sap.findCollisions(&pairs);
// pairs contains (1, 2) since they overlap
Expand All @@ -123,7 +123,7 @@ try sap.findCollisions(&pairs);
sap.updatePosition(1, Position{ .x = 50, .y = 50 });

// Query by region
var in_region: std.ArrayListUnmanaged(u32) = .empty;
var in_region: std.ArrayList(u32) = .empty;
try sap.queryRect(Position{ .x = 0, .y = 0 }, 30, 30, &in_region);
try sap.queryRadius(Position{ .x = 0, .y = 0 }, 20, &in_region);
```
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.{
.name = .zig_utils,
.version = "0.7.3",
.version = "0.8.0",
.fingerprint = 0x6dc482caf73c4a75,
.minimum_zig_version = "0.16.0",
.minimum_zig_version = "0.17.1",

.dependencies = .{
.zspec = .{
.url = "https://github.com/apotema/zspec/archive/v0.9.2.tar.gz",
.hash = "zspec-0.9.1-jaKLbXgMBACFwbNjflhbMyP113leoYjboxn-1UOP-FGw",
.url = "https://github.com/apotema/zspec/archive/v0.10.0.tar.gz",
.hash = "zspec-0.10.0-jaKLbbQlBABK3_qQJn5tDMF0wbJmepYdXFQug35tOur4",
},
},

Expand Down
8 changes: 4 additions & 4 deletions src/a_star.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn AStar(comptime WeightType: type) type {
to: u32,
weight: WeightType,
};
const EdgeList = std.ArrayListUnmanaged(Edge);
const AdjacencyList = std.ArrayListUnmanaged(EdgeList);
const EdgeList = std.ArrayList(Edge);
const AdjacencyList = std.ArrayList(EdgeList);

/// Priority queue node for A* open set
const PQNode = struct {
Expand Down Expand Up @@ -224,8 +224,8 @@ pub fn AStar(comptime WeightType: type) type {
@memset(came_from, std.math.maxInt(u32)); // maxInt = no parent

// BitSet instead of HashMap for closed_set - ~32x smaller, faster
var closed_set = try std.DynamicBitSet.initEmpty(self.allocator, n);
defer closed_set.deinit();
var closed_set = try std.bit_set.Dynamic.initEmpty(self.allocator, n);
defer closed_set.deinit(self.allocator);

var open_set = std.PriorityQueue(PQNode, void, PQNode.compare).initContext({});
defer open_set.deinit(self.allocator);
Expand Down
2 changes: 1 addition & 1 deletion src/floyd_warshall.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn FloydWarshall(comptime DistanceType: type) type {

/// Build the path from u to v and store in the provided unmanaged ArrayList
/// Returns error.PathNotFound if no path exists between the nodes.
pub fn setPathWithMappingUnmanaged(self: *Self, allocator: std.mem.Allocator, path_list: *std.ArrayListUnmanaged(u32), u_node: u32, v_node: u32) !void {
pub fn setPathWithMappingUnmanaged(self: *Self, allocator: std.mem.Allocator, path_list: *std.ArrayList(u32), u_node: u32, v_node: u32) !void {
const initial_len = path_list.items.len;
var current = u_node;
while (current != v_node) {
Expand Down
2 changes: 1 addition & 1 deletion src/floyd_warshall_optimized.zig
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub fn FloydWarshallOptimized(comptime config: Config) type {

/// Build the path from u to v and store in the provided unmanaged ArrayList
/// Returns error.NoPathFound if no path exists between the nodes
pub fn setPathWithMappingUnmanaged(self: *const Self, allocator: std.mem.Allocator, path_list: *std.ArrayListUnmanaged(u32), u_node: u32, v_node: u32) PathError!void {
pub fn setPathWithMappingUnmanaged(self: *const Self, allocator: std.mem.Allocator, path_list: *std.ArrayList(u32), u_node: u32, v_node: u32) PathError!void {
var current = u_node;
var steps: usize = 0;
const max_steps: usize = self.size; // a shortest path visits each node at most once
Expand Down
10 changes: 5 additions & 5 deletions src/quad_tree.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn QuadTree(comptime T: type, comptime config: QuadTreeConfig) type {
return struct {
const Self = @This();

nodes: std.ArrayListUnmanaged(Node),
nodes: std.ArrayList(Node),

lowest_x: f32 = 0.0,
lowest_y: f32 = 0.0,
Expand Down Expand Up @@ -254,11 +254,11 @@ pub fn QuadTree(comptime T: type, comptime config: QuadTreeConfig) type {
}

/// Query all points within a rectangle
pub fn queryRect(self: *Self, range: Rectangle, buffer: *std.ArrayListUnmanaged(Point)) !void {
pub fn queryRect(self: *Self, range: Rectangle, buffer: *std.ArrayList(Point)) !void {
try self.queryRectAt(range, buffer, 0);
}

fn queryRectAt(self: *Self, range: Rectangle, buffer: *std.ArrayListUnmanaged(Point), node_idx: u32) !void {
fn queryRectAt(self: *Self, range: Rectangle, buffer: *std.ArrayList(Point), node_idx: u32) !void {
if (!self.nodes.items[node_idx].boundary.intersects(range)) {
return;
}
Expand All @@ -279,7 +279,7 @@ pub fn QuadTree(comptime T: type, comptime config: QuadTreeConfig) type {
}

/// Query all points within a radius of a center position
pub fn queryRadius(self: *Self, center: Position, radius: f32, buffer: *std.ArrayListUnmanaged(Point)) !void {
pub fn queryRadius(self: *Self, center: Position, radius: f32, buffer: *std.ArrayList(Point)) !void {
const range = Rectangle{
.x = center.x - radius,
.y = center.y - radius,
Expand All @@ -289,7 +289,7 @@ pub fn QuadTree(comptime T: type, comptime config: QuadTreeConfig) type {
try self.queryRadiusAt(range, center, radius * radius, buffer, 0);
}

fn queryRadiusAt(self: *Self, range: Rectangle, center: Position, radius_sq: f32, buffer: *std.ArrayListUnmanaged(Point), node_idx: u32) !void {
fn queryRadiusAt(self: *Self, range: Rectangle, center: Position, radius_sq: f32, buffer: *std.ArrayList(Point), node_idx: u32) !void {
if (!self.nodes.items[node_idx].boundary.intersects(range)) {
return;
}
Expand Down
12 changes: 6 additions & 6 deletions src/sweep_and_prune.zig
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ pub fn SweepAndPrune(comptime T: type) type {
b: T,
};

entities: std.ArrayListUnmanaged(Entity),
sorted_indices: std.ArrayListUnmanaged(usize),
entities: std.ArrayList(Entity),
sorted_indices: std.ArrayList(usize),
allocator: std.mem.Allocator,

pub fn init(allocator: std.mem.Allocator) Self {
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn SweepAndPrune(comptime T: type) type {
}

/// Find all collision pairs using sweep and prune
pub fn findCollisions(self: *Self, pairs: *std.ArrayListUnmanaged(Pair)) !void {
pub fn findCollisions(self: *Self, pairs: *std.ArrayList(Pair)) !void {
const n = self.entities.items.len;
if (n < 2) return;

Expand Down Expand Up @@ -201,7 +201,7 @@ pub fn SweepAndPrune(comptime T: type) type {
}

/// Find all entities overlapping with a given AABB
pub fn queryRect(self: *Self, center: Position, half_width: f32, half_height: f32, results: *std.ArrayListUnmanaged(T)) !void {
pub fn queryRect(self: *Self, center: Position, half_width: f32, half_height: f32, results: *std.ArrayList(T)) !void {
const query = Entity{
.id = undefined,
.pos = center,
Expand All @@ -217,7 +217,7 @@ pub fn SweepAndPrune(comptime T: type) type {
}

/// Find all entities within a radius of a position
pub fn queryRadius(self: *Self, center: Position, radius: f32, results: *std.ArrayListUnmanaged(T)) !void {
pub fn queryRadius(self: *Self, center: Position, radius: f32, results: *std.ArrayList(T)) !void {
const radius_sq = radius * radius;

for (self.entities.items) |entity| {
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn SweepAndPrune(comptime T: type) type {
/// Simple sweep and prune for AABBs (non-generic version)
pub fn sweepAndPrune(
boxes: []const AABB,
pairs: *std.ArrayListUnmanaged(CollisionPair),
pairs: *std.ArrayList(CollisionPair),
allocator: std.mem.Allocator,
) !void {
const n = boxes.len;
Expand Down
20 changes: 4 additions & 16 deletions src/vector.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,8 @@ pub const Position = struct {
return @abs(self.x - other.x) <= epsilon and @abs(self.y - other.y) <= epsilon;
}

pub fn format(
self: Position,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = fmt;
_ = options;
/// Formatter for the `{f}` specifier: `writer.print("{f}", .{pos})`.
pub fn format(self: Position, writer: *std.Io.Writer) std.Io.Writer.Error!void {
try writer.print("Position({d:.2}, {d:.2})", .{ self.x, self.y });
}
};
Expand Down Expand Up @@ -203,14 +197,8 @@ pub const PositionI = struct {
};
}

pub fn format(
self: PositionI,
comptime fmt: []const u8,
options: std.fmt.FormatOptions,
writer: anytype,
) !void {
_ = fmt;
_ = options;
/// Formatter for the `{f}` specifier: `writer.print("{f}", .{pos})`.
pub fn format(self: PositionI, writer: *std.Io.Writer) std.Io.Writer.Error!void {
try writer.print("PositionI({d}, {d})", .{ self.x, self.y });
}
};
4 changes: 2 additions & 2 deletions src/z_index_buckets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ pub fn ZIndexBuckets(comptime T: type, comptime ZIndexType: type) type {

return struct {
const Self = @This();
const Bucket = std.ArrayListUnmanaged(T);
const Bucket = std.ArrayList(T);

buckets: [bucket_count]Bucket,
allocator: std.mem.Allocator,
total_count: usize,

pub fn init(allocator: std.mem.Allocator) Self {
return Self{
.buckets = [_]Bucket{.empty} ** bucket_count,
.buckets = @splat(.empty),
.allocator = allocator,
.total_count = 0,
};
Expand Down
Loading
Loading