31 lines
828 B
Zig
31 lines
828 B
Zig
|
const PointF = @import("point_f.zig").PointF;
|
||
|
|
||
|
pub const Point = struct {
|
||
|
x: i64,
|
||
|
y: i64,
|
||
|
|
||
|
pub fn init(x: i64, y: i64) Point {
|
||
|
return Point{ .x = x, .y = y };
|
||
|
}
|
||
|
|
||
|
pub fn initUsize(x: usize, y: usize) Point {
|
||
|
return Point.init(@intCast(i64, x), @intCast(i64, y));
|
||
|
}
|
||
|
|
||
|
pub fn add(self: Point, other: Point) Point {
|
||
|
return Point{ .x = self.x + other.x, .y = self.y + other.y };
|
||
|
}
|
||
|
|
||
|
pub fn float(self: Point) PointF {
|
||
|
return PointF{ .x = @intToFloat(f32, self.x), .y = @intToFloat(f32, self.y) };
|
||
|
}
|
||
|
|
||
|
pub fn multiply(self: Point, factor: i64) Point {
|
||
|
return Point{ .x = self.x * factor, .y = self.y * factor };
|
||
|
}
|
||
|
|
||
|
pub fn subtract(self: Point, other: Point) Point {
|
||
|
return Point{ .x = self.x - other.x, .y = self.y - other.y };
|
||
|
}
|
||
|
};
|