Vector int-float conversion methods
This commit is contained in:
@@ -34,6 +34,10 @@ pub const Vector2 = extern struct {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asInt(self: Vector2) vm.Vector2Int {
|
||||
return .{ .x = @intFromFloat(self.x), .y = @intFromFloat(self.y) };
|
||||
}
|
||||
|
||||
pub inline fn withZ(self: Vector2, z: f32) vm.Vector3 {
|
||||
return .{ .x = self.x, .y = self.y, .z = z };
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ pub const Vector2Int = extern struct {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asFloat(self: Vector2Int) vm.Vector2 {
|
||||
return .{ .x = @floatFromInt(self.x), .y = @floatFromInt(self.y) };
|
||||
}
|
||||
|
||||
pub inline fn withZ(self: Vector2Int, z: i32) vm.Vector3Int {
|
||||
return .{ .x = self.x, .y = self.y, .z = z };
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ pub const Vector2Int_x8 = struct {
|
||||
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asFloat(self: Vector2Int_x8) vm.Vector2x8 {
|
||||
return .{ .x = @floatFromInt(self.x), .y = @floatFromInt(self.y) };
|
||||
}
|
||||
|
||||
pub inline fn withZ(self: Vector2Int_x8, z: vm.i32x8) vm.Vector3Int_x8 {
|
||||
return .{ .x = self.x, .y = self.y, .z = z };
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ pub const Vector2x8 = struct {
|
||||
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asInt(self: Vector2x8) vm.Vector2Int_x8 {
|
||||
return .{ .x = @intFromFloat(self.x), .y = @intFromFloat(self.y) };
|
||||
}
|
||||
|
||||
pub inline fn withZ(self: Vector2x8, z: vm.f32x8) vm.Vector3x8 {
|
||||
return .{ .x = self.x, .y = self.y, .z = z };
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ pub const Vector3 = extern struct {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asInt(self: Vector3) vm.Vector3Int {
|
||||
return .{ .x = @intFromFloat(self.x), .y = @intFromFloat(self.y), .z = @intFromFloat(self.z) };
|
||||
}
|
||||
|
||||
pub inline fn dropZ(self: Vector3) vm.Vector2 {
|
||||
return .{ .x = self.x, .y = self.y };
|
||||
}
|
||||
@@ -145,7 +149,7 @@ pub const Vector3 = extern struct {
|
||||
pub inline fn rotate_x8(self: Vector3, quaternion: vm.Quaternion_x8) vm.Vector3x8 {
|
||||
const w = quaternion.getScalar();
|
||||
const xyz = quaternion.getVector();
|
||||
const self_x8: vm.Vector3x8 = .splat(self);
|
||||
const self_x8 = vm.Vector3x8.splat(self);
|
||||
|
||||
return .add(
|
||||
self_x8,
|
||||
|
||||
@@ -37,6 +37,10 @@ pub const Vector3Int = extern struct {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asFloat(self: Vector3Int) vm.Vector3 {
|
||||
return .{ .x = @floatFromInt(self.x), .y = @floatFromInt(self.y), .z = @floatFromInt(self.z) };
|
||||
}
|
||||
|
||||
pub inline fn dropZ(self: Vector3Int) vm.Vector2Int {
|
||||
return .{ .x = self.x, .y = self.y };
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ pub const Vector3Int_x8 = struct {
|
||||
|
||||
// --- 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 };
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ pub const Vector3x8 = struct {
|
||||
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asInt(self: Vector3x8) vm.Vector3Int_x8 {
|
||||
return .{ .x = @intFromFloat(self.x), .y = @intFromFloat(self.y), .z = @intFromFloat(self.z) };
|
||||
}
|
||||
|
||||
pub inline fn dropZ(self: Vector3x8) vm.Vector2x8 {
|
||||
return .{ .x = self.x, .y = self.y };
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ pub const Vector4 = extern struct {
|
||||
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asInt(self: Vector4) vm.Vector4Int {
|
||||
return .{ .x = @intFromFloat(self.x), .y = @intFromFloat(self.y), .z = @intFromFloat(self.z), .w = @intFromFloat(self.w) };
|
||||
}
|
||||
|
||||
pub inline fn asArray(self: Vector4) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ pub const Vector4Int = extern struct {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asFloat(self: Vector4Int) vm.Vector4 {
|
||||
return .{ .x = @floatFromInt(self.x), .y = @floatFromInt(self.y), .z = @floatFromInt(self.z), .w = @floatFromInt(self.w) };
|
||||
}
|
||||
|
||||
pub inline fn dropW(self: Vector4Int) vm.Vector3Int {
|
||||
return .{ .x = self.x, .y = self.y, .z = self.z };
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ pub const Vector4Int_x8 = struct {
|
||||
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asFloat(self: Vector4Int_x8) vm.Vector4x8 {
|
||||
return .{ .x = @floatFromInt(self.x), .y = @floatFromInt(self.y), .z = @floatFromInt(self.z), .w = @floatFromInt(self.w) };
|
||||
}
|
||||
|
||||
pub inline fn dropW(self: Vector4Int_x8) vm.Vector3Int_x8 {
|
||||
return .{ .x = self.x, .y = self.y, .z = self.z };
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ pub const Vector4x8 = struct {
|
||||
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asInt(self: Vector4x8) vm.Vector4Int_x8 {
|
||||
return .{ .x = @intFromFloat(self.x), .y = @intFromFloat(self.y), .z = @intFromFloat(self.z), .w = @intFromFloat(self.w) };
|
||||
}
|
||||
|
||||
pub inline fn dropW(self: Vector4x8) vm.Vector3x8 {
|
||||
return .{ .x = self.x, .y = self.y, .z = self.z };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user