sonnum/zigsonnum/point.zig

30 lines
No EOL
534 B
Zig

const std = @import("std");
const print = std.debug.print;
const math = std.math;
pub const Pnt = struct {
x: f32 = 0,
y: f32 = 0,
z: f32 = 0,
fn printPnt(self: *const Pnt) void {
print("{d} {d} {d}\n", .{self.x, self.y, self.z});
}
};
pub fn distanceBetweenPoints(pt1: Pnt, pt2: Pnt) f32 {
if ((pt1.x == pt2.x) and (pt1.y == pt2.y) and (pt1.z == pt2.z)) {
return 0;
}
const dx: f32 = pt1.x - pt2.x;
const dy: f32 = pt1.y - pt2.y;
const dz: f32 = pt1.z - pt2.z;
return math.sqrt(dx*dx + dy*dy + dz*dz);
}