sonnum/zigsonnum/point.zig
2025-09-12 21:16:39 +03:00

37 lines
No EOL
639 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 set(self: *Pnt, x: f32, y: f32, z: f32) void {
self.x = x;
self.y = y;
self.z = z;
}
};
pub fn distanceBetweenPoints(pt1: Pnt, pt2: Pnt) f64 {
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);
}