aboutsummaryrefslogtreecommitdiffstats
path: root/src/math.zig
diff options
context:
space:
mode:
authorkj_sh6042026-06-05 15:29:19 -0400
committerkj_sh6042026-06-05 15:29:19 -0400
commit2253d41b98210abdc670054d848e8bb4d29468dd (patch)
tree81c8ba6e452f0c0de00a6a91e8702f9106bde414 /src/math.zig
parent78d5ae31b7a9ddd1f2fa6d47c96f9e3bae3b3d26 (diff)
refactor: src/math.zig
Diffstat (limited to 'src/math.zig')
-rw-r--r--src/math.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/math.zig b/src/math.zig
new file mode 100644
index 0000000..a9e9e23
--- /dev/null
+++ b/src/math.zig
@@ -0,0 +1,32 @@
+pub const Vec2f = struct {
+ x: f32 = 0,
+ y: f32 = 0,
+
+ pub fn init(x: f32, y: f32) Vec2f {
+ return .{ .x = x, .y = y };
+ }
+
+ pub fn add(self: Vec2f, other: Vec2f) Vec2f {
+ return .{ .x = self.x + other.x, .y = self.y + other.y };
+ }
+
+ pub fn sub(self: Vec2f, other: Vec2f) Vec2f {
+ return .{ .x = self.x - other.x, .y = self.y - other.y };
+ }
+
+ pub fn mul(self: Vec2f, s: f32) Vec2f {
+ return .{ .x = self.x * s, .y = self.y * s };
+ }
+
+ pub fn div(self: Vec2f, s: f32) Vec2f {
+ return .{ .x = self.x / s, .y = self.y / s };
+ }
+
+ pub fn length(self: Vec2f) f32 {
+ return @sqrt(self.x * self.x + self.y * self.y);
+ }
+
+ pub fn abs(self: Vec2f) Vec2f {
+ return .{ .x = @abs(self.x), .y = @abs(self.y) };
+ }
+}; \ No newline at end of file