git.s-ol.nu ~forks/glm-zig / master
add VecN format(), shrink() s-ol 23 days ago
1 changed file(s) with 25 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2424 return .{ .values = values };
2525 }
2626
27 pub fn format(
28 self: Self,
29 comptime fmt: []const u8,
30 options: std.fmt.FormatOptions,
31 writer: anytype,
32 ) !void {
33 try writer.print("Vec{}[{}", .{N, self.values[0]});
34 comptime var i = 1;
35 inline while (i < N) : (i += 1) {
36 try writer.print(", {}", .{self.values[i]});
37 }
38 try writer.writeAll("]");
39 }
40
2741 /// Creates a vector filled with zeroes.
2842 pub fn zeroes() Self {
2943 return comptime Self.filled(0);
182196
183197 return Self{ .values = values };
184198 }
199
200 pub fn shrink(self: Self, comptime L: usize) Vector(L) {
201 if (L > N) unreachable;
202
203 var result: Vector(L) = undefined;
204 comptime var i = 0;
205 inline while (i < L) : (i += 1) {
206 result.values[i] = self.values[i];
207 }
208 return result;
209 }
185210 };
186211 }
187212