From 8b8564f179ae68760dc58355a8f13e541f2a3dc1 Mon Sep 17 00:00:00 2001 From: Dominik Winecki Date: Wed, 5 Apr 2023 16:45:23 +0000 Subject: [PATCH] Add dimension check --- rstar/src/point.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rstar/src/point.rs b/rstar/src/point.rs index ee419ef..16e336e 100644 --- a/rstar/src/point.rs +++ b/rstar/src/point.rs @@ -313,6 +313,8 @@ where const DIMENSIONS: usize = N; fn generate(mut generator: impl FnMut(usize) -> S) -> Self { + assert!(N >= 2, "Point dimension too small - must be at least 2"); + // The same implementation used in std::array::from_fn // Since this is a const generic it gets unrolled let mut idx = 0; @@ -325,11 +327,13 @@ where #[inline] fn nth(&self, index: usize) -> Self::Scalar { + assert!(N >= 2, "Point dimension too small - must be at least 2"); self[index] } #[inline] fn nth_mut(&mut self, index: usize) -> &mut Self::Scalar { + assert!(N >= 2, "Point dimension too small - must be at least 2"); &mut self[index] } }