@@ -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( ) ) )
@@ -462,7 +462,9 @@ macro_rules! impl_float_vector_fns {
462462 }
463463
464464 /// Performs a cubic interpolation between this vector and `b` using `pre_a` and `post_b` as handles,
465- /// and returns the result at position `weight`. `weight` is on the range of 0.0 to 1.0, representing the amount of interpolation.
465+ /// and returns the result at position `weight`.
466+ ///
467+ /// `weight` is on the range of 0.0 to 1.0, representing the amount of interpolation.
466468 #[ inline]
467469 pub fn cubic_interpolate( self , b: Self , pre_a: Self , post_b: Self , weight: real) -> Self {
468470 Self :: new(
@@ -473,7 +475,9 @@ macro_rules! impl_float_vector_fns {
473475 }
474476
475477 /// Performs a cubic interpolation between this vector and `b` using `pre_a` and `post_b` as handles,
476- /// and returns the result at position `weight`. `weight` is on the range of 0.0 to 1.0, representing the amount of interpolation.
478+ /// and returns the result at position `weight`.
479+ ///
480+ /// `weight` is on the range of 0.0 to 1.0, representing the amount of interpolation.
477481 /// It can perform smoother interpolation than [`Self::cubic_interpolate`] by the time values.
478482 #[ inline]
479483 #[ allow( clippy:: too_many_arguments) ]
@@ -496,7 +500,9 @@ macro_rules! impl_float_vector_fns {
496500 )
497501 }
498502
499- /// Returns the normalized vector pointing from this vector to `to`. This is equivalent to using `(b - a).normalized()`.
503+ /// Returns the normalized vector pointing from this vector to `to`.
504+ ///
505+ /// This is equivalent to using `(b - a).normalized()`.
500506 #[ inline]
501507 pub fn direction_to( self , to: Self ) -> Self {
502508 ( to - self ) . normalized( )
@@ -541,13 +547,15 @@ macro_rules! impl_float_vector_fns {
541547 }
542548
543549 /// 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.
550+ ///
551+ /// This method is faster than using `approx_eq()` with one value as a zero vector.
545552 #[ inline]
546553 pub fn is_zero_approx( self ) -> bool {
547554 $( self . $comp. is_zero_approx( ) ) &&*
548555 }
549556
550557 /// Returns the result of the linear interpolation between this vector and `to` by amount `weight`.
558+ ///
551559 /// `weight` is on the range of `0.0` to `1.0`, representing the amount of interpolation.
552560 #[ inline]
553561 pub fn lerp( self , other: Self , weight: real) -> Self {
@@ -559,19 +567,14 @@ macro_rules! impl_float_vector_fns {
559567 /// Returns the vector scaled to unit length. Equivalent to `self / self.length()`. See
560568 /// also `is_normalized()`.
561569 ///
562- /// If the vector is zero, the result is also zero.
570+ /// # Panics
571+ /// If called on a zero vector.
563572 #[ inline]
564573 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- }
569-
570- let l = self . length( ) ;
574+ assert_ne!( self , Self :: ZERO , "normalized() called on zero vector" ) ;
571575
572- Self :: new(
573- $( self . $comp / l ) ,*
574- )
576+ // Copy Godot's implementation since it's faster than using glam's normalize_or_zero().
577+ self / self . length( )
575578 }
576579
577580 /// Returns a vector composed of the [`FloatExt::fposmod`] of this vector's components and `pmod`.
@@ -612,7 +615,7 @@ macro_rules! impl_float_vector_fns {
612615 impl $crate:: builtin:: math:: ApproxEq for $Vector {
613616 /// Returns `true` if this vector and `to` are approximately equal.
614617 #[ inline]
615- #[ doc( alias = "is_approx_eq " ) ]
618+ #[ doc( alias = "is_equal_approx " ) ]
616619 fn approx_eq( & self , other: & Self ) -> bool {
617620 $( self . $comp. approx_eq( & other. $comp) ) &&*
618621 }
@@ -857,9 +860,13 @@ macro_rules! impl_vector2_vector3_fns {
857860 }
858861
859862 /// Returns a new vector "bounced off" from a plane defined by the given normal.
863+ ///
864+ /// # Panics
865+ /// If `n` is not normalized.
860866 #[ inline]
861- pub fn bounce( self , normal: Self ) -> Self {
862- -self . reflect( normal)
867+ pub fn bounce( self , n: Self ) -> Self {
868+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
869+ -self . reflect( n)
863870 }
864871
865872 /// Returns the vector with a maximum length by limiting its length to `length`.
@@ -884,14 +891,22 @@ macro_rules! impl_vector2_vector3_fns {
884891 }
885892
886893 /// Returns the result of reflecting the vector defined by the given direction vector `n`.
894+ ///
895+ /// # Panics
896+ /// If `n` is not normalized.
887897 #[ inline]
888898 pub fn reflect( self , n: Self ) -> Self {
899+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
889900 2.0 * n * self . dot( n) - self
890901 }
891902
892903 /// Returns a new vector slid along a plane defined by the given normal.
904+ ///
905+ /// # Panics
906+ /// If `n` is not normalized.
893907 #[ inline]
894908 pub fn slide( self , n: Self ) -> Self {
909+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
895910 self - n * self . dot( n)
896911 }
897912 }
@@ -911,9 +926,7 @@ macro_rules! impl_vector3_vector4_fns {
911926 #[ inline]
912927 #[ doc( alias = "inverse" ) ]
913928 pub fn recip( self ) -> Self {
914- Self :: new(
915- $( 1.0 / self . $comp ) ,*
916- )
929+ Self :: from_glam( self . to_glam( ) . recip( ) )
917930 }
918931 }
919932 } ;
0 commit comments