blob: a9e9e23cce6fff1c228c3fde9d9d2ca559c62a56 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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) };
}
};
|