8
8
use godot_ffi as sys;
9
9
use sys:: { ffi_methods, GodotFfi } ;
10
10
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 } ;
13
13
14
14
use std:: fmt;
15
15
@@ -39,67 +39,18 @@ pub struct Vector4i {
39
39
}
40
40
41
41
impl_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 ) ;
46
42
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 ) ;
83
45
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 ) ;
99
48
49
+ impl Vector4i {
100
50
/// Constructs a new `Vector4i` from a [`Vector4`]. The floating point coordinates will be
101
51
/// truncated.
102
- pub const fn from_vector3 ( v : Vector4 ) -> Self {
52
+ #[ inline]
53
+ pub const fn from_vector4 ( v : Vector4 ) -> Self {
103
54
Self {
104
55
x : v. x as i32 ,
105
56
y : v. y as i32 ,
@@ -108,24 +59,9 @@ impl Vector4i {
108
59
}
109
60
}
110
61
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
-
127
62
/// 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 {
129
65
RVec4 :: new (
130
66
self . x as real ,
131
67
self . y as real ,
@@ -134,8 +70,10 @@ impl Vector4i {
134
70
)
135
71
}
136
72
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 )
139
77
}
140
78
}
141
79
0 commit comments