37 lines
1006 B
Zig
37 lines
1006 B
Zig
const std = @import("std");
|
|
|
|
const Point = @import("point.zig").Point;
|
|
|
|
pub const PointF = struct {
|
|
x: f32,
|
|
y: f32,
|
|
|
|
pub fn init(x: f32, y: f32) PointF {
|
|
return PointF{ .x = x, .y = y };
|
|
}
|
|
|
|
pub fn add(self: PointF, other: PointF) PointF {
|
|
return PointF{ .x = self.x + other.x, .y = self.y + other.y };
|
|
}
|
|
|
|
pub fn ceil(self: PointF) PointF {
|
|
return PointF{ .x = std.math.ceil(self.x), .y = std.math.ceil(self.y) };
|
|
}
|
|
|
|
pub fn floor(self: PointF) PointF {
|
|
return PointF{ .x = std.math.floor(self.x), .y = std.math.floor(self.y) };
|
|
}
|
|
|
|
pub fn integer(self: PointF) Point {
|
|
return Point{ .x = @floatToInt(i64, self.x), .y = @floatToInt(i64, self.y) };
|
|
}
|
|
|
|
pub fn multiply(self: PointF, factor: f32) PointF {
|
|
return PointF{ .x = self.x * factor, .y = self.y * factor };
|
|
}
|
|
|
|
pub fn subtract(self: PointF, other: PointF) PointF {
|
|
return PointF{ .x = self.x - other.x, .y = self.y - other.y };
|
|
}
|
|
};
|