File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
godot-core/src/builtin/vectors Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ impl GlamConv for Vector2i {
124124#[ cfg( test) ]
125125mod test {
126126 use super :: * ;
127+ use crate :: assert_eq_approx;
127128
128129 #[ test]
129130 fn coord_min_max ( ) {
@@ -161,4 +162,29 @@ mod test {
161162 assert_eq ! ( Vector2i :: new( 15 , 15 ) . max_axis( ) , None ) ;
162163 assert_eq ! ( Vector2i :: new( 15 , 15 ) . min_axis( ) , None ) ;
163164 }
165+
166+ #[ test]
167+ fn distance ( ) {
168+ let a = Vector2i :: new ( 1 , 2 ) ;
169+ let b = Vector2i :: new ( 4 , 6 ) ;
170+
171+ assert_eq ! ( a. distance_squared_to( b) , 25 ) ;
172+ assert_eq_approx ! ( a. distance_to( b) , 5.0 ) ;
173+ }
174+
175+ #[ test]
176+ fn mini_maxi_clampi ( ) {
177+ let v = Vector2i :: new ( 10 , -5 ) ;
178+
179+ assert_eq ! ( v. mini( 3 ) , Vector2i :: new( 3 , -5 ) ) ;
180+ assert_eq ! ( v. maxi( -2 ) , Vector2i :: new( 10 , -2 ) ) ;
181+ assert_eq ! ( v. clampi( -3 , 7 ) , Vector2i :: new( 7 , -3 ) ) ;
182+ }
183+
184+ #[ test]
185+ fn snappedi ( ) {
186+ let v = Vector2i :: new ( 13 , -8 ) ;
187+
188+ assert_eq ! ( v. snappedi( 5 ) , Vector2i :: new( 15 , -10 ) ) ;
189+ }
164190}
You can’t perform that action at this time.
0 commit comments