const std = @import("std"); const vm = @import("../root.zig"); pub const Vector3Int_x8 = struct { x: vm.i32x8, y: vm.i32x8, z: vm.i32x8, pub const zero = initScalarSingle(0); pub const one = initScalarSingle(1); pub const unit_x = initSingle(1, 0, 0); pub const unit_y = initSingle(0, 1, 0); pub const unit_z = initSingle(0, 0, 1); pub const unit_nx = initSingle(-1, 0, 0); pub const unit_ny = initSingle(0, -1, 0); pub const unit_nz = initSingle(0, 0, -1); // --- INIT ---------------------------------------------------------------- pub inline fn init(x: vm.i32x8, y: vm.i32x8, z: vm.i32x8) Vector3Int_x8 { return .{ .x = x, .y = y, .z = z }; } pub inline fn initSingle(x: i32, y: i32, z: i32) Vector3Int_x8 { return .{ .x = vm.epi32(x), .y = vm.epi32(y), .z = vm.epi32(z) }; } pub inline fn initScalar(scalar: vm.i32x8) Vector3Int_x8 { return .{ .x = scalar, .y = scalar, .z = scalar }; } pub inline fn initScalarSingle(scalar: i32) Vector3Int_x8 { return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar) }; } pub inline fn splat(vector: vm.Vector3Int) Vector3Int_x8 { return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y), .z = vm.epi32(vector.z) }; } // --- CONVERSION ---------------------------------------------------------- pub inline fn asFloat(self: Vector3Int_x8) vm.Vector3x8 { return .{ .x = @floatFromInt(self.x), .y = @floatFromInt(self.y), .z = @floatFromInt(self.z) }; } pub inline fn dropZ(self: Vector3Int_x8) vm.Vector2Int_x8 { return .{ .x = self.x, .y = self.y }; } pub inline fn withW(self: Vector3Int_x8, w: vm.i32x8) vm.Vector4Int_x8 { return .{ .x = self.x, .y = self.y, .z = self.z, .w = w }; } pub inline fn unpack(self: Vector3Int_x8) [3]vm.i32x8 { return .{ self.x, self.y, self.z }; } // --- COMPONENT-WISE ------------------------------------------------------ pub inline fn add(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z }; } pub inline fn sub(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = self.x - other.x, .y = self.y - other.y, .z = self.z - other.z }; } pub inline fn mul(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = self.x * other.x, .y = self.y * other.y, .z = self.z * other.z }; } pub inline fn mulScalar(self: Vector3Int_x8, scalar: vm.i32x8) Vector3Int_x8 { return .{ .x = self.x * scalar, .y = self.y * scalar, .z = self.z * scalar }; } pub inline fn mulScalarSingle(self: Vector3Int_x8, scalar: i32) Vector3Int_x8 { return .{ .x = self.x * vm.epi32(scalar), .y = self.y * vm.epi32(scalar), .z = self.z * vm.epi32(scalar) }; } pub inline fn div(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = @divFloor(self.x, other.x), .y = @divFloor(self.y, other.y), .z = @divFloor(self.z, other.z) }; } pub inline fn divScalar(self: Vector3Int_x8, scalar: vm.i32x8) Vector3Int_x8 { return .{ .x = @divFloor(self.x, scalar), .y = @divFloor(self.y, scalar), .z = @divFloor(self.z, scalar) }; } pub inline fn divScalarSingle(self: Vector3Int_x8, scalar: i32) Vector3Int_x8 { return .{ .x = @divFloor(self.x, vm.epi32(scalar)), .y = @divFloor(self.y, vm.epi32(scalar)), .z = @divFloor(self.z, vm.epi32(scalar)) }; } pub inline fn mod(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = @mod(self.x, other.x), .y = @mod(self.y, other.y), .z = @mod(self.z, other.z) }; } pub inline fn modScalar(self: Vector3Int_x8, scalar: vm.i32x8) Vector3Int_x8 { return .{ .x = @mod(self.x, scalar), .y = @mod(self.y, scalar), .z = @mod(self.z, scalar) }; } pub inline fn modScalarSingle(self: Vector3Int_x8, scalar: i32) Vector3Int_x8 { return .{ .x = @mod(self.x, vm.epi32(scalar)), .y = @mod(self.y, vm.epi32(scalar)), .z = @mod(self.z, vm.epi32(scalar)) }; } pub inline fn negate(self: Vector3Int_x8) Vector3Int_x8 { return .{ .x = -self.x, .y = -self.y, .z = -self.z }; } pub inline fn abs(self: Vector3Int_x8) Vector3Int_x8 { return .{ .x = @intCast(@abs(self.x)), .y = @intCast(@abs(self.y)), .z = @intCast(@abs(self.z)) }; } pub inline fn min(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = @min(self.x, other.x), .y = @min(self.y, other.y), .z = @min(self.z, other.z) }; } pub inline fn max(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y), .z = @max(self.z, other.z) }; } // --- OTHER --------------------------------------------------------------- pub inline fn lenSquared(self: Vector3Int_x8) vm.i32x8 { return self.x * self.x + self.y * self.y + self.z * self.z; } pub inline fn dot(self: Vector3Int_x8, other: Vector3Int_x8) vm.i32x8 { return self.x * other.x + self.y * other.y + self.z * other.z; } pub inline fn cross(self: Vector3Int_x8, other: Vector3Int_x8) vm.i32x8 { return .{ .x = self.y * other.z - self.z * other.y, .y = self.z * other.x - self.x * other.z, .z = self.x * other.y - self.y * other.x, }; } test "refAllDecls" { std.testing.refAllDecls(@This()); } };