@@ -289,10 +289,10 @@ macro_rules! impl_integer_vector_consts {
289
289
$Vector: ty
290
290
) => {
291
291
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`.
293
293
pub const MIN : Self = Self :: splat( i32 :: MIN ) ;
294
294
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`.
296
296
pub const MAX : Self = Self :: splat( i32 :: MAX ) ;
297
297
}
298
298
} ;
@@ -402,8 +402,8 @@ macro_rules! impl_vector_fns {
402
402
403
403
/// Returns a new vector with all components clamped between the components of `min` and `max`.
404
404
///
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.
407
407
#[ inline]
408
408
pub fn clamp( self , min: Self , max: Self ) -> Self {
409
409
Self :: from_glam( self . to_glam( ) . clamp( min. to_glam( ) , max. to_glam( ) ) )
@@ -462,7 +462,9 @@ macro_rules! impl_float_vector_fns {
462
462
}
463
463
464
464
/// 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.
466
468
#[ inline]
467
469
pub fn cubic_interpolate( self , b: Self , pre_a: Self , post_b: Self , weight: real) -> Self {
468
470
Self :: new(
@@ -473,7 +475,9 @@ macro_rules! impl_float_vector_fns {
473
475
}
474
476
475
477
/// 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.
477
481
/// It can perform smoother interpolation than [`Self::cubic_interpolate`] by the time values.
478
482
#[ inline]
479
483
#[ allow( clippy:: too_many_arguments) ]
@@ -496,7 +500,9 @@ macro_rules! impl_float_vector_fns {
496
500
)
497
501
}
498
502
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()`.
500
506
#[ inline]
501
507
pub fn direction_to( self , to: Self ) -> Self {
502
508
( to - self ) . normalized( )
@@ -541,13 +547,15 @@ macro_rules! impl_float_vector_fns {
541
547
}
542
548
543
549
/// 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.
545
552
#[ inline]
546
553
pub fn is_zero_approx( self ) -> bool {
547
554
$( self . $comp. is_zero_approx( ) ) &&*
548
555
}
549
556
550
557
/// Returns the result of the linear interpolation between this vector and `to` by amount `weight`.
558
+ ///
551
559
/// `weight` is on the range of `0.0` to `1.0`, representing the amount of interpolation.
552
560
#[ inline]
553
561
pub fn lerp( self , other: Self , weight: real) -> Self {
@@ -559,19 +567,14 @@ macro_rules! impl_float_vector_fns {
559
567
/// Returns the vector scaled to unit length. Equivalent to `self / self.length()`. See
560
568
/// also `is_normalized()`.
561
569
///
562
- /// If the vector is zero, the result is also zero.
570
+ /// # Panics
571
+ /// If called on a zero vector.
563
572
#[ inline]
564
573
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" ) ;
571
575
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( )
575
578
}
576
579
577
580
/// 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 {
612
615
impl $crate:: builtin:: math:: ApproxEq for $Vector {
613
616
/// Returns `true` if this vector and `to` are approximately equal.
614
617
#[ inline]
615
- #[ doc( alias = "is_approx_eq " ) ]
618
+ #[ doc( alias = "is_equal_approx " ) ]
616
619
fn approx_eq( & self , other: & Self ) -> bool {
617
620
$( self . $comp. approx_eq( & other. $comp) ) &&*
618
621
}
@@ -857,9 +860,13 @@ macro_rules! impl_vector2_vector3_fns {
857
860
}
858
861
859
862
/// Returns a new vector "bounced off" from a plane defined by the given normal.
863
+ ///
864
+ /// # Panics
865
+ /// If `n` is not normalized.
860
866
#[ 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)
863
870
}
864
871
865
872
/// Returns the vector with a maximum length by limiting its length to `length`.
@@ -884,14 +891,22 @@ macro_rules! impl_vector2_vector3_fns {
884
891
}
885
892
886
893
/// Returns the result of reflecting the vector defined by the given direction vector `n`.
894
+ ///
895
+ /// # Panics
896
+ /// If `n` is not normalized.
887
897
#[ inline]
888
898
pub fn reflect( self , n: Self ) -> Self {
899
+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
889
900
2.0 * n * self . dot( n) - self
890
901
}
891
902
892
903
/// Returns a new vector slid along a plane defined by the given normal.
904
+ ///
905
+ /// # Panics
906
+ /// If `n` is not normalized.
893
907
#[ inline]
894
908
pub fn slide( self , n: Self ) -> Self {
909
+ assert!( n. is_normalized( ) , "n is not normalized!" ) ;
895
910
self - n * self . dot( n)
896
911
}
897
912
}
@@ -911,9 +926,7 @@ macro_rules! impl_vector3_vector4_fns {
911
926
#[ inline]
912
927
#[ doc( alias = "inverse" ) ]
913
928
pub fn recip( self ) -> Self {
914
- Self :: new(
915
- $( 1.0 / self . $comp ) ,*
916
- )
929
+ Self :: from_glam( self . to_glam( ) . recip( ) )
917
930
}
918
931
}
919
932
} ;
0 commit comments