1use derive_cmp_ops::CmpOps;
2use glium::uniforms::AsUniformValue;
3use super::{vec4::Vec4, divec3::*, bvec4::*};
4#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, CmpOps)]
5pub struct DIVec4 {
7 pub x: i64,
8 pub y: i64,
9 pub z: i64,
10 pub w: i64
11}
12impl DIVec4 {
13 pub const ZERO: Self = divec4(0, 0, 0, 0);
15 pub const ONE: Self = divec4(1, 1, 1, 1);
17 pub const X: Self = divec4(1, 0, 0, 0);
19 pub const Y: Self = divec4(0, 1, 0, 0);
21 pub const Z: Self = divec4(0, 0, 1, 0);
23 pub const W: Self = divec4(0, 0, 0, 1);
25
26 pub const fn new(x: i64, y: i64, z: i64, w: i64) -> Self { Self { x, y, z, w } }
27 pub const fn truncate(self) -> DIVec3{ divec3(self.x, self.y, self.z) }
28 pub const fn splat(value: i64) -> Self{ Self::new(value, value, value, value) }
30
31 pub fn length_squared(self) -> i64 {
33 self.x*self.x + self.y*self.y + self.z*self.z + self.w*self.w
34 }
35 pub fn distance_squared(self, other: DIVec4) -> i64{
37 (self - other).length_squared()
38 }
39 pub fn dot(self, other: DIVec4) -> i64{
41 self.x * other.x + self.y * other.y + self.z * other.z + self.w * other.w
42 }
43 pub fn scale(self, scalar: i64) -> DIVec4{
45 Self::new(self.x * scalar, self.y * scalar, self.z * scalar, self.w * scalar)
46 }
47 pub fn eq(self, rhs: Self) -> BVec4 { bvec4(self.x == rhs.x, self.y == rhs.y, self.z == rhs.z, self.w == rhs.w) }
49 pub fn less(self, rhs: Self) -> BVec4 { bvec4(self.x < rhs.x, self.y < rhs.y, self.z < rhs.z, self.w < rhs.w) }
51 pub fn more(self, rhs: Self) -> BVec4 { bvec4(self.x > rhs.x, self.y > rhs.y, self.z > rhs.z, self.w > rhs.w) }
53 pub fn less_or_eq(self, rhs: Self) -> BVec4 {
55 bvec4(self.x <= rhs.x, self.y <= rhs.y, self.z <= rhs.z, self.w <= rhs.w)
56 }
57 pub fn more_or_eq(self, rhs: Self) -> BVec4 {
59 bvec4(self.x >= rhs.x, self.y >= rhs.y, self.z >= rhs.z, self.w >= rhs.w)
60 }
61}
62impl std::ops::Mul<DIVec4> for i64 {
63 fn mul(self, rhs: DIVec4) -> Self::Output { rhs * self }
64 type Output = DIVec4;
65}
66impl std::ops::Mul<i64> for DIVec4 {
67 fn mul(self, rhs: i64) -> Self::Output { self.scale(rhs) }
68 type Output = Self;
69}
70impl std::ops::MulAssign<i64> for DIVec4 { fn mul_assign(&mut self, rhs: i64) { *self = *self * rhs } }
71impl std::ops::Div<DIVec4> for i64 {
72 fn div(self, rhs: DIVec4) -> Self::Output { DIVec4::splat(self) / rhs }
73 type Output = DIVec4;
74}
75impl std::ops::Div<i64> for DIVec4 {
76 fn div(self, rhs: i64) -> Self::Output { self / DIVec4::splat(rhs) }
77 type Output = Self;
78}
79impl std::ops::DivAssign<i64> for DIVec4 { fn div_assign(&mut self, rhs: i64) { *self = *self / rhs } }
80impl std::ops::Rem<DIVec4> for i64 {
81 fn rem(self, rhs: DIVec4) -> Self::Output { DIVec4::splat(self) % rhs }
82 type Output = DIVec4;
83}
84impl std::ops::Rem<i64> for DIVec4 {
85 fn rem(self, rhs: i64) -> Self::Output { self % DIVec4::splat(rhs) }
86 type Output = Self;
87}
88impl std::ops::RemAssign<i64> for DIVec4 { fn rem_assign(&mut self, rhs: i64) { *self = *self % rhs } }
89
90impl AsUniformValue for DIVec4 {
91 fn as_uniform_value(&self) -> glium::uniforms::UniformValue<'_> {
92 glium::uniforms::UniformValue::Int64Vec4([self.x, self.y, self.z, self.w])
93 }
94}
95impl From<Vec4> for DIVec4 {
96 fn from(value: Vec4) -> Self {
97 Self { x: value.x as i64, y: value.y as i64, z: value.z as i64, w: value.w as i64 }
98 }
99}
100impl From<(i64, i64, i64, i64)> for DIVec4 {
101 fn from(value: (i64, i64, i64, i64)) -> Self {
102 Self { x: value.0, y: value.1, z: value.2, w: value.3 }
103 }
104}
105impl From<[i64; 4]> for DIVec4 {
106 fn from(value: [i64; 4]) -> Self {
107 Self { x: value[0], y: value[1], z: value[2], w: value[3] }
108 }
109}
110impl From<DIVec4> for [i64; 4] {
111 fn from(value: DIVec4) -> Self {
112 [value.x, value.y, value.z, value.w]
113 }
114}
115impl From<DIVec4> for (i64, i64, i64, i64) {
116 fn from(value: DIVec4) -> Self {
117 (value.x, value.y, value.z, value.w)
118 }
119}
120pub const fn divec4(x: i64, y: i64, z: i64, w: i64) -> DIVec4 {
122 DIVec4 { x, y, z, w }
123}