iomath/types/
vectors.rs

1use crate::types::basic_types::{ TVector2, TVector3, TVector4, TQuaternion };
2use crate::types::basic_types::num_traits::Zero;
3
4use std::ops::*;
5use std::fmt::*;
6
7impl<T> TVector2<T> where T : Zero<T> + Copy {
8    /// Creates TVector2&lt;type&gt; whose x and y equal to zero
9    /// ```
10    /// use iomath::vectors::Vector2;
11    /// 
12    /// let vector = Vector2::empty();
13    /// assert_eq!(vector, Vector2 { x: 0.0, y: 0.0 });
14    /// ```
15    pub fn empty() -> Self {
16        Self {
17            x: T::zero(),
18            y: T::zero()
19        }
20    }
21    
22    /// Creates TVector2&lt;type&gt; with x and y
23    /// ```
24    /// use iomath::vectors::Vector2;
25    /// 
26    /// let vector = Vector2::new(3.7, -1.3);
27    /// assert_eq!(vector, Vector2 { x: 3.7, y: -1.3 });
28    /// ```
29    pub fn new(x: T, y: T) -> Self {
30        Self {
31            x,
32            y
33        }
34    }
35    
36    /// Creates TVector2&lt;type&gt; whose x and y equal to scalar
37    /// ```
38    /// use iomath::vectors::Vector2;
39    /// 
40    /// let vector = Vector2::from_scalar(8.2);
41    /// assert_eq!(vector, Vector2::new(8.2, 8.2));
42    /// ```
43    pub fn from_scalar(scalar: T) -> Self {
44        Self {
45            x: scalar,
46            y: scalar
47        }
48    }
49}
50
51impl<T> TVector3<T> where T : Zero<T> + Copy {
52    /// Creates TVector3&lt;type&gt; whose x, y and z equal to zero
53    /// ```
54    /// use iomath::vectors::Vector3;
55    /// 
56    /// let vector = Vector3::empty();
57    /// assert_eq!(vector, Vector3 { x: 0.0, y: 0.0, z: 0.0 });
58    /// ```
59    pub fn empty() -> Self {
60        Self {
61            x: T::zero(),
62            y: T::zero(),
63            z: T::zero()
64        }
65    }
66    
67    /// Creates TVector3&lt;type&gt; with x, y and z
68    /// ```
69    /// use iomath::vectors::Vector3;
70    /// 
71    /// let vector = Vector3::new(3.7, -1.3, 0.5);
72    /// assert_eq!(vector, Vector3 { x: 3.7, y: -1.3, z: 0.5 });
73    /// ```
74    pub fn new(x: T, y: T, z: T) -> Self {
75        Self {
76            x,
77            y,
78            z
79        }
80    }
81    
82    /// Creates TVector3&lt;type&gt; whose x, y and z equal to scalar
83    /// ```
84    /// use iomath::vectors::Vector3;
85    /// 
86    /// let vector = Vector3::from_scalar(8.2);
87    /// assert_eq!(vector, Vector3::new(8.2, 8.2, 8.2));
88    /// ```
89    pub fn from_scalar(scalar: T) -> Self {
90        Self {
91            x: scalar,
92            y: scalar,
93            z: scalar
94        }
95    }
96
97    /// Creates TVector3&lt;type&gt; whose x equals to value, y and z equal to TVector2&lt;type&gt;'s x and y
98    /// ```
99    /// use iomath::vectors::{ Vector3, Vector2 };
100    /// 
101    /// let vector = Vector3::from_value_vector(-4.2, Vector2::new(7.3, 2.4));
102    /// assert_eq!(vector, Vector3::new(-4.2, 7.3, 2.4));
103    /// ```
104    pub fn from_value_vector(value: T, vector: TVector2<T>) -> Self {
105        Self {
106            x: value,
107            y: vector.x,
108            z: vector.y
109        }
110    }
111
112    /// Creates TVector3&lt;type&gt; whose x and y equal to TVector2&lt;type&gt;'s x and y, z equals to value
113    /// ```
114    /// use iomath::vectors::{ Vector3, Vector2 };
115    /// 
116    /// let vector = Vector3::from_vector_value(Vector2::new(7.3, 2.4), -4.2);
117    /// assert_eq!(vector, Vector3::new(7.3, 2.4, -4.2));
118    /// ```
119    pub fn from_vector_value(vector: TVector2<T>, value: T) -> Self {
120        Self {
121            x: vector.x,
122            y: vector.y,
123            z: value
124        }
125    }
126}
127
128impl<T> TVector4<T> where T : Zero<T> + Copy {
129    /// Creates TVector4&lt;type&gt; whose x, y, z and w equal to zero
130    /// ```
131    /// use iomath::vectors::Vector4;
132    /// 
133    /// let vector = Vector4::empty();
134    /// assert_eq!(vector, Vector4 { x: 0.0, y: 0.0, z: 0.0, w: 0.0 });
135    /// ```
136    pub fn empty() -> Self {
137        Self {
138            x: T::zero(),
139            y: T::zero(),
140            z: T::zero(),
141            w: T::zero()
142        }
143    }
144
145    /// Creates TVector4&lt;type&gt; with x, y, z and w
146    /// ```
147    /// use iomath::vectors::Vector4;
148    /// 
149    /// let vector = Vector4::new(3.7, -1.3, 0.5, 6.4);
150    /// assert_eq!(vector, Vector4 { x: 3.7, y: -1.3, z: 0.5, w: 6.4 });
151    /// ```
152    pub fn new(x: T, y: T, z: T, w: T) -> Self {
153        Self {
154            x,
155            y,
156            z,
157            w
158        }
159    }
160
161    /// Creates TVector4&lt;type&gt; whose x, y, z, and w equal to scalar
162    /// ```
163    /// use iomath::vectors::Vector4;
164    /// 
165    /// let vector = Vector4::from_scalar(9.0);
166    /// assert_eq!(vector, Vector4::new(9.0, 9.0, 9.0, 9.0));
167    /// ```
168    pub fn from_scalar(scalar: T) -> Self {
169        Self {
170            x: scalar,
171            y: scalar,
172            z: scalar,
173            w: scalar
174        }
175    }
176
177    /// Creates TVector4&lt;type&gt; whose x equals to first value, y to second value, z and w to TVector2&lt;type&gt;'s x and y
178    /// ```
179    /// use iomath::vectors::{ Vector4, Vector2 };
180    /// 
181    /// let vector = Vector4::from_two_values_vector(4.0, 5.0, Vector2::new(6.0, 7.0));
182    /// assert_eq!(vector, Vector4::new(4.0, 5.0, 6.0, 7.0));
183    /// ```
184    pub fn from_two_values_vector(first_val: T, second_val: T, vector: TVector2<T>) -> Self {
185        Self {
186            x: first_val,
187            y: second_val,
188            z: vector.x,
189            w: vector.y
190        }
191    }
192
193    /// Creates TVector4&lt;type&gt; whose x equals to first value,y and z to TVector2&lt;type&gt;'s x and y, w to second value
194    /// ```
195    /// use iomath::vectors::{ Vector4, Vector2 };
196    /// 
197    /// let vector = Vector4::from_value_vector_value(4.0, Vector2::new(6.0, 7.0), 5.0);
198    /// assert_eq!(vector, Vector4::new(4.0, 6.0, 7.0, 5.0));
199    /// ```
200    pub fn from_value_vector_value(first_val: T, vector: TVector2<T>, second_val: T) -> Self {
201        Self {
202            x: first_val,
203            y: vector.x,
204            z: vector.y,
205            w: second_val
206        }
207    }
208
209    /// Creates TVector4&lt;type&gt; whose x and y equal to TVector2&lt;type&gt;'s x and y, z to first value, w to second value
210    /// ```
211    /// use iomath::vectors::{ Vector4, Vector2 };
212    /// 
213    /// let vector = Vector4::from_vector_two_values(Vector2::new(6.0, 7.0), 4.0, 5.0);
214    /// assert_eq!(vector, Vector4::new(6.0, 7.0, 4.0, 5.0));
215    /// ```
216    pub fn from_vector_two_values(vector: TVector2<T>, first_val: T, second_val: T) -> Self {
217        Self {
218            x: vector.x,
219            y: vector.y,
220            z: first_val,
221            w: second_val
222        }
223    }
224
225    /// Creates TVector4&lt;type&gt; whose x and y equal to first TVector2&lt;type&gt;'s x and y, z and w to second TVector2&lt;type&gt;'s x and y
226    /// ```
227    /// use iomath::vectors::{ Vector4, Vector2 };
228    /// 
229    /// let vector = Vector4::from_two_vectors(Vector2::new(4.0, 7.0), Vector2::new(5.0, 6.0));
230    /// assert_eq!(vector, Vector4::new(4.0, 7.0, 5.0, 6.0));
231    /// ```
232    pub fn from_two_vectors(first_vector: TVector2<T>, second_vector: TVector2<T>) -> Self {
233        Self {
234            x: first_vector.x,
235            y: first_vector.y,
236            z: second_vector.x,
237            w: second_vector.y
238        }
239    }
240
241    /// Creates TVector4&lt;type&gt; whose x equals to value, y, z and w equal to TVector3&lt;type&gt;'s x, y and z
242    /// ```
243    /// use iomath::vectors::{ Vector4, Vector3 };
244    /// 
245    /// let vector = Vector4::from_value_vector(1.7, Vector3::new(1.4, 5.5, 2.3));
246    /// assert_eq!(vector, Vector4::new(1.7, 1.4, 5.5, 2.3));
247    /// ```
248    pub fn from_value_vector(value: T, vector: TVector3<T>) -> Self {
249        Self {
250            x: value,
251            y: vector.x,
252            z: vector.y,
253            w: vector.z
254        }
255    }
256
257    /// Creates TVector4&lt;type&gt; whose x, y and z equal to TVector3&lt;type&gt;'s x, y and z, w equals to value
258    /// ```
259    /// use iomath::vectors::{ Vector4, Vector3 };
260    /// 
261    /// let vector = Vector4::from_vector_value(Vector3::new(1.4, 5.5, 2.3), 1.7);
262    /// assert_eq!(vector, Vector4::new(1.4, 5.5, 2.3, 1.7));
263    /// ```
264    pub fn from_vector_value(vector: TVector3<T>, value: T) -> Self {
265        Self {
266            x: vector.x,
267            y: vector.y,
268            z: vector.z,
269            w: value
270        }
271    }
272}
273
274impl<T> Copy for TVector2<T> where T : Copy { }
275impl<T> Clone for TVector2<T> where T : Copy {
276    fn clone(&self) -> Self {
277        *self
278    }
279
280    fn clone_from(&mut self, source: &Self) {
281        self.x = source.x;
282        self.y = source.y;
283    }
284}
285
286impl<T> From<TVector3<T>> for TVector2<T> {
287    fn from(vector: TVector3<T>) -> Self {
288        Self {
289            x: vector.x,
290            y: vector.y
291        }
292    }
293}
294
295impl<T> From<TVector4<T>> for TVector2<T> {
296    fn from(vector: TVector4<T>) -> Self {
297        Self {
298            x: vector.x,
299            y: vector.y
300        }
301    }
302}
303
304impl<T> From<TQuaternion<T>> for TVector2<T> {
305    fn from(quat: TQuaternion<T>) -> Self {
306        Self {
307            x: quat.x,
308            y: quat.y
309        }
310    }
311}
312
313impl<T> Index<usize> for TVector2<T> {
314    type Output = T;
315    
316    fn index(&self, index: usize) -> &Self::Output {
317        match index {
318            0 => &self.x,
319            1 => &self.y,
320            _ => &self.y
321        }
322    }
323}
324
325impl<T> IndexMut<usize> for TVector2<T> {
326    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
327        match index {
328            0 => &mut self.x,
329            1 => &mut self.y,
330            _ => &mut self.y
331        }
332    }
333}
334
335impl<T> PartialEq for TVector2<T> where T : PartialEq {
336    fn eq(&self, other: &Self) -> bool {
337        self.x == other.x &&
338        self.y == other.y
339    }
340}
341
342impl<T> Add<T> for TVector2<T> where T : Add<Output = T> + Copy {
343    type Output = Self;
344
345    fn add(self, scalar: T) -> Self::Output {
346        Self {
347            x: self.x + scalar,
348            y: self.y + scalar
349        }
350    }
351}
352
353impl<T> Add<TVector2<T>> for TVector2<T> where T : Add<Output = T> {
354    type Output = Self;
355
356    fn add(self, other: Self) -> Self::Output {
357        Self {
358            x: self.x + other.x,
359            y: self.y + other.y
360        }
361    }
362}
363
364impl<T> AddAssign<T> for TVector2<T> where T : AddAssign + Copy {
365    fn add_assign(&mut self, scalar: T) {
366        self.x += scalar;
367        self.y += scalar;
368    }
369}
370
371impl<T> AddAssign<TVector2<T>> for TVector2<T> where T : AddAssign {
372    fn add_assign(&mut self, other: Self) {
373        self.x += other.x;
374        self.y += other.y;
375    }
376}
377
378impl<T> Sub<T> for TVector2<T> where T : Sub<Output = T> + Copy {
379    type Output = Self;
380
381    fn sub(self, scalar: T) -> Self::Output {
382        Self {
383            x: self.x - scalar,
384            y: self.y - scalar
385        }
386    }
387}
388
389impl<T> Sub<TVector2<T>> for TVector2<T> where T : Sub<Output = T> {
390    type Output = Self;
391
392    fn sub(self, other: Self) -> Self::Output {
393        Self {
394            x: self.x - other.x,
395            y: self.y - other.y
396        }
397    }
398}
399
400impl<T> SubAssign<T> for TVector2<T> where T : SubAssign + Copy {
401    fn sub_assign(&mut self, scalar: T) {
402        self.x -= scalar;
403        self.y -= scalar;
404    }
405}
406
407impl<T> SubAssign<TVector2<T>> for TVector2<T> where T : SubAssign {
408    fn sub_assign(&mut self, other: Self) {
409        self.x -= other.x;
410        self.y -= other.y;
411    }
412}
413
414impl<T> Mul<T> for TVector2<T> where T : Mul<Output = T> + Copy {
415    type Output = Self;
416
417    fn mul(self, scalar: T) -> Self::Output {
418        Self {
419            x: self.x * scalar,
420            y: self.y * scalar
421        }
422    }
423}
424
425impl<T> Mul<TVector2<T>> for TVector2<T> where T : Mul<Output = T> {
426    type Output = Self;
427
428    fn mul(self, other: Self) -> Self::Output {
429        Self {
430            x: self.x * other.x,
431            y: self.y * other.y
432        }
433    }
434}
435
436impl<T> MulAssign<T> for TVector2<T> where T : MulAssign + Copy {
437    fn mul_assign(&mut self, scalar: T) {
438        self.x *= scalar;
439        self.y *= scalar;
440    }
441}
442
443impl<T> MulAssign<TVector2<T>> for TVector2<T> where T : MulAssign {
444    fn mul_assign(&mut self, other: Self) {
445        self.x *= other.x;
446        self.y *= other.y;
447    }
448}
449
450impl<T> Div<T> for TVector2<T> where T : Div<Output = T> + Copy {
451    type Output = Self;
452
453    fn div(self, scalar: T) -> Self::Output {
454        Self {
455            x: self.x / scalar,
456            y: self.y / scalar
457        }
458    }
459}
460
461impl<T> Div<TVector2<T>> for TVector2<T> where T : Div<Output = T> {
462    type Output = Self;
463
464    fn div(self, other: Self) -> Self::Output {
465        Self {
466            x: self.x / other.x,
467            y: self.y / other.y
468        }
469    }
470}
471
472impl<T> DivAssign<T> for TVector2<T> where T : DivAssign + Copy {
473    fn div_assign(&mut self, scalar: T) {
474        self.x /= scalar;
475        self.y /= scalar;
476    }
477}
478
479impl<T> DivAssign<TVector2<T>> for TVector2<T> where T : DivAssign {
480    fn div_assign(&mut self, other: Self) {
481        self.x /= other.x;
482        self.y /= other.y;
483    }
484}
485
486impl<T> Neg for TVector2<T> where T : Neg<Output = T> {
487    type Output = Self;
488
489    fn neg(self) -> Self::Output {
490        Self {
491            x: -self.x,
492            y: -self.y
493        }
494    }
495}
496
497impl<T> BitAnd<T> for TVector2<T> where T : BitAnd<Output = T> + Copy {
498    type Output = Self;
499
500    fn bitand(self, scalar: T) -> Self::Output {
501        Self {
502            x: self.x & scalar,
503            y: self.y & scalar
504        }
505    }
506}
507
508impl<T> BitAnd<TVector2<T>> for TVector2<T> where T : BitAnd<Output = T> {
509    type Output = Self;
510
511    fn bitand(self, rhs: Self) -> Self::Output {
512        Self {
513            x: self.x & rhs.x,
514            y: self.y & rhs.y
515        }
516    }
517}
518
519impl<T> BitAndAssign<T> for TVector2<T> where T : BitAndAssign + Copy {
520    fn bitand_assign(&mut self, scalar: T) {
521        self.x &= scalar;
522        self.y &= scalar;
523    }
524}
525
526impl<T> BitAndAssign<TVector2<T>> for TVector2<T> where T : BitAndAssign {
527    fn bitand_assign(&mut self, rhs: Self) {
528        self.x &= rhs.x;
529        self.y &= rhs.y;
530    }
531}
532
533impl<T> BitOr<T> for TVector2<T> where T : BitOr<Output = T> + Copy {
534    type Output = Self;
535
536    fn bitor(self, scalar: T) -> Self::Output {
537        Self {
538            x: self.x | scalar,
539            y: self.y | scalar
540        }
541    }
542}
543
544impl<T> BitOr<TVector2<T>> for TVector2<T> where T : BitOr<Output = T> {
545    type Output = Self;
546
547    fn bitor(self, rhs: Self) -> Self::Output {
548        Self {
549            x: self.x | rhs.x,
550            y: self.y | rhs.y
551        }
552    }
553}
554
555impl<T> BitOrAssign<T> for TVector2<T> where T : BitOrAssign + Copy {
556    fn bitor_assign(&mut self, scalar: T) {
557        self.x |= scalar;
558        self.y |= scalar;
559    }
560}
561
562impl<T> BitOrAssign<TVector2<T>> for TVector2<T> where T : BitOrAssign {
563    fn bitor_assign(&mut self, rhs: Self) {
564        self.x |= rhs.x;
565        self.y |= rhs.y;
566    }
567}
568
569impl<T> BitXor<T> for TVector2<T> where T : BitXor<Output = T> + Copy {
570    type Output = Self;
571
572    fn bitxor(self, scalar: T) -> Self::Output {
573        Self {
574            x: self.x ^ scalar,
575            y: self.y ^ scalar
576        }
577    }
578}
579
580impl<T> BitXor<TVector2<T>> for TVector2<T> where T : BitXor<Output = T> {
581    type Output = Self;
582
583    fn bitxor(self, rhs: Self) -> Self::Output {
584        Self {
585            x: self.x ^ rhs.x,
586            y: self.y ^ rhs.y
587        }
588    }
589}
590
591impl<T> BitXorAssign<T> for TVector2<T> where T : BitXorAssign + Copy {
592    fn bitxor_assign(&mut self, scalar: T) {
593        self.x ^= scalar;
594        self.y ^= scalar;
595    }
596}
597
598impl<T> BitXorAssign<TVector2<T>> for TVector2<T> where T : BitXorAssign {
599    fn bitxor_assign(&mut self, rhs: Self) {
600        self.x ^= rhs.x;
601        self.y ^= rhs.y;
602    }
603}
604
605impl<T> Rem<T> for TVector2<T> where T : Rem<Output = T> + Copy {
606    type Output = Self;
607
608    fn rem(self, scalar: T) -> Self::Output {
609        Self {
610            x: self.x % scalar,
611            y: self.y % scalar
612        }
613    }
614}
615
616impl<T> Rem<TVector2<T>> for TVector2<T> where T : Rem<Output = T> {
617    type Output = Self;
618
619    fn rem(self, rhs: Self) -> Self::Output {
620        Self {
621            x: self.x % rhs.x,
622            y: self.y % rhs.y
623        }
624    }
625}
626
627impl<T> RemAssign<T> for TVector2<T> where T : RemAssign + Copy {
628    fn rem_assign(&mut self, scalar: T) {
629        self.x %= scalar;
630        self.y %= scalar;
631    }
632}
633
634impl<T> RemAssign<TVector2<T>> for TVector2<T> where T : RemAssign {
635    fn rem_assign(&mut self, rhs: Self) {
636        self.x %= rhs.x;
637        self.y %= rhs.y;
638    }
639}
640
641impl<T> Shl<T> for TVector2<T> where T : Shl<Output = T> + Copy {
642    type Output = Self;
643
644    fn shl(self, scalar: T) -> Self::Output {
645        Self {
646            x: self.x << scalar,
647            y: self.y << scalar
648        }
649    }
650}
651
652impl<T> Shl<TVector2<T>> for TVector2<T> where T : Shl<Output = T> {
653    type Output = Self;
654
655    fn shl(self, rhs: Self) -> Self::Output {
656        Self {
657            x: self.x << rhs.x,
658            y: self.y << rhs.y
659        }
660    }
661}
662
663impl<T> ShlAssign<T> for TVector2<T> where T : ShlAssign + Copy {
664    fn shl_assign(&mut self, scalar: T) {
665        self.x <<= scalar;
666        self.y <<= scalar;
667    }
668}
669
670impl<T> ShlAssign<TVector2<T>> for TVector2<T> where T : ShlAssign {
671    fn shl_assign(&mut self, rhs: Self) {
672        self.x <<= rhs.x;
673        self.y <<= rhs.y;
674    }
675}
676
677impl<T> Shr<T> for TVector2<T> where T : Shr<Output = T> + Copy {
678    type Output = Self;
679
680    fn shr(self, scalar: T) -> Self::Output {
681        Self {
682            x: self.x >> scalar,
683            y: self.y >> scalar
684        }
685    }
686}
687
688impl<T> Shr<TVector2<T>> for TVector2<T> where T : Shr<Output = T> {
689    type Output = Self;
690
691    fn shr(self, rhs: Self) -> Self::Output {
692        Self {
693            x: self.x >> rhs.x,
694            y: self.y >> rhs.y
695        }
696    }
697}
698
699impl<T> ShrAssign<T> for TVector2<T> where T : ShrAssign + Copy {
700    fn shr_assign(&mut self, scalar: T) {
701        self.x >>= scalar;
702        self.y >>= scalar;
703    }
704}
705
706impl<T> ShrAssign<TVector2<T>> for TVector2<T> where T : ShrAssign {
707    fn shr_assign(&mut self, rhs: Self) {
708        self.x >>= rhs.x;
709        self.y >>= rhs.y;
710    }
711}
712
713impl<T> Debug for TVector2<T> where T : Debug {
714    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
715        f.debug_struct(format!("TVector2<{}>", std::any::type_name::<T>()).as_str())
716         .field("x", &self.x)
717         .field("y", &self.y)
718         .finish()
719    }
720}
721
722impl<T> Copy for TVector3<T> where T : Copy { }
723impl<T> Clone for TVector3<T> where T : Copy {
724    fn clone(&self) -> Self {
725        *self
726    }
727
728    fn clone_from(&mut self, source: &Self) {
729        self.x = source.x;
730        self.y = source.y;
731        self.z = source.z;
732    }
733}
734
735impl<T> From<TVector2<T>> for TVector3<T> where T : Zero<T> {
736    fn from(vector: TVector2<T>) -> Self {
737        Self {
738            x: vector.x,
739            y: vector.y,
740            z: T::zero()
741        }
742    }
743}
744
745impl<T> From<TVector4<T>> for TVector3<T> {
746    fn from(vector: TVector4<T>) -> Self {
747        Self {
748            x: vector.x,
749            y: vector.y,
750            z: vector.z
751        }
752    }
753}
754
755impl<T> From<TQuaternion<T>> for TVector3<T> {
756    fn from(quat: TQuaternion<T>) -> Self {
757        Self {
758            x: quat.x,
759            y: quat.y,
760            z: quat.z
761        }
762    }
763}
764
765impl<T> Index<usize> for TVector3<T> {
766    type Output = T;
767    
768    fn index(&self, index: usize) -> &Self::Output {
769        match index {
770            0 => &self.x,
771            1 => &self.y,
772            2 => &self.z,
773            _ => &self.z
774        }
775    }
776}
777
778impl<T> IndexMut<usize> for TVector3<T> {
779    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
780        match index {
781            0 => &mut self.x,
782            1 => &mut self.y,
783            2 => &mut self.z,
784            _ => &mut self.z
785        }
786    }
787}
788
789impl<T> PartialEq for TVector3<T> where T : PartialEq {
790    fn eq(&self, other: &Self) -> bool {
791        self.x == other.x &&
792        self.y == other.y &&
793        self.z == other.z
794    }
795}
796
797impl<T> Add<T> for TVector3<T> where T : Add<Output = T> + Copy {
798    type Output = Self;
799
800    fn add(self, scalar: T) -> Self::Output {
801        Self {
802            x: self.x + scalar,
803            y: self.y + scalar,
804            z: self.z + scalar
805        }
806    }
807}
808
809impl<T> Add<TVector3<T>> for TVector3<T> where T : Add<Output = T> {
810    type Output = Self;
811
812    fn add(self, other: Self) -> Self::Output {
813        Self {
814            x: self.x + other.x,
815            y: self.y + other.y,
816            z: self.z + other.z
817        }
818    }
819}
820
821impl<T> AddAssign<T> for TVector3<T> where T : AddAssign + Copy {
822    fn add_assign(&mut self, scalar: T) {
823        self.x += scalar;
824        self.y += scalar;
825        self.z += scalar;
826    }
827}
828
829impl<T> AddAssign<TVector3<T>> for TVector3<T> where T : AddAssign {
830    fn add_assign(&mut self, other: Self) {
831        self.x += other.x;
832        self.y += other.y;
833        self.z += other.z;
834    }
835}
836
837impl<T> Sub<T> for TVector3<T> where T : Sub<Output = T> + Copy {
838    type Output = Self;
839
840    fn sub(self, scalar: T) -> Self::Output {
841        Self {
842            x: self.x - scalar,
843            y: self.y - scalar,
844            z: self.z - scalar
845        }
846    }
847}
848
849impl<T> Sub<TVector3<T>> for TVector3<T> where T : Sub<Output = T> {
850    type Output = Self;
851
852    fn sub(self, other: Self) -> Self::Output {
853        Self {
854            x: self.x - other.x,
855            y: self.y - other.y,
856            z: self.z - other.z
857        }
858    }
859}
860
861impl<T> SubAssign<T> for TVector3<T> where T : SubAssign + Copy {
862    fn sub_assign(&mut self, scalar: T) {
863        self.x -= scalar;
864        self.y -= scalar;
865        self.z -= scalar;
866    }
867}
868
869impl<T> SubAssign<TVector3<T>> for TVector3<T> where T : SubAssign {
870    fn sub_assign(&mut self, other: Self) {
871        self.x -= other.x;
872        self.y -= other.y;
873        self.z -= other.z;
874    }
875}
876
877impl<T> Mul<T> for TVector3<T> where T : Mul<Output = T> + Copy {
878    type Output = Self;
879
880    fn mul(self, scalar: T) -> Self::Output {
881        Self {
882            x: self.x * scalar,
883            y: self.y * scalar,
884            z: self.z * scalar
885        }
886    }
887}
888
889impl<T> Mul<TVector3<T>> for TVector3<T> where T : Mul<Output = T> {
890    type Output = Self;
891
892    fn mul(self, other: Self) -> Self::Output {
893        Self {
894            x: self.x * other.x,
895            y: self.y * other.y,
896            z: self.z * other.z
897        }
898    }
899}
900
901impl<T> MulAssign<T> for TVector3<T> where T : MulAssign + Copy {
902    fn mul_assign(&mut self, scalar: T) {
903        self.x *= scalar;
904        self.y *= scalar;
905        self.z *= scalar;
906    }
907}
908
909impl<T> MulAssign<TVector3<T>> for TVector3<T> where T : MulAssign {
910    fn mul_assign(&mut self, other: Self) {
911        self.x *= other.x;
912        self.y *= other.y;
913        self.z *= other.z;
914    }
915}
916
917impl<T> Div<T> for TVector3<T> where T : Div<Output = T> + Copy {
918    type Output = Self;
919
920    fn div(self, scalar: T) -> Self::Output {
921        Self {
922            x: self.x / scalar,
923            y: self.y / scalar,
924            z: self.z / scalar
925        }
926    }
927}
928
929impl<T> Div<TVector3<T>> for TVector3<T> where T : Div<Output = T> {
930    type Output = Self;
931
932    fn div(self, other: Self) -> Self::Output {
933        Self {
934            x: self.x / other.x,
935            y: self.y / other.y,
936            z: self.z / other.z
937        }
938    }
939}
940
941impl<T> DivAssign<T> for TVector3<T> where T : DivAssign + Copy {
942    fn div_assign(&mut self, scalar: T) {
943        self.x /= scalar;
944        self.y /= scalar;
945        self.z /= scalar;
946    }
947}
948
949impl<T> DivAssign<TVector3<T>> for TVector3<T> where T : DivAssign {
950    fn div_assign(&mut self, other: Self) {
951        self.x /= other.x;
952        self.y /= other.y;
953        self.z /= other.z;
954    }
955}
956
957impl<T> Neg for TVector3<T> where T : Neg<Output = T> {
958    type Output = Self;
959
960    fn neg(self) -> Self::Output {
961        Self {
962            x: -self.x,
963            y: -self.y,
964            z: -self.z
965        }
966    }
967}
968
969impl<T> BitAnd<T> for TVector3<T> where T : BitAnd<Output = T> + Copy {
970    type Output = Self;
971
972    fn bitand(self, scalar: T) -> Self::Output {
973        Self {
974            x: self.x & scalar,
975            y: self.y & scalar,
976            z: self.z & scalar
977        }
978    }
979}
980
981impl<T> BitAnd<TVector3<T>> for TVector3<T> where T : BitAnd<Output = T> {
982    type Output = Self;
983
984    fn bitand(self, rhs: Self) -> Self::Output {
985        Self {
986            x: self.x & rhs.x,
987            y: self.y & rhs.y,
988            z: self.z & rhs.z
989        }
990    }
991}
992
993impl<T> BitAndAssign<T> for TVector3<T> where T : BitAndAssign + Copy {
994    fn bitand_assign(&mut self, scalar: T) {
995        self.x &= scalar;
996        self.y &= scalar;
997        self.z &= scalar;
998    }
999}
1000
1001impl<T> BitAndAssign<TVector3<T>> for TVector3<T> where T : BitAndAssign {
1002    fn bitand_assign(&mut self, rhs: Self) {
1003        self.x &= rhs.x;
1004        self.y &= rhs.y;
1005        self.z &= rhs.z;
1006    }
1007}
1008
1009impl<T> BitOr<T> for TVector3<T> where T : BitOr<Output = T> + Copy {
1010    type Output = Self;
1011
1012    fn bitor(self, scalar: T) -> Self::Output {
1013        Self {
1014            x: self.x | scalar,
1015            y: self.y | scalar,
1016            z: self.z | scalar
1017        }
1018    }
1019}
1020
1021impl<T> BitOr<TVector3<T>> for TVector3<T> where T : BitOr<Output = T> {
1022    type Output = Self;
1023
1024    fn bitor(self, rhs: Self) -> Self::Output {
1025        Self {
1026            x: self.x | rhs.x,
1027            y: self.y | rhs.y,
1028            z: self.z | rhs.z
1029        }
1030    }
1031}
1032
1033impl<T> BitOrAssign<T> for TVector3<T> where T : BitOrAssign + Copy {
1034    fn bitor_assign(&mut self, scalar: T) {
1035        self.x |= scalar;
1036        self.y |= scalar;
1037        self.z |= scalar;
1038    }
1039}
1040
1041impl<T> BitOrAssign<TVector3<T>> for TVector3<T> where T : BitOrAssign {
1042    fn bitor_assign(&mut self, rhs: Self) {
1043        self.x |= rhs.x;
1044        self.y |= rhs.y;
1045        self.z |= rhs.z;
1046    }
1047}
1048
1049impl<T> BitXor<T> for TVector3<T> where T : BitXor<Output = T> + Copy {
1050    type Output = Self;
1051
1052    fn bitxor(self, scalar: T) -> Self::Output {
1053        Self {
1054            x: self.x ^ scalar,
1055            y: self.y ^ scalar,
1056            z: self.z ^ scalar
1057        }
1058    }
1059}
1060
1061impl<T> BitXor<TVector3<T>> for TVector3<T> where T : BitXor<Output = T> {
1062    type Output = Self;
1063
1064    fn bitxor(self, rhs: Self) -> Self::Output {
1065        Self {
1066            x: self.x ^ rhs.x,
1067            y: self.y ^ rhs.y,
1068            z: self.z ^ rhs.z
1069        }
1070    }
1071}
1072
1073impl<T> BitXorAssign<T> for TVector3<T> where T : BitXorAssign + Copy {
1074    fn bitxor_assign(&mut self, scalar: T) {
1075        self.x ^= scalar;
1076        self.y ^= scalar;
1077        self.z ^= scalar;
1078    }
1079}
1080
1081impl<T> BitXorAssign<TVector3<T>> for TVector3<T> where T : BitXorAssign {
1082    fn bitxor_assign(&mut self, rhs: Self) {
1083        self.x ^= rhs.x;
1084        self.y ^= rhs.y;
1085        self.z ^= rhs.z;
1086    }
1087}
1088
1089impl<T> Rem<T> for TVector3<T> where T : Rem<Output = T> + Copy {
1090    type Output = Self;
1091
1092    fn rem(self, scalar: T) -> Self::Output {
1093        Self {
1094            x: self.x % scalar,
1095            y: self.y % scalar,
1096            z: self.z % scalar
1097        }
1098    }
1099}
1100
1101impl<T> Rem<TVector3<T>> for TVector3<T> where T : Rem<Output = T> {
1102    type Output = Self;
1103
1104    fn rem(self, rhs: Self) -> Self::Output {
1105        Self {
1106            x: self.x % rhs.x,
1107            y: self.y % rhs.y,
1108            z: self.z % rhs.z
1109        }
1110    }
1111}
1112
1113impl<T> RemAssign<T> for TVector3<T> where T : RemAssign + Copy {
1114    fn rem_assign(&mut self, scalar: T) {
1115        self.x %= scalar;
1116        self.y %= scalar;
1117        self.z %= scalar;
1118    }
1119}
1120
1121impl<T> RemAssign<TVector3<T>> for TVector3<T> where T : RemAssign {
1122    fn rem_assign(&mut self, rhs: Self) {
1123        self.x %= rhs.x;
1124        self.y %= rhs.y;
1125        self.z %= rhs.z;
1126    }
1127}
1128
1129impl<T> Shl<T> for TVector3<T> where T : Shl<Output = T> + Copy {
1130    type Output = Self;
1131
1132    fn shl(self, scalar: T) -> Self::Output {
1133        Self {
1134            x: self.x << scalar,
1135            y: self.y << scalar,
1136            z: self.z << scalar
1137        }
1138    }
1139}
1140
1141impl<T> Shl<TVector3<T>> for TVector3<T> where T : Shl<Output = T> {
1142    type Output = Self;
1143
1144    fn shl(self, rhs: Self) -> Self::Output {
1145        Self {
1146            x: self.x << rhs.x,
1147            y: self.y << rhs.y,
1148            z: self.z << rhs.z
1149        }
1150    }
1151}
1152
1153impl<T> ShlAssign<T> for TVector3<T> where T : ShlAssign + Copy {
1154    fn shl_assign(&mut self, scalar: T) {
1155        self.x <<= scalar;
1156        self.y <<= scalar;
1157        self.z <<= scalar;
1158    }
1159}
1160
1161impl<T> ShlAssign<TVector3<T>> for TVector3<T> where T : ShlAssign {
1162    fn shl_assign(&mut self, rhs: Self) {
1163        self.x <<= rhs.x;
1164        self.y <<= rhs.y;
1165        self.z <<= rhs.z;
1166    }
1167}
1168
1169impl<T> Shr<T> for TVector3<T> where T : Shr<Output = T> + Copy {
1170    type Output = Self;
1171
1172    fn shr(self, scalar: T) -> Self::Output {
1173        Self {
1174            x: self.x >> scalar,
1175            y: self.y >> scalar,
1176            z: self.z >> scalar
1177        }
1178    }
1179}
1180
1181impl<T> Shr<TVector3<T>> for TVector3<T> where T : Shr<Output = T> {
1182    type Output = Self;
1183
1184    fn shr(self, rhs: Self) -> Self::Output {
1185        Self {
1186            x: self.x >> rhs.x,
1187            y: self.y >> rhs.y,
1188            z: self.z >> rhs.z
1189        }
1190    }
1191}
1192
1193impl<T> ShrAssign<T> for TVector3<T> where T : ShrAssign + Copy {
1194    fn shr_assign(&mut self, scalar: T) {
1195        self.x >>= scalar;
1196        self.y >>= scalar;
1197        self.z >>= scalar;
1198    }
1199}
1200
1201impl<T> ShrAssign<TVector3<T>> for TVector3<T> where T : ShrAssign {
1202    fn shr_assign(&mut self, rhs: Self) {
1203        self.x >>= rhs.x;
1204        self.y >>= rhs.y;
1205        self.z >>= rhs.z;
1206    }
1207}
1208
1209impl<T> Debug for TVector3<T> where T : Debug {
1210    fn fmt(&self, f: &mut Formatter<'_>) -> Result {        
1211        f.debug_struct(format!("TVector3<{}>", std::any::type_name::<T>()).as_str())
1212         .field("x", &self.x)
1213         .field("y", &self.y)
1214         .field("z", &self.z)
1215         .finish()
1216    }
1217}
1218
1219impl<T> Copy for TVector4<T> where T : Copy { }
1220impl<T> Clone for TVector4<T> where T : Copy {
1221    fn clone(&self) -> Self {
1222        *self
1223    }
1224
1225    fn clone_from(&mut self, source: &Self) {
1226        self.x = source.x;
1227        self.y = source.y;
1228        self.z = source.z;
1229        self.w = source.w;
1230    }
1231}
1232
1233impl<T> From<TVector2<T>> for TVector4<T> where T : Zero<T> {
1234    fn from(vector: TVector2<T>) -> Self {
1235        Self {
1236            x: vector.x,
1237            y: vector.y,
1238            z: T::zero(),
1239            w: T::zero()
1240        }
1241    }
1242}
1243
1244impl<T> From<TVector3<T>> for TVector4<T> where T : Zero<T> {
1245    fn from(vector: TVector3<T>) -> Self {
1246        Self {
1247            x: vector.x,
1248            y: vector.y,
1249            z: vector.z,
1250            w: T::zero()
1251        }
1252    }
1253}
1254
1255impl<T> From<TQuaternion<T>> for TVector4<T> {
1256    fn from(quat: TQuaternion<T>) -> Self {
1257        Self {
1258            x: quat.x,
1259            y: quat.y,
1260            z: quat.z,
1261            w: quat.w
1262        }
1263    }
1264}
1265
1266impl<T> Index<usize> for TVector4<T> {
1267    type Output = T;
1268    
1269    fn index(&self, index: usize) -> &Self::Output {
1270        match index {
1271            0 => &self.x,
1272            1 => &self.y,
1273            2 => &self.z,
1274            3 => &self.w,
1275            _ => &self.w
1276        }
1277    }
1278}
1279
1280impl<T> IndexMut<usize> for TVector4<T> {
1281    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1282        match index {
1283            0 => &mut self.x,
1284            1 => &mut self.y,
1285            2 => &mut self.z,
1286            3 => &mut self.w,
1287            _ => &mut self.w
1288        }
1289    }
1290}
1291
1292impl<T> PartialEq for TVector4<T> where T : PartialEq {
1293    fn eq(&self, other: &Self) -> bool {
1294        self.x == other.x &&
1295        self.y == other.y &&
1296        self.z == other.z &&
1297        self.w == other.w
1298    }
1299}
1300
1301impl<T> Add<T> for TVector4<T> where T : Add<Output = T> + Copy {
1302    type Output = Self;
1303
1304    fn add(self, scalar: T) -> Self::Output {
1305        Self {
1306            x: self.x + scalar,
1307            y: self.y + scalar,
1308            z: self.z + scalar,
1309            w: self.w + scalar
1310        }
1311    }
1312}
1313
1314impl<T> Add<TVector4<T>> for TVector4<T> where T : Add<Output = T> {
1315    type Output = Self;
1316
1317    fn add(self, other: Self) -> Self::Output {
1318        Self {
1319            x: self.x + other.x,
1320            y: self.y + other.y,
1321            z: self.z + other.z,
1322            w: self.w + other.w
1323        }
1324    }
1325}
1326
1327impl<T> AddAssign<T> for TVector4<T> where T : AddAssign + Copy {
1328    fn add_assign(&mut self, scalar: T) {
1329        self.x += scalar;
1330        self.y += scalar;
1331        self.z += scalar;
1332        self.w += scalar;
1333    }
1334}
1335
1336impl<T> AddAssign<TVector4<T>> for TVector4<T> where T : AddAssign {
1337    fn add_assign(&mut self, other: Self) {
1338        self.x += other.x;
1339        self.y += other.y;
1340        self.z += other.z;
1341        self.w += other.w
1342    }
1343}
1344
1345impl<T> Sub<T> for TVector4<T> where T : Sub<Output = T> + Copy {
1346    type Output = Self;
1347
1348    fn sub(self, scalar: T) -> Self::Output {
1349        Self {
1350            x: self.x - scalar,
1351            y: self.y - scalar,
1352            z: self.z - scalar,
1353            w: self.w - scalar
1354        }
1355    }
1356}
1357
1358impl<T> Sub<TVector4<T>> for TVector4<T> where T : Sub<Output = T> {
1359    type Output = Self;
1360
1361    fn sub(self, other: Self) -> Self::Output {
1362        Self {
1363            x: self.x - other.x,
1364            y: self.y - other.y,
1365            z: self.z - other.z,
1366            w: self.w - other.w
1367        }
1368    }
1369}
1370
1371impl<T> SubAssign<T> for TVector4<T> where T : SubAssign + Copy {
1372    fn sub_assign(&mut self, scalar: T) {
1373        self.x -= scalar;
1374        self.y -= scalar;
1375        self.z -= scalar;
1376        self.w -= scalar;
1377    }
1378}
1379
1380impl<T> SubAssign<TVector4<T>> for TVector4<T> where T : SubAssign {
1381    fn sub_assign(&mut self, other: Self) {
1382        self.x -= other.x;
1383        self.y -= other.y;
1384        self.z -= other.z;
1385        self.w -= other.w;
1386    }
1387}
1388
1389impl<T> Mul<T> for TVector4<T> where T : Mul<Output = T> + Copy {
1390    type Output = Self;
1391
1392    fn mul(self, scalar: T) -> Self::Output {
1393        Self {
1394            x: self.x * scalar,
1395            y: self.y * scalar,
1396            z: self.z * scalar,
1397            w: self.w * scalar
1398        }
1399    }
1400}
1401
1402impl<T> Mul<TVector4<T>> for TVector4<T> where T : Mul<Output = T> {
1403    type Output = Self;
1404
1405    fn mul(self, other: Self) -> Self::Output {
1406        Self {
1407            x: self.x * other.x,
1408            y: self.y * other.y,
1409            z: self.z * other.z,
1410            w: self.w * other.w
1411        }
1412    }
1413}
1414
1415impl<T> MulAssign<T> for TVector4<T> where T : MulAssign + Copy {
1416    fn mul_assign(&mut self, scalar: T) {
1417        self.x *= scalar;
1418        self.y *= scalar;
1419        self.z *= scalar;
1420        self.w *= scalar;
1421    }
1422}
1423
1424impl<T> MulAssign<TVector4<T>> for TVector4<T> where T : MulAssign {
1425    fn mul_assign(&mut self, other: Self) {
1426        self.x *= other.x;
1427        self.y *= other.y;
1428        self.z *= other.z;
1429        self.w *= other.w;
1430    }
1431}
1432
1433impl<T> Div<T> for TVector4<T> where T : Div<Output = T> + Copy {
1434    type Output = Self;
1435
1436    fn div(self, scalar: T) -> Self::Output {
1437        Self {
1438            x: self.x / scalar,
1439            y: self.y / scalar,
1440            z: self.z / scalar,
1441            w: self.w / scalar
1442        }
1443    }
1444}
1445
1446impl<T> Div<TVector4<T>> for TVector4<T> where T : Div<Output = T> {
1447    type Output = Self;
1448
1449    fn div(self, other: Self) -> Self::Output {
1450        Self {
1451            x: self.x / other.x,
1452            y: self.y / other.y,
1453            z: self.z / other.z,
1454            w: self.w / other.w
1455        }
1456    }
1457}
1458
1459impl<T> DivAssign<T> for TVector4<T> where T : DivAssign + Copy {
1460    fn div_assign(&mut self, scalar: T) {
1461        self.x /= scalar;
1462        self.y /= scalar;
1463        self.z /= scalar;
1464        self.w /= scalar;
1465    }
1466}
1467
1468impl<T> DivAssign<TVector4<T>> for TVector4<T> where T : DivAssign {
1469    fn div_assign(&mut self, other: Self) {
1470        self.x /= other.x;
1471        self.y /= other.y;
1472        self.z /= other.z;
1473        self.w /= other.w;
1474    }
1475}
1476
1477impl<T> Neg for TVector4<T> where T : Neg<Output = T> {
1478    type Output = Self;
1479
1480    fn neg(self) -> Self::Output {
1481        Self {
1482            x: -self.x,
1483            y: -self.y,
1484            z: -self.z,
1485            w: -self.w
1486        }
1487    }
1488}
1489
1490impl<T> BitAnd<T> for TVector4<T> where T : BitAnd<Output = T> + Copy {
1491    type Output = Self;
1492
1493    fn bitand(self, scalar: T) -> Self::Output {
1494        Self {
1495            x: self.x & scalar,
1496            y: self.y & scalar,
1497            z: self.z & scalar,
1498            w: self.w & scalar
1499        }
1500    }
1501}
1502
1503impl<T> BitAnd<TVector4<T>> for TVector4<T> where T : BitAnd<Output = T> {
1504    type Output = Self;
1505
1506    fn bitand(self, rhs: Self) -> Self::Output {
1507        Self {
1508            x: self.x & rhs.x,
1509            y: self.y & rhs.y,
1510            z: self.z & rhs.z,
1511            w: self.w & rhs.w
1512        }
1513    }
1514}
1515
1516impl<T> BitAndAssign<T> for TVector4<T> where T : BitAndAssign + Copy {
1517    fn bitand_assign(&mut self, scalar: T) {
1518        self.x &= scalar;
1519        self.y &= scalar;
1520        self.z &= scalar;
1521        self.w &= scalar;
1522    }
1523}
1524
1525impl<T> BitAndAssign<TVector4<T>> for TVector4<T> where T : BitAndAssign {
1526    fn bitand_assign(&mut self, rhs: Self) {
1527        self.x &= rhs.x;
1528        self.y &= rhs.y;
1529        self.z &= rhs.z;
1530        self.w &= rhs.w;
1531    }
1532}
1533
1534impl<T> BitOr<T> for TVector4<T> where T : BitOr<Output = T> + Copy {
1535    type Output = Self;
1536
1537    fn bitor(self, scalar: T) -> Self::Output {
1538        Self {
1539            x: self.x | scalar,
1540            y: self.y | scalar,
1541            z: self.z | scalar,
1542            w: self.w | scalar
1543        }
1544    }
1545}
1546
1547impl<T> BitOr<TVector4<T>> for TVector4<T> where T : BitOr<Output = T> {
1548    type Output = Self;
1549
1550    fn bitor(self, rhs: Self) -> Self::Output {
1551        Self {
1552            x: self.x | rhs.x,
1553            y: self.y | rhs.y,
1554            z: self.z | rhs.z,
1555            w: self.w | rhs.w
1556        }
1557    }
1558}
1559
1560impl<T> BitOrAssign<T> for TVector4<T> where T : BitOrAssign + Copy {
1561    fn bitor_assign(&mut self, scalar: T) {
1562        self.x |= scalar;
1563        self.y |= scalar;
1564        self.z |= scalar;
1565        self.w |= scalar;
1566    }
1567}
1568
1569impl<T> BitOrAssign<TVector4<T>> for TVector4<T> where T : BitOrAssign {
1570    fn bitor_assign(&mut self, rhs: Self) {
1571        self.x |= rhs.x;
1572        self.y |= rhs.y;
1573        self.z |= rhs.z;
1574        self.w |= rhs.w;
1575    }
1576}
1577
1578impl<T> BitXor<T> for TVector4<T> where T : BitXor<Output = T> + Copy {
1579    type Output = Self;
1580
1581    fn bitxor(self, scalar: T) -> Self::Output {
1582        Self {
1583            x: self.x ^ scalar,
1584            y: self.y ^ scalar,
1585            z: self.z ^ scalar,
1586            w: self.w ^ scalar
1587        }
1588    }
1589}
1590
1591impl<T> BitXor<TVector4<T>> for TVector4<T> where T : BitXor<Output = T> {
1592    type Output = Self;
1593
1594    fn bitxor(self, rhs: Self) -> Self::Output {
1595        Self {
1596            x: self.x ^ rhs.x,
1597            y: self.y ^ rhs.y,
1598            z: self.z ^ rhs.z,
1599            w: self.w ^ rhs.w
1600        }
1601    }
1602}
1603
1604impl<T> BitXorAssign<T> for TVector4<T> where T : BitXorAssign + Copy {
1605    fn bitxor_assign(&mut self, scalar: T) {
1606        self.x ^= scalar;
1607        self.y ^= scalar;
1608        self.z ^= scalar;
1609        self.w ^= scalar;
1610    }
1611}
1612
1613impl<T> BitXorAssign<TVector4<T>> for TVector4<T> where T : BitXorAssign {
1614    fn bitxor_assign(&mut self, rhs: Self) {
1615        self.x ^= rhs.x;
1616        self.y ^= rhs.y;
1617        self.z ^= rhs.z;
1618        self.w ^= rhs.w;
1619    }
1620}
1621
1622impl<T> Rem<T> for TVector4<T> where T : Rem<Output = T> + Copy {
1623    type Output = Self;
1624
1625    fn rem(self, scalar: T) -> Self::Output {
1626        Self {
1627            x: self.x % scalar,
1628            y: self.y % scalar,
1629            z: self.z % scalar,
1630            w: self.w % scalar
1631        }
1632    }
1633}
1634
1635impl<T> Rem<TVector4<T>> for TVector4<T> where T : Rem<Output = T> {
1636    type Output = Self;
1637
1638    fn rem(self, rhs: Self) -> Self::Output {
1639        Self {
1640            x: self.x % rhs.x,
1641            y: self.y % rhs.y,
1642            z: self.z % rhs.z,
1643            w: self.w % rhs.w
1644        }
1645    }
1646}
1647
1648impl<T> RemAssign<T> for TVector4<T> where T : RemAssign + Copy {
1649    fn rem_assign(&mut self, scalar: T) {
1650        self.x %= scalar;
1651        self.y %= scalar;
1652        self.z %= scalar;
1653        self.w %= scalar;
1654    }
1655}
1656
1657impl<T> RemAssign<TVector4<T>> for TVector4<T> where T : RemAssign {
1658    fn rem_assign(&mut self, rhs: Self) {
1659        self.x %= rhs.x;
1660        self.y %= rhs.y;
1661        self.z %= rhs.z;
1662        self.w %= rhs.w;
1663    }
1664}
1665
1666impl<T> Shl<T> for TVector4<T> where T : Shl<Output = T> + Copy {
1667    type Output = Self;
1668
1669    fn shl(self, scalar: T) -> Self::Output {
1670        Self {
1671            x: self.x << scalar,
1672            y: self.y << scalar,
1673            z: self.z << scalar,
1674            w: self.w << scalar
1675        }
1676    }
1677}
1678
1679impl<T> Shl<TVector4<T>> for TVector4<T> where T : Shl<Output = T> {
1680    type Output = Self;
1681
1682    fn shl(self, rhs: Self) -> Self::Output {
1683        Self {
1684            x: self.x << rhs.x,
1685            y: self.y << rhs.y,
1686            z: self.z << rhs.z,
1687            w: self.w << rhs.w
1688        }
1689    }
1690}
1691
1692impl<T> ShlAssign<T> for TVector4<T> where T : ShlAssign + Copy {
1693    fn shl_assign(&mut self, scalar: T) {
1694        self.x <<= scalar;
1695        self.y <<= scalar;
1696        self.z <<= scalar;
1697        self.w <<= scalar;
1698    }
1699}
1700
1701impl<T> ShlAssign<TVector4<T>> for TVector4<T> where T : ShlAssign {
1702    fn shl_assign(&mut self, rhs: Self) {
1703        self.x <<= rhs.x;
1704        self.y <<= rhs.y;
1705        self.z <<= rhs.z;
1706        self.w <<= rhs.w;
1707    }
1708}
1709
1710impl<T> Shr<T> for TVector4<T> where T : Shr<Output = T> + Copy {
1711    type Output = Self;
1712
1713    fn shr(self, scalar: T) -> Self::Output {
1714        Self {
1715            x: self.x >> scalar,
1716            y: self.y >> scalar,
1717            z: self.z >> scalar,
1718            w: self.w >> scalar
1719        }
1720    }
1721}
1722
1723impl<T> Shr<TVector4<T>> for TVector4<T> where T : Shr<Output = T> {
1724    type Output = Self;
1725
1726    fn shr(self, rhs: Self) -> Self::Output {
1727        Self {
1728            x: self.x >> rhs.x,
1729            y: self.y >> rhs.y,
1730            z: self.z >> rhs.z,
1731            w: self.w >> rhs.w
1732        }
1733    }
1734}
1735
1736impl<T> ShrAssign<T> for TVector4<T> where T : ShrAssign + Copy {
1737    fn shr_assign(&mut self, scalar: T) {
1738        self.x >>= scalar;
1739        self.y >>= scalar;
1740        self.z >>= scalar;
1741        self.w >>= scalar;
1742    }
1743}
1744
1745impl<T> ShrAssign<TVector4<T>> for TVector4<T> where T : ShrAssign {
1746    fn shr_assign(&mut self, rhs: Self) {
1747        self.x >>= rhs.x;
1748        self.y >>= rhs.y;
1749        self.z >>= rhs.z;
1750        self.w >>= rhs.w;
1751    }
1752}
1753
1754impl<T> Debug for TVector4<T> where T : Debug {
1755    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
1756        f.debug_struct(format!("TVector4<{}>", std::any::type_name::<T>()).as_str())
1757         .field("x", &self.x)
1758         .field("y", &self.y)
1759         .field("z", &self.z)
1760         .field("w", &self.w)
1761         .finish()
1762    }
1763}