38 lines
915 B
Zig
38 lines
915 B
Zig
const std = @import("std");
|
|
const writer = std.io.getStdOut().writer();
|
|
const expect = std.testing.expect;
|
|
|
|
fn Vec3(comptime T: type) type {
|
|
return struct {
|
|
const Self = @This();
|
|
x: T,
|
|
y: T,
|
|
z: T,
|
|
fn init(this: *Self, x: T, y: T, z: T) void {
|
|
this.x = x;
|
|
this.y = y;
|
|
this.z = z;
|
|
}
|
|
|
|
fn print(this: Self) !void {
|
|
try writer.print("X: {d}\nY: {d}\nZ: {d}\n", .{this.x, this.y, this.z});
|
|
}
|
|
|
|
fn add(this: *Self, other: Self) void {
|
|
this.x = this.x + other.x;
|
|
this.y = this.y + other.y;
|
|
this.z = this.z + other.z;
|
|
}
|
|
};
|
|
}
|
|
|
|
pub fn main() !void {
|
|
var vec1: Vec3(u64) = undefined;
|
|
var vec2: Vec3(u64) = undefined;
|
|
vec1.init(2, 4, 3);
|
|
vec2.init(1, 1, 1);
|
|
try vec1.print();
|
|
vec1.add(vec2);
|
|
try vec1.print();
|
|
}
|