@@ -538,6 +538,56 @@ macro_rules! inline_impl_integer_vector_fns {
538538 // Names of the components, for example `x, y`.
539539 $( $comp: ident) ,*
540540 ) => {
541+ /// Returns the distance between this vector and `to`.
542+ ///
543+ /// Where possible, prefer [`distance_squared_to()`][Self::distance_squared_to] for precision and performance.
544+ #[ inline]
545+ pub fn distance_to( self , to: Self ) -> real {
546+ ( to - self ) . length( )
547+ }
548+
549+ /// Returns the squared distance between this vector and `to`.
550+ ///
551+ /// Faster than [`distance_to()`][Self::distance_to], so prefer it if you need to compare distances, or need the squared distance
552+ /// in a formula.
553+ #[ inline]
554+ pub fn distance_squared_to( self , to: Self ) -> i32 {
555+ ( to - self ) . length_squared( ) as i32
556+ }
557+
558+ /// Returns `self` with each component limited to a range defined by `min` and `max`.
559+ ///
560+ /// # Panics
561+ /// If `min > max` on any axis.
562+ #[ inline]
563+ pub fn clampi( self , min: i32 , max: i32 ) -> Self {
564+ Self :: new(
565+ $(
566+ self . $comp. clamp( min, max)
567+ ) ,*
568+ )
569+ }
570+
571+ /// Returns a new vector with each component set to the minimum of `self` and `with`.
572+ #[ inline]
573+ pub fn mini( self , with: i32 ) -> Self {
574+ Self :: new(
575+ $(
576+ self . $comp. min( with)
577+ ) ,*
578+ )
579+ }
580+
581+ /// Returns a new vector with each component set to the maximum of `self` and `with`.
582+ #[ inline]
583+ pub fn maxi( self , with: i32 ) -> Self {
584+ Self :: new(
585+ $(
586+ self . $comp. max( with)
587+ ) ,*
588+ )
589+ }
590+
541591 /// A new vector with each component snapped to the closest multiple of the corresponding
542592 /// component in `step`.
543593 ///
@@ -556,6 +606,15 @@ macro_rules! inline_impl_integer_vector_fns {
556606 )
557607 }
558608
609+ /// A new vector with each component snapped to the closest multiple of `step`.
610+ ///
611+ /// # Panics
612+ /// On under- or overflow (see [`snapped()`][Self::snapped] for details).
613+ #[ inline]
614+ pub fn snappedi( self , step: i32 ) -> Self {
615+ self . snapped( Self :: splat( step) )
616+ }
617+
559618 /// Converts to a vector with floating-point [`real`](type.real.html) components, using `as` casts.
560619 #[ inline]
561620 pub const fn cast_float( self ) -> $VectorFloat {
@@ -654,13 +713,16 @@ macro_rules! impl_float_vector_fns {
654713
655714 /// Returns the squared distance between this vector and `to`.
656715 ///
657- /// This method runs faster than [`Self::distance_to`], so prefer it if you need to compare vectors or need the squared distance for some formula.
716+ /// Faster than [`distance_to()`][Self::distance_to], so prefer it if you need to compare distances, or need the squared distance
717+ /// in a formula.
658718 #[ inline]
659719 pub fn distance_squared_to( self , to: Self ) -> real {
660720 ( to - self ) . length_squared( )
661721 }
662722
663723 /// Returns the distance between this vector and `to`.
724+ ///
725+ /// Where possible, prefer [`distance_squared_to()`][Self::distance_squared_to] for performance reasons.
664726 #[ inline]
665727 pub fn distance_to( self , to: Self ) -> real {
666728 ( to - self ) . length( )
0 commit comments