66 */
77
88use godot_ffi as sys;
9- use std:: cmp:: Ordering ;
109use sys:: { ffi_methods, GodotFfi } ;
1110
1211use crate :: builtin:: math:: { FloatExt , GlamConv , GlamType } ;
1312use crate :: builtin:: meta:: impl_godot_as_self;
14- use crate :: builtin:: { real, RVec2 , Vector2 , Vector2Axis } ;
13+ use crate :: builtin:: { real, RVec2 , Vector2 } ;
1514
1615use std:: fmt;
1716
@@ -35,58 +34,21 @@ pub struct Vector2i {
3534 pub y : i32 ,
3635}
3736
38- impl Vector2i {
39- /// Vector with all components set to `0`.
40- pub const ZERO : Self = Self :: splat ( 0 ) ;
41-
42- /// Vector with all components set to `1`.
43- pub const ONE : Self = Self :: splat ( 1 ) ;
44-
45- /// Unit vector in -X direction (right in 2D coordinate system).
46- pub const LEFT : Self = Self :: new ( -1 , 0 ) ;
47-
48- /// Unit vector in +X direction (right in 2D coordinate system).
49- pub const RIGHT : Self = Self :: new ( 1 , 0 ) ;
50-
51- /// Unit vector in -Y direction (up in 2D coordinate system).
52- pub const UP : Self = Self :: new ( 0 , -1 ) ;
53-
54- /// Unit vector in +Y direction (down in 2D coordinate system).
55- pub const DOWN : Self = Self :: new ( 0 , 1 ) ;
56-
57- /// Constructs a new `Vector2i` from the given `x` and `y`.
58- pub const fn new ( x : i32 , y : i32 ) -> Self {
59- Self { x, y }
60- }
61-
62- /// Aspect ratio: x / y, as a `real` value.
63- pub fn aspect ( self ) -> real {
64- self . x as real / self . y as real
65- }
37+ impl_vector_operators ! ( Vector2i , i32 , ( x, y) ) ;
6638
67- /// Axis of the vector's highest value. [`None`] if components are equal.
68- pub fn max_axis ( self ) -> Option < Vector2Axis > {
69- match self . x . cmp ( & self . y ) {
70- Ordering :: Less => Some ( Vector2Axis :: Y ) ,
71- Ordering :: Equal => None ,
72- Ordering :: Greater => Some ( Vector2Axis :: X ) ,
73- }
74- }
39+ impl_vector_consts ! ( Vector2i , i32 ) ;
40+ impl_integer_vector_consts ! ( Vector2i ) ;
41+ impl_vector2x_consts ! ( Vector2i , i32 ) ;
7542
76- /// Axis of the vector's highest value. [`None`] if components are equal.
77- pub fn min_axis ( self ) -> Option < Vector2Axis > {
78- match self . x . cmp ( & self . y ) {
79- Ordering :: Less => Some ( Vector2Axis :: X ) ,
80- Ordering :: Equal => None ,
81- Ordering :: Greater => Some ( Vector2Axis :: Y ) ,
82- }
83- }
43+ impl_vector_fns ! ( Vector2i , i32 , ( x, y) ) ;
44+ impl_vector2x_fns ! ( Vector2i , i32 ) ;
8445
85- /// Constructs a new `Vector2i` with both components set to `v`.
86- pub const fn splat ( v : i32 ) -> Self {
87- Self :: new ( v, v)
88- }
46+ // TODO: remove old impls
47+ impl_integer_vector_glam_fns ! ( Vector2i , real) ;
48+ impl_integer_vector_component_fns ! ( Vector2i , real, ( x, y) ) ;
8949
50+ // TODO: remove old impls
51+ impl Vector2i {
9052 /// Constructs a new `Vector2i` from a [`Vector2`]. The floating point coordinates will be truncated.
9153 pub const fn from_vector2 ( v : Vector2 ) -> Self {
9254 Self {
@@ -122,12 +84,6 @@ impl fmt::Display for Vector2i {
12284 }
12385}
12486
125- impl_common_vector_fns ! ( Vector2i , i32 ) ;
126- impl_integer_vector_glam_fns ! ( Vector2i , real) ;
127- impl_integer_vector_component_fns ! ( Vector2i , real, ( x, y) ) ;
128- impl_vector_operators ! ( Vector2i , i32 , ( x, y) ) ;
129- impl_from_tuple_for_vector2x ! ( Vector2i , i32 ) ;
130-
13187// SAFETY:
13288// This type is represented as `Self` in Godot, so `*mut Self` is sound.
13389unsafe impl GodotFfi for Vector2i {
@@ -158,6 +114,8 @@ impl GlamConv for Vector2i {
158114
159115#[ cfg( test) ]
160116mod test {
117+ use crate :: builtin:: Vector2Axis ;
118+
161119 use super :: * ;
162120
163121 #[ test]
@@ -179,13 +137,13 @@ mod test {
179137
180138 #[ test]
181139 fn axis_min_max ( ) {
182- assert_eq ! ( Vector2i :: new( 10 , 5 ) . max_axis( ) , Some ( Vector2Axis :: X ) ) ;
183- assert_eq ! ( Vector2i :: new( 5 , 10 ) . max_axis( ) , Some ( Vector2Axis :: Y ) ) ;
140+ assert_eq ! ( Vector2i :: new( 10 , 5 ) . max_axis( ) , Vector2Axis :: X ) ;
141+ assert_eq ! ( Vector2i :: new( 5 , 10 ) . max_axis( ) , Vector2Axis :: Y ) ;
184142
185- assert_eq ! ( Vector2i :: new( -5 , 5 ) . min_axis( ) , Some ( Vector2Axis :: X ) ) ;
186- assert_eq ! ( Vector2i :: new( 5 , -5 ) . min_axis( ) , Some ( Vector2Axis :: Y ) ) ;
143+ assert_eq ! ( Vector2i :: new( -5 , 5 ) . min_axis( ) , Vector2Axis :: X ) ;
144+ assert_eq ! ( Vector2i :: new( 5 , -5 ) . min_axis( ) , Vector2Axis :: Y ) ;
187145
188- assert_eq ! ( Vector2i :: new( 15 , 15 ) . max_axis( ) , None ) ;
189- assert_eq ! ( Vector2i :: new( 15 , 15 ) . min_axis( ) , None ) ;
146+ assert_eq ! ( Vector2i :: new( 15 , 15 ) . max_axis( ) , Vector2Axis :: X ) ;
147+ assert_eq ! ( Vector2i :: new( 15 , 15 ) . min_axis( ) , Vector2Axis :: Y ) ;
190148 }
191149}
0 commit comments