Skip to content

Commit

Permalink
Add dimension check
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikWin committed Apr 5, 2023
1 parent dc67a25 commit 8b8564f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rstar/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]
}
}
Expand Down

0 comments on commit 8b8564f

Please sign in to comment.