@@ -532,6 +532,8 @@ pub(super) fn snap_one(mut value: i32, step: i32) -> i32 {
532
532
/// Implements functions that are present only on integer vectors.
533
533
macro_rules! inline_impl_integer_vector_fns {
534
534
(
535
+ // Name of the float-equivalent vector type.
536
+ $VectorFloat: ty,
535
537
// Names of the components, for example `x, y`.
536
538
$( $comp: ident) ,*
537
539
) => {
@@ -542,6 +544,7 @@ macro_rules! inline_impl_integer_vector_fns {
542
544
/// On under- or overflow:
543
545
/// - If any component of `self` is [`i32::MIN`] while the same component on `step` is `-1`.
544
546
/// - If any component of `self` plus half of the same component of `step` is not in range on [`i32`].
547
+ #[ inline]
545
548
pub fn snapped( self , step: Self ) -> Self {
546
549
use crate :: builtin:: vectors:: vector_macros:: snap_one;
547
550
@@ -551,20 +554,39 @@ macro_rules! inline_impl_integer_vector_fns {
551
554
) ,*
552
555
)
553
556
}
557
+
558
+ /// Converts to a vector with floating-point [`real`](type.real.html) components, using `as` casts.
559
+ #[ inline]
560
+ pub const fn cast_float( self ) -> $VectorFloat {
561
+ <$VectorFloat>:: new( $( self . $comp as real) ,* )
562
+ }
554
563
} ;
555
564
}
556
565
557
566
macro_rules! impl_float_vector_fns {
558
567
(
559
568
// Name of the vector type.
560
569
$Vector: ty,
570
+ // Name of the integer-equivalent vector type.
571
+ $VectorInt: ty,
561
572
// Names of the components, with parentheses, for example `(x, y)`.
562
573
( $( $comp: ident) ,* )
563
574
) => {
564
575
/// # Float-specific functions
565
576
///
566
577
/// The following methods are only available on floating-point vectors.
567
578
impl $Vector {
579
+ /// Converts to a vector with integer components, using `as` casts.
580
+ pub const fn cast_int( self ) -> $VectorInt {
581
+ <$VectorInt>:: new( $( self . $comp as i32 ) ,* )
582
+ }
583
+
584
+ /// Returns a new vector with all components rounded down (towards negative infinity).
585
+ #[ inline]
586
+ pub fn floor( self ) -> Self {
587
+ Self :: from_glam( self . to_glam( ) . floor( ) )
588
+ }
589
+
568
590
/// Returns a new vector with all components rounded up (towards positive infinity).
569
591
#[ inline]
570
592
pub fn ceil( self ) -> Self {
@@ -649,12 +671,6 @@ macro_rules! impl_float_vector_fns {
649
671
self . to_glam( ) . dot( with. to_glam( ) )
650
672
}
651
673
652
- /// Returns a new vector with all components rounded down (towards negative infinity).
653
- #[ inline]
654
- pub fn floor( self ) -> Self {
655
- Self :: from_glam( self . to_glam( ) . floor( ) )
656
- }
657
-
658
674
/// Returns true if each component of this vector is finite.
659
675
#[ inline]
660
676
pub fn is_finite( self ) -> bool {
0 commit comments