aboutsummaryrefslogtreecommitdiffstats
path: root/src/math.zig
diff options
context:
space:
mode:
authorkj_sh6042026-06-05 16:08:47 -0400
committerkj_sh6042026-06-05 16:08:47 -0400
commitffb0182d90d5607ccccff5210a2e711d6af35458 (patch)
tree3bb0cee0f2917a66d735b1e08797da0dd9666f45 /src/math.zig
parent8c3af04bf55c334500252faca56fae61429fb770 (diff)
refactor: zig re-implementation
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