From 6a1e62d87205daf07c21b17531af490a528b415c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Tue, 5 Nov 2024 00:35:31 +0000 Subject: [PATCH] Fix VecN::write_to_slice Fix regression introduced in #571. `VecN::write_to_slice` expects the slice length to be >= dim, not == dim. `slice::copy_from_slice` expects both slices to have the same length. --- codegen/templates/vec.rs.tera | 2 +- src/f32/coresimd/vec3a.rs | 2 +- src/f32/coresimd/vec4.rs | 2 +- src/f32/neon/vec3a.rs | 2 +- src/f32/scalar/vec3a.rs | 2 +- src/f32/scalar/vec4.rs | 2 +- src/f32/sse2/vec3a.rs | 2 +- src/f32/vec2.rs | 2 +- src/f32/vec3.rs | 2 +- src/f32/wasm32/vec3a.rs | 2 +- src/f32/wasm32/vec4.rs | 2 +- src/f64/dvec2.rs | 2 +- src/f64/dvec3.rs | 2 +- src/f64/dvec4.rs | 2 +- src/i16/i16vec2.rs | 2 +- src/i16/i16vec3.rs | 2 +- src/i16/i16vec4.rs | 2 +- src/i32/ivec2.rs | 2 +- src/i32/ivec3.rs | 2 +- src/i32/ivec4.rs | 2 +- src/i64/i64vec2.rs | 2 +- src/i64/i64vec3.rs | 2 +- src/i64/i64vec4.rs | 2 +- src/i8/i8vec2.rs | 2 +- src/i8/i8vec3.rs | 2 +- src/i8/i8vec4.rs | 2 +- src/u16/u16vec2.rs | 2 +- src/u16/u16vec3.rs | 2 +- src/u16/u16vec4.rs | 2 +- src/u32/uvec2.rs | 2 +- src/u32/uvec3.rs | 2 +- src/u32/uvec4.rs | 2 +- src/u64/u64vec2.rs | 2 +- src/u64/u64vec3.rs | 2 +- src/u64/u64vec4.rs | 2 +- src/u8/u8vec2.rs | 2 +- src/u8/u8vec3.rs | 2 +- src/u8/u8vec4.rs | 2 +- tests/vec2.rs | 5 +++++ tests/vec3.rs | 5 +++++ tests/vec4.rs | 5 +++++ 41 files changed, 53 insertions(+), 38 deletions(-) diff --git a/codegen/templates/vec.rs.tera b/codegen/templates/vec.rs.tera index 356f717f..7859070c 100644 --- a/codegen/templates/vec.rs.tera +++ b/codegen/templates/vec.rs.tera @@ -529,7 +529,7 @@ impl {{ self_t }} { assert!(slice.len() >= 4); unsafe { vst1q_f32(slice.as_mut_ptr(), self.0); } {% else %} - slice.copy_from_slice(&self.to_array()); + slice[..{{ dim }}].copy_from_slice(&self.to_array()); {% endif %} } diff --git a/src/f32/coresimd/vec3a.rs b/src/f32/coresimd/vec3a.rs index ce905f2b..3601af8b 100644 --- a/src/f32/coresimd/vec3a.rs +++ b/src/f32/coresimd/vec3a.rs @@ -143,7 +143,7 @@ impl Vec3A { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. diff --git a/src/f32/coresimd/vec4.rs b/src/f32/coresimd/vec4.rs index 46252b92..824dc826 100644 --- a/src/f32/coresimd/vec4.rs +++ b/src/f32/coresimd/vec4.rs @@ -145,7 +145,7 @@ impl Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/f32/neon/vec3a.rs b/src/f32/neon/vec3a.rs index cdf77beb..fe08d2e0 100644 --- a/src/f32/neon/vec3a.rs +++ b/src/f32/neon/vec3a.rs @@ -148,7 +148,7 @@ impl Vec3A { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. diff --git a/src/f32/scalar/vec3a.rs b/src/f32/scalar/vec3a.rs index 5dfd0fab..4c1c0ce8 100644 --- a/src/f32/scalar/vec3a.rs +++ b/src/f32/scalar/vec3a.rs @@ -150,7 +150,7 @@ impl Vec3A { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. diff --git a/src/f32/scalar/vec4.rs b/src/f32/scalar/vec4.rs index 467fd5aa..bd414481 100644 --- a/src/f32/scalar/vec4.rs +++ b/src/f32/scalar/vec4.rs @@ -169,7 +169,7 @@ impl Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/f32/sse2/vec3a.rs b/src/f32/sse2/vec3a.rs index 2bbe2979..e9b5e47e 100644 --- a/src/f32/sse2/vec3a.rs +++ b/src/f32/sse2/vec3a.rs @@ -156,7 +156,7 @@ impl Vec3A { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. diff --git a/src/f32/vec2.rs b/src/f32/vec2.rs index e9d639f0..f4b7fdf8 100644 --- a/src/f32/vec2.rs +++ b/src/f32/vec2.rs @@ -134,7 +134,7 @@ impl Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/f32/vec3.rs b/src/f32/vec3.rs index 91da1999..f475e1eb 100644 --- a/src/f32/vec3.rs +++ b/src/f32/vec3.rs @@ -141,7 +141,7 @@ impl Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/f32/wasm32/vec3a.rs b/src/f32/wasm32/vec3a.rs index 24ea2009..b1d6b903 100644 --- a/src/f32/wasm32/vec3a.rs +++ b/src/f32/wasm32/vec3a.rs @@ -142,7 +142,7 @@ impl Vec3A { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Creates a [`Vec3A`] from the `x`, `y` and `z` elements of `self` discarding `w`. diff --git a/src/f32/wasm32/vec4.rs b/src/f32/wasm32/vec4.rs index 6fa506ce..cb1d90b6 100644 --- a/src/f32/wasm32/vec4.rs +++ b/src/f32/wasm32/vec4.rs @@ -144,7 +144,7 @@ impl Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f32]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/f64/dvec2.rs b/src/f64/dvec2.rs index 7cb40296..bdd615c0 100644 --- a/src/f64/dvec2.rs +++ b/src/f64/dvec2.rs @@ -134,7 +134,7 @@ impl DVec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f64]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/f64/dvec3.rs b/src/f64/dvec3.rs index 0b32b30d..5a67ca06 100644 --- a/src/f64/dvec3.rs +++ b/src/f64/dvec3.rs @@ -141,7 +141,7 @@ impl DVec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f64]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/f64/dvec4.rs b/src/f64/dvec4.rs index 79d2026f..f13647a1 100644 --- a/src/f64/dvec4.rs +++ b/src/f64/dvec4.rs @@ -160,7 +160,7 @@ impl DVec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [f64]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/i16/i16vec2.rs b/src/i16/i16vec2.rs index ea4c2938..dc6d6ade 100644 --- a/src/i16/i16vec2.rs +++ b/src/i16/i16vec2.rs @@ -126,7 +126,7 @@ impl I16Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i16]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/i16/i16vec3.rs b/src/i16/i16vec3.rs index bad1489d..0168311a 100644 --- a/src/i16/i16vec3.rs +++ b/src/i16/i16vec3.rs @@ -135,7 +135,7 @@ impl I16Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i16]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/i16/i16vec4.rs b/src/i16/i16vec4.rs index 7dd3347c..b82ef789 100644 --- a/src/i16/i16vec4.rs +++ b/src/i16/i16vec4.rs @@ -152,7 +152,7 @@ impl I16Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i16]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/i32/ivec2.rs b/src/i32/ivec2.rs index 34ab5bb1..f220d1d7 100644 --- a/src/i32/ivec2.rs +++ b/src/i32/ivec2.rs @@ -126,7 +126,7 @@ impl IVec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i32]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/i32/ivec3.rs b/src/i32/ivec3.rs index 5a251619..bc15b11f 100644 --- a/src/i32/ivec3.rs +++ b/src/i32/ivec3.rs @@ -135,7 +135,7 @@ impl IVec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/i32/ivec4.rs b/src/i32/ivec4.rs index 8de67435..eef4c8d7 100644 --- a/src/i32/ivec4.rs +++ b/src/i32/ivec4.rs @@ -152,7 +152,7 @@ impl IVec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i32]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/i64/i64vec2.rs b/src/i64/i64vec2.rs index ce7af5bb..0873aa31 100644 --- a/src/i64/i64vec2.rs +++ b/src/i64/i64vec2.rs @@ -126,7 +126,7 @@ impl I64Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i64]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/i64/i64vec3.rs b/src/i64/i64vec3.rs index d01f0c0f..5f42aee2 100644 --- a/src/i64/i64vec3.rs +++ b/src/i64/i64vec3.rs @@ -135,7 +135,7 @@ impl I64Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i64]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/i64/i64vec4.rs b/src/i64/i64vec4.rs index 62ede4a2..667756a9 100644 --- a/src/i64/i64vec4.rs +++ b/src/i64/i64vec4.rs @@ -152,7 +152,7 @@ impl I64Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i64]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/i8/i8vec2.rs b/src/i8/i8vec2.rs index 194e9293..ee75627e 100644 --- a/src/i8/i8vec2.rs +++ b/src/i8/i8vec2.rs @@ -126,7 +126,7 @@ impl I8Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i8]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/i8/i8vec3.rs b/src/i8/i8vec3.rs index 8678fd5e..6609475d 100644 --- a/src/i8/i8vec3.rs +++ b/src/i8/i8vec3.rs @@ -135,7 +135,7 @@ impl I8Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i8]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/i8/i8vec4.rs b/src/i8/i8vec4.rs index 1cb36dbd..e1e797d5 100644 --- a/src/i8/i8vec4.rs +++ b/src/i8/i8vec4.rs @@ -152,7 +152,7 @@ impl I8Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [i8]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/u16/u16vec2.rs b/src/u16/u16vec2.rs index 3389dfb4..907f8a86 100644 --- a/src/u16/u16vec2.rs +++ b/src/u16/u16vec2.rs @@ -117,7 +117,7 @@ impl U16Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u16]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/u16/u16vec3.rs b/src/u16/u16vec3.rs index b2ea8186..14bb406b 100644 --- a/src/u16/u16vec3.rs +++ b/src/u16/u16vec3.rs @@ -123,7 +123,7 @@ impl U16Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u16]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/u16/u16vec4.rs b/src/u16/u16vec4.rs index 82f51db9..0ff3b722 100644 --- a/src/u16/u16vec4.rs +++ b/src/u16/u16vec4.rs @@ -137,7 +137,7 @@ impl U16Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u16]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/u32/uvec2.rs b/src/u32/uvec2.rs index 509a1981..e81e0032 100644 --- a/src/u32/uvec2.rs +++ b/src/u32/uvec2.rs @@ -117,7 +117,7 @@ impl UVec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u32]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/u32/uvec3.rs b/src/u32/uvec3.rs index 90796984..5ac4d496 100644 --- a/src/u32/uvec3.rs +++ b/src/u32/uvec3.rs @@ -123,7 +123,7 @@ impl UVec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u32]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/u32/uvec4.rs b/src/u32/uvec4.rs index 9011fe38..f02182f4 100644 --- a/src/u32/uvec4.rs +++ b/src/u32/uvec4.rs @@ -137,7 +137,7 @@ impl UVec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u32]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/u64/u64vec2.rs b/src/u64/u64vec2.rs index eff4751f..83f333bd 100644 --- a/src/u64/u64vec2.rs +++ b/src/u64/u64vec2.rs @@ -117,7 +117,7 @@ impl U64Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u64]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/u64/u64vec3.rs b/src/u64/u64vec3.rs index 77a6c1cc..585fbb5a 100644 --- a/src/u64/u64vec3.rs +++ b/src/u64/u64vec3.rs @@ -123,7 +123,7 @@ impl U64Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u64]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/u64/u64vec4.rs b/src/u64/u64vec4.rs index 775e91d2..07ce2274 100644 --- a/src/u64/u64vec4.rs +++ b/src/u64/u64vec4.rs @@ -137,7 +137,7 @@ impl U64Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u64]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/src/u8/u8vec2.rs b/src/u8/u8vec2.rs index 1edf7d79..cf2c1bba 100644 --- a/src/u8/u8vec2.rs +++ b/src/u8/u8vec2.rs @@ -117,7 +117,7 @@ impl U8Vec2 { /// Panics if `slice` is less than 2 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u8]) { - slice.copy_from_slice(&self.to_array()); + slice[..2].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from `self` and the given `z` value. diff --git a/src/u8/u8vec3.rs b/src/u8/u8vec3.rs index 67745ab8..09ba3f4a 100644 --- a/src/u8/u8vec3.rs +++ b/src/u8/u8vec3.rs @@ -123,7 +123,7 @@ impl U8Vec3 { /// Panics if `slice` is less than 3 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u8]) { - slice.copy_from_slice(&self.to_array()); + slice[..3].copy_from_slice(&self.to_array()); } /// Internal method for creating a 3D vector from a 4D vector, discarding `w`. diff --git a/src/u8/u8vec4.rs b/src/u8/u8vec4.rs index 2d10d2c3..1b64aa8c 100644 --- a/src/u8/u8vec4.rs +++ b/src/u8/u8vec4.rs @@ -137,7 +137,7 @@ impl U8Vec4 { /// Panics if `slice` is less than 4 elements long. #[inline] pub fn write_to_slice(self, slice: &mut [u8]) { - slice.copy_from_slice(&self.to_array()); + slice[..4].copy_from_slice(&self.to_array()); } /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. diff --git a/tests/vec2.rs b/tests/vec2.rs index 737aefbb..e97e308e 100644 --- a/tests/vec2.rs +++ b/tests/vec2.rs @@ -613,6 +613,11 @@ macro_rules! impl_vec2_tests { v.write_to_slice(&mut a); assert_eq!(v, $vec2::from_slice(&a)); + let mut a = [0 as $t; 17]; + v.write_to_slice(&mut a); + assert_eq!(v, $vec2::from_slice(&a[..2])); + assert_eq!([0 as $t; 15], a[2..]); + should_panic!({ $vec2::ONE.write_to_slice(&mut [0 as $t]) }); should_panic!({ $vec2::from_slice(&[0 as $t]) }); }); diff --git a/tests/vec3.rs b/tests/vec3.rs index 0fc515c5..4f4ad052 100644 --- a/tests/vec3.rs +++ b/tests/vec3.rs @@ -718,6 +718,11 @@ macro_rules! impl_vec3_tests { v.write_to_slice(&mut a); assert_eq!(v, $vec3::from_slice(&a)); + let mut a = [0 as $t; 17]; + v.write_to_slice(&mut a); + assert_eq!(v, $vec3::from_slice(&a[..3])); + assert_eq!([0 as $t; 14], a[3..]); + should_panic!({ $vec3::ONE.write_to_slice(&mut [0 as $t; 2]) }); should_panic!({ $vec3::from_slice(&[0 as $t; 2]) }); }); diff --git a/tests/vec4.rs b/tests/vec4.rs index 24b922d9..1abdaf21 100644 --- a/tests/vec4.rs +++ b/tests/vec4.rs @@ -836,6 +836,11 @@ macro_rules! impl_vec4_tests { let mut a = [0 as $t, 0 as $t, 0 as $t, 0 as $t]; v.write_to_slice(&mut a); assert_eq!(v, $vec4::from_slice(&a)); + + let mut a = [0 as $t; 17]; + v.write_to_slice(&mut a); + assert_eq!(v, $vec4::from_slice(&a[..4])); + assert_eq!([0 as $t; 13], a[4..]); }); glam_test!(test_sum, {