88use godot_ffi as sys;
99use sys:: { ffi_methods, GodotFfi } ;
1010
11- use crate :: builtin:: math:: { FloatExt , GlamConv , GlamType } ;
12- use crate :: builtin:: { real, RVec4 , Vector4 , Vector4Axis } ;
11+ use crate :: builtin:: math:: { GlamConv , GlamType } ;
12+ use crate :: builtin:: { inner , real, RVec4 , Vector4 , Vector4Axis } ;
1313
1414use std:: fmt;
1515
@@ -39,67 +39,18 @@ pub struct Vector4i {
3939}
4040
4141impl_vector_operators ! ( Vector4i , i32 , ( x, y, z, w) ) ;
42- impl_integer_vector_glam_fns ! ( Vector4i , real) ;
43- impl_integer_vector_component_fns ! ( Vector4i , real, ( x, y, z, w) ) ;
44- impl_common_vector_fns ! ( Vector4i , i32 ) ;
45- impl_swizzle_trait_for_vector4x ! ( Vector4i , i32 ) ;
4642
47- impl Vector4i {
48- /// Returns a `Vector4i` with the given components.
49- pub const fn new ( x : i32 , y : i32 , z : i32 , w : i32 ) -> Self {
50- Self { x, y, z, w }
51- }
52-
53- /// Axis of the vector's highest value. [`None`] if at least two components are equal.
54- pub fn max_axis ( self ) -> Option < Vector4Axis > {
55- use Vector4Axis :: * ;
56-
57- let mut max_axis = X ;
58- let mut previous = None ;
59- let mut max_value = self . x ;
60-
61- let components = [ ( Y , self . y ) , ( Z , self . z ) , ( W , self . w ) ] ;
62-
63- for ( axis, value) in components {
64- if value >= max_value {
65- max_axis = axis;
66- previous = Some ( max_value) ;
67- max_value = value;
68- }
69- }
70-
71- ( Some ( max_value) != previous) . then_some ( max_axis)
72- }
73-
74- /// Axis of the vector's highest value. [`None`] if at least two components are equal.
75- pub fn min_axis ( self ) -> Option < Vector4Axis > {
76- use Vector4Axis :: * ;
77-
78- let mut min_axis = X ;
79- let mut previous = None ;
80- let mut min_value = self . x ;
81-
82- let components = [ ( Y , self . y ) , ( Z , self . z ) , ( W , self . w ) ] ;
43+ impl_vector_consts ! ( Vector4i , i32 ) ;
44+ impl_integer_vector_consts ! ( Vector4i ) ;
8345
84- for ( axis, value) in components {
85- if value <= min_value {
86- min_axis = axis;
87- previous = Some ( min_value) ;
88- min_value = value;
89- }
90- }
91-
92- ( Some ( min_value) != previous) . then_some ( min_axis)
93- }
94-
95- /// Constructs a new `Vector4i` with all components set to `v`.
96- pub const fn splat ( v : i32 ) -> Self {
97- Self :: new ( v, v, v, v)
98- }
46+ impl_vector_fns ! ( Vector4i , glam:: IVec4 , i32 , ( x, y, z, w) ) ;
47+ impl_vector4x_fns ! ( Vector4i , i32 ) ;
9948
49+ impl Vector4i {
10050 /// Constructs a new `Vector4i` from a [`Vector4`]. The floating point coordinates will be
10151 /// truncated.
102- pub const fn from_vector3 ( v : Vector4 ) -> Self {
52+ #[ inline]
53+ pub const fn from_vector4 ( v : Vector4 ) -> Self {
10354 Self {
10455 x : v. x as i32 ,
10556 y : v. y as i32 ,
@@ -108,24 +59,9 @@ impl Vector4i {
10859 }
10960 }
11061
111- /// Zero vector, a vector with all components set to `0`.
112- pub const ZERO : Self = Self :: splat ( 0 ) ;
113-
114- /// One vector, a vector with all components set to `1`.
115- pub const ONE : Self = Self :: splat ( 1 ) ;
116-
117- /// Converts the corresponding `glam` type to `Self`.
118- fn from_glam ( v : glam:: IVec4 ) -> Self {
119- Self :: new ( v. x , v. y , v. z , v. w )
120- }
121-
122- /// Converts `self` to the corresponding `glam` type.
123- fn to_glam ( self ) -> glam:: IVec4 {
124- glam:: IVec4 :: new ( self . x , self . y , self . z , self . w )
125- }
126-
12762 /// Converts `self` to the corresponding [`real`] `glam` type.
128- fn to_glam_real ( self ) -> RVec4 {
63+ #[ inline]
64+ pub fn to_glam_real ( self ) -> RVec4 {
12965 RVec4 :: new (
13066 self . x as real ,
13167 self . y as real ,
@@ -134,8 +70,10 @@ impl Vector4i {
13470 )
13571 }
13672
137- pub fn coords ( & self ) -> ( i32 , i32 , i32 , i32 ) {
138- ( self . x , self . y , self . z , self . w )
73+ #[ doc( hidden) ]
74+ #[ inline]
75+ pub fn as_inner ( & self ) -> inner:: InnerVector4i {
76+ inner:: InnerVector4i :: from_outer ( self )
13977 }
14078}
14179
0 commit comments