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