@@ -289,10 +289,10 @@ macro_rules! impl_integer_vector_consts {
289289 $Vector: ty
290290 ) => {
291291 impl $Vector {
292- /// Min vector, a vector with all components equal to [`i32::MIN`]. Can be used as a negative integer equivalent of [`Vector2 ::INF`] .
292+ /// Min vector, a vector with all components equal to [`i32::MIN`]. Can be used as a negative integer equivalent of `real ::INF`.
293293 pub const MIN : Self = Self :: splat( i32 :: MIN ) ;
294294
295- /// Max vector, a vector with all components equal to [`i32::MAX`]. Can be used as an integer equivalent of [`Vector2 ::INF`] .
295+ /// Max vector, a vector with all components equal to [`i32::MAX`]. Can be used as an integer equivalent of `real ::INF`.
296296 pub const MAX : Self = Self :: splat( i32 :: MAX ) ;
297297 }
298298 } ;
@@ -402,8 +402,8 @@ macro_rules! impl_vector_fns {
402402
403403 /// Returns a new vector with all components clamped between the components of `min` and `max`.
404404 ///
405- /// Panics
406- /// Panics if `min` > `max`, `min` is NaN, or `max` is NaN.
405+ /// # Panics
406+ /// If `min` > `max`, `min` is NaN, or `max` is NaN.
407407 #[ inline]
408408 pub fn clamp( self , min: Self , max: Self ) -> Self {
409409 Self :: from_glam( self . to_glam( ) . clamp( min. to_glam( ) , max. to_glam( ) ) )
@@ -541,7 +541,8 @@ macro_rules! impl_float_vector_fns {
541541 }
542542
543543 /// Returns `true` if this vector's values are approximately zero.
544- /// This method is faster than using [`Self::is_equal_approx`] with one value as a zero vector.
544+ ///
545+ /// This method is faster than using `approx_eq()` with one value as a zero vector.
545546 #[ inline]
546547 pub fn is_zero_approx( self ) -> bool {
547548 $( self . $comp. is_zero_approx( ) ) &&*
@@ -559,19 +560,14 @@ macro_rules! impl_float_vector_fns {
559560 /// Returns the vector scaled to unit length. Equivalent to `self / self.length()`. See
560561 /// also `is_normalized()`.
561562 ///
562- /// If the vector is zero, the result is also zero.
563+ /// # Panics
564+ /// If called on a zero vector.
563565 #[ inline]
564566 pub fn normalized( self ) -> Self {
565- // Copy Godot's implementation since it's faster than using glam's normalize_or_zero().
566- if self == Self :: ZERO {
567- return self ;
568- }
567+ assert_ne!( self , Self :: ZERO , "normalized() called on zero vector!" ) ;
569568
570- let l = self . length( ) ;
571-
572- Self :: new(
573- $( self . $comp / l ) ,*
574- )
569+ // Copy Godot's implementation since it's faster than using glam's normalize_or_zero().
570+ self / self . length( )
575571 }
576572
577573 /// Returns a vector composed of the [`FloatExt::fposmod`] of this vector's components and `pmod`.
@@ -612,7 +608,7 @@ macro_rules! impl_float_vector_fns {
612608 impl $crate:: builtin:: math:: ApproxEq for $Vector {
613609 /// Returns `true` if this vector and `to` are approximately equal.
614610 #[ inline]
615- #[ doc( alias = "is_approx_eq " ) ]
611+ #[ doc( alias = "is_equal_approx " ) ]
616612 fn approx_eq( & self , other: & Self ) -> bool {
617613 $( self . $comp. approx_eq( & other. $comp) ) &&*
618614 }
@@ -857,9 +853,13 @@ macro_rules! impl_vector2_vector3_fns {
857853 }
858854
859855 /// Returns a new vector "bounced off" from a plane defined by the given normal.
856+ ///
857+ /// # Panics
858+ /// If `n` is not normalized.
860859 #[ inline]
861- pub fn bounce( self , normal: Self ) -> Self {
862- -self . reflect( normal)
860+ pub fn bounce( self , n: Self ) -> Self {
861+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
862+ -self . reflect( n)
863863 }
864864
865865 /// Returns the vector with a maximum length by limiting its length to `length`.
@@ -884,14 +884,22 @@ macro_rules! impl_vector2_vector3_fns {
884884 }
885885
886886 /// Returns the result of reflecting the vector defined by the given direction vector `n`.
887+ ///
888+ /// # Panics
889+ /// If `n` is not normalized.
887890 #[ inline]
888891 pub fn reflect( self , n: Self ) -> Self {
892+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
889893 2.0 * n * self . dot( n) - self
890894 }
891895
892896 /// Returns a new vector slid along a plane defined by the given normal.
897+ ///
898+ /// # Panics
899+ /// If `n` is not normalized.
893900 #[ inline]
894901 pub fn slide( self , n: Self ) -> Self {
902+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
895903 self - n * self . dot( n)
896904 }
897905 }
0 commit comments