Skip to content

Commit

Permalink
Fix the random number generation
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Feb 19, 2024
1 parent 3f6a1ab commit 1d1bf1d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ impl<const N: usize> Plane<N> {
source: &mut T,
) -> (Self, Vec<usize>, Vec<usize>) {
debug_assert!(vectors.len() > 1);
let i = (indices.len() as f64 * source.read::<f64>()) as usize;
let i = source.read::<usize>() % indices.len();
let mut j = i;
while i == j {
j = (indices.len() as f64 * source.read::<f64>()) as usize;
j = source.read::<usize>() % indices.len();
}
let normal = vectors[j].subtract(&vectors[i]);
let offset = -normal.product(&vectors[i].average(&vectors[j]));
Expand Down Expand Up @@ -220,8 +220,8 @@ mod tests {
let vectors = vec![Vector([4.0, 2.0]), Vector([5.0, 7.0])];
let indices = (0..vectors.len()).collect::<Vec<_>>();
let (plane, above, below) = Plane::build(&vectors, &indices, &mut source);
assert::close(&plane.normal.0, &[1.0, 5.0], 1e-6);
assert_eq!(above, &[1]);
assert_eq!(below, &[0]);
assert::close(&plane.normal.0, &[-1.0, -5.0], 1e-6);
assert_eq!(above, &[0]);
assert_eq!(below, &[1]);
}
}

0 comments on commit 1d1bf1d

Please sign in to comment.