const std = @import("std"); const PointF = @import("point_f.zig").PointF; pub const Point = struct { x: i64, y: i64, pub const One = Point{ .x = 1, .y = 1 }; pub const Zero = Point{ .x = 0, .y = 0 }; 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(@as(i64, @intCast(x)), @as(i64, @intCast(y))); } pub fn add(self: Point, other: Point) Point { return Point{ .x = self.x + other.x, .y = self.y + other.y }; } pub fn distance(self: Point, to: Point) i64 { return std.math.sqrt(self.distance2(to)); } pub fn distance2(self: Point, to: Point) i64 { const dx = to.x - self.x; const dy = to.y - self.y; return dx * dx + dy * dy; } pub fn float(self: Point) PointF { return PointF{ .x = @as(f32, @floatFromInt(self.x)), .y = @as(f32, @floatFromInt(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 }; } };