33use crate :: KdTree ;
44use nalgebra:: Vector4 ;
55use rand:: prelude:: * ;
6- use rand:: thread_rng ;
6+ use rand:: rng ;
77use rayon:: prelude:: * ;
88use std:: collections:: { HashSet , VecDeque } ;
99use threecrate_core:: NearestNeighborSearch ;
@@ -136,7 +136,7 @@ pub fn segment_plane(
136136 }
137137
138138 let points = & cloud. points ;
139- let mut rng = thread_rng ( ) ;
139+ let mut rng = rng ( ) ;
140140 let mut best_model: Option < PlaneModel > = None ;
141141 let mut best_inliers = Vec :: new ( ) ;
142142 let mut best_score = 0 ;
@@ -145,7 +145,7 @@ pub fn segment_plane(
145145 // Randomly sample 3 points
146146 let mut indices = HashSet :: new ( ) ;
147147 while indices. len ( ) < 3 {
148- indices. insert ( rng. gen_range ( 0 ..points. len ( ) ) ) ;
148+ indices. insert ( rng. random_range ( 0 ..points. len ( ) ) ) ;
149149 }
150150 let indices: Vec < usize > = indices. into_iter ( ) . collect ( ) ;
151151
@@ -218,12 +218,12 @@ pub fn segment_plane_parallel(
218218 let results: Vec < _ > = ( 0 ..max_iters)
219219 . into_par_iter ( )
220220 . filter_map ( |_| {
221- let mut rng = thread_rng ( ) ;
221+ let mut rng = rng ( ) ;
222222
223223 // Randomly sample 3 points
224224 let mut indices = HashSet :: new ( ) ;
225225 while indices. len ( ) < 3 {
226- indices. insert ( rng. gen_range ( 0 ..points. len ( ) ) ) ;
226+ indices. insert ( rng. random_range ( 0 ..points. len ( ) ) ) ;
227227 }
228228 let indices: Vec < usize > = indices. into_iter ( ) . collect ( ) ;
229229
@@ -711,23 +711,23 @@ mod tests {
711711 fn test_segment_plane_ransac_noisy ( ) {
712712 // Create a point cloud with noisy planar points
713713 let mut cloud = PointCloud :: new ( ) ;
714- let mut rng = thread_rng ( ) ;
714+ let mut rng = rng ( ) ;
715715
716716 // Add points on XY plane (z=0) with noise
717717 for i in 0 ..20 {
718718 for j in 0 ..20 {
719719 let x = i as f32 ;
720720 let y = j as f32 ;
721- let z = rng. gen_range ( -0.05 ..0.05 ) ; // Add noise to z coordinate
721+ let z = rng. random_range ( -0.05 ..0.05 ) ; // Add noise to z coordinate
722722 cloud. push ( Point3f :: new ( x, y, z) ) ;
723723 }
724724 }
725725
726726 // Add some outliers
727727 for _ in 0 ..20 {
728- let x = rng. gen_range ( 0.0 ..20.0 ) ;
729- let y = rng. gen_range ( 0.0 ..20.0 ) ;
730- let z = rng. gen_range ( 1.0 ..5.0 ) ; // Outliers above the plane
728+ let x = rng. random_range ( 0.0 ..20.0 ) ;
729+ let y = rng. random_range ( 0.0 ..20.0 ) ;
730+ let z = rng. random_range ( 1.0 ..5.0 ) ; // Outliers above the plane
731731 cloud. push ( Point3f :: new ( x, y, z) ) ;
732732 }
733733
@@ -764,7 +764,7 @@ mod tests {
764764 fn test_segment_plane_ransac_tilted_plane ( ) {
765765 // Create a tilted plane (not aligned with coordinate axes)
766766 let mut cloud = PointCloud :: new ( ) ;
767- let mut rng = thread_rng ( ) ;
767+ let mut rng = rng ( ) ;
768768
769769 // Create a tilted plane: x + y + z = 0
770770 for i in 0 ..15 {
@@ -774,19 +774,19 @@ mod tests {
774774 let z = -( x + y) ; // Points on the plane x + y + z = 0
775775
776776 // Add some noise
777- let noise_x = rng. gen_range ( -0.02 ..0.02 ) ;
778- let noise_y = rng. gen_range ( -0.02 ..0.02 ) ;
779- let noise_z = rng. gen_range ( -0.02 ..0.02 ) ;
777+ let noise_x = rng. random_range ( -0.02 ..0.02 ) ;
778+ let noise_y = rng. random_range ( -0.02 ..0.02 ) ;
779+ let noise_z = rng. random_range ( -0.02 ..0.02 ) ;
780780
781781 cloud. push ( Point3f :: new ( x + noise_x, y + noise_y, z + noise_z) ) ;
782782 }
783783 }
784784
785785 // Add outliers
786786 for _ in 0 ..30 {
787- let x = rng. gen_range ( 0.0 ..15.0 ) ;
788- let y = rng. gen_range ( 0.0 ..15.0 ) ;
789- let z = rng. gen_range ( 5.0 ..10.0 ) ; // Outliers above the plane
787+ let x = rng. random_range ( 0.0 ..15.0 ) ;
788+ let y = rng. random_range ( 0.0 ..15.0 ) ;
789+ let z = rng. random_range ( 5.0 ..10.0 ) ; // Outliers above the plane
790790 cloud. push ( Point3f :: new ( x, y, z) ) ;
791791 }
792792
@@ -873,12 +873,12 @@ mod tests {
873873 // ---- Euclidean cluster extraction tests ----
874874
875875 fn make_sphere_cloud ( center : Point3f , radius : f32 , count : usize ) -> Vec < Point3f > {
876- let mut rng = thread_rng ( ) ;
876+ let mut rng = rng ( ) ;
877877 let mut pts = Vec :: with_capacity ( count) ;
878878 while pts. len ( ) < count {
879- let x: f32 = rng. gen_range ( -radius..radius) ;
880- let y: f32 = rng. gen_range ( -radius..radius) ;
881- let z: f32 = rng. gen_range ( -radius..radius) ;
879+ let x: f32 = rng. random_range ( -radius..radius) ;
880+ let y: f32 = rng. random_range ( -radius..radius) ;
881+ let z: f32 = rng. random_range ( -radius..radius) ;
882882 if x * x + y * y + z * z <= radius * radius {
883883 pts. push ( Point3f :: new ( center. x + x, center. y + y, center. z + z) ) ;
884884 }
0 commit comments