@@ -126,11 +126,7 @@ pub fn matrix_rank(vectors: &[Vec<f64>], tol: f64) -> Result<usize, GeometryErro
126126 let rows = vectors. len ( ) ;
127127 let flat: Vec < f64 > = vectors. iter ( ) . flat_map ( |row| row. iter ( ) . copied ( ) ) . collect ( ) ;
128128 let svd = DMatrix :: from_row_slice ( rows, cols, & flat) . svd ( false , false ) ;
129- let max_singular = svd
130- . singular_values
131- . iter ( )
132- . copied ( )
133- . fold ( 0.0_f64 , f64:: max) ;
129+ let max_singular = svd. singular_values . iter ( ) . copied ( ) . fold ( 0.0_f64 , f64:: max) ;
134130 let tol = if tol. is_sign_positive ( ) {
135131 tol
136132 } else {
@@ -155,24 +151,25 @@ pub fn fast_2d_point_in_simplex(
155151 let [ [ p0x, p0y] , [ p1x, p1y] , [ p2x, p2y] ] = * simplex;
156152 let [ px, py] = * point;
157153
158- let area: f64 = 0.5
159- * ( -p1y * p2x + p0y * ( p2x - p1x) + p1x * p2y + p0x * ( p1y - p2y) ) ;
154+ let area: f64 = 0.5 * ( -p1y * p2x + p0y * ( p2x - p1x) + p1x * p2y + p0x * ( p1y - p2y) ) ;
160155 if area == 0.0 {
161156 return Err ( GeometryError :: DegenerateSimplex ) ;
162157 }
163158
164- let s = 1.0 / ( 2.0 * area)
165- * ( p0y * p2x + ( p2y - p0y) * px - p0x * p2y + ( p0x - p2x) * py) ;
159+ let s = 1.0 / ( 2.0 * area) * ( p0y * p2x + ( p2y - p0y) * px - p0x * p2y + ( p0x - p2x) * py) ;
166160 if s < -eps || s > 1.0 + eps {
167161 return Ok ( false ) ;
168162 }
169163
170- let t = 1.0 / ( 2.0 * area)
171- * ( p0x * p1y + ( p0y - p1y) * px - p0y * p1x + ( p1x - p0x) * py) ;
164+ let t = 1.0 / ( 2.0 * area) * ( p0x * p1y + ( p0y - p1y) * px - p0y * p1x + ( p1x - p0x) * py) ;
172165 Ok ( t >= -eps && s + t <= 1.0 + eps)
173166}
174167
175- pub fn point_in_simplex ( point : & [ f64 ] , simplex : & [ Vec < f64 > ] , eps : f64 ) -> Result < bool , GeometryError > {
168+ pub fn point_in_simplex (
169+ point : & [ f64 ] ,
170+ simplex : & [ Vec < f64 > ] ,
171+ eps : f64 ,
172+ ) -> Result < bool , GeometryError > {
176173 if simplex. is_empty ( ) || simplex. len ( ) != point. len ( ) + 1 {
177174 return Err ( GeometryError :: InvalidDimensions (
178175 "Simplex dimension mismatch" . to_string ( ) ,
@@ -247,14 +244,10 @@ pub fn fast_3d_circumsphere(points: &[[f64; 3]; 4]) -> ([f64; 3], f64) {
247244 let l2 = x2 * x2 + y2 * y2 + z2 * z2;
248245 let l3 = x3 * x3 + y3 * y3 + z3 * z3;
249246
250- let dx = l1 * ( y2 * z3 - z2 * y3) - l2 * ( y1 * z3 - z1 * y3)
251- + l3 * ( y1 * z2 - z1 * y2) ;
252- let dy = l1 * ( x2 * z3 - z2 * x3) - l2 * ( x1 * z3 - z1 * x3)
253- + l3 * ( x1 * z2 - z1 * x2) ;
254- let dz = l1 * ( x2 * y3 - y2 * x3) - l2 * ( x1 * y3 - y1 * x3)
255- + l3 * ( x1 * y2 - y1 * x2) ;
256- let aa = x1 * ( y2 * z3 - z2 * y3) - x2 * ( y1 * z3 - z1 * y3)
257- + x3 * ( y1 * z2 - z1 * y2) ;
247+ let dx = l1 * ( y2 * z3 - z2 * y3) - l2 * ( y1 * z3 - z1 * y3) + l3 * ( y1 * z2 - z1 * y2) ;
248+ let dy = l1 * ( x2 * z3 - z2 * x3) - l2 * ( x1 * z3 - z1 * x3) + l3 * ( x1 * z2 - z1 * x2) ;
249+ let dz = l1 * ( x2 * y3 - y2 * x3) - l2 * ( x1 * y3 - y1 * x3) + l3 * ( x1 * y2 - y1 * x2) ;
250+ let aa = x1 * ( y2 * z3 - z2 * y3) - x2 * ( y1 * z3 - z1 * y3) + x3 * ( y1 * z2 - z1 * y2) ;
258251 let a = 2.0 * aa;
259252
260253 let cx = dx / a;
@@ -344,8 +337,8 @@ fn slogdet(matrix: &[Vec<f64>]) -> Result<(f64, f64), GeometryError> {
344337 for pivot_col in 0 ..n {
345338 let mut pivot_row = pivot_col;
346339 let mut pivot_abs = work[ pivot_col] [ pivot_col] . abs ( ) ;
347- for row in ( pivot_col + 1 ) ..n {
348- let candidate = work [ row ] [ pivot_col] . abs ( ) ;
340+ for ( row, values ) in work . iter ( ) . enumerate ( ) . skip ( pivot_col + 1 ) {
341+ let candidate = values [ pivot_col] . abs ( ) ;
349342 if candidate > pivot_abs {
350343 pivot_abs = candidate;
351344 pivot_row = row;
@@ -368,11 +361,12 @@ fn slogdet(matrix: &[Vec<f64>]) -> Result<(f64, f64), GeometryError> {
368361 sign *= pivot. signum ( ) ;
369362 log_abs_det += pivot. abs ( ) . ln ( ) ;
370363
371- for row in ( pivot_col + 1 ) ..n {
372- let factor = work[ row] [ pivot_col] / pivot;
373- work[ row] [ pivot_col] = 0.0 ;
374- for col in ( pivot_col + 1 ) ..n {
375- work[ row] [ col] -= factor * work[ pivot_col] [ col] ;
364+ let pivot_values = work[ pivot_col] . clone ( ) ;
365+ for row_values in work. iter_mut ( ) . skip ( pivot_col + 1 ) {
366+ let factor = row_values[ pivot_col] / pivot;
367+ row_values[ pivot_col] = 0.0 ;
368+ for ( col, value) in row_values. iter_mut ( ) . enumerate ( ) . skip ( pivot_col + 1 ) {
369+ * value -= factor * pivot_values[ col] ;
376370 }
377371 }
378372 }
@@ -450,9 +444,11 @@ pub fn simplex_volume_in_embedding(vertices: &[Vec<f64>]) -> Result<f64, Geometr
450444
451445 let n = vertices. len ( ) ;
452446 let mut matrix = vec ! [ vec![ 0.0 ; n + 1 ] ; n + 1 ] ;
453- for idx in 1 ..=n {
454- matrix[ 0 ] [ idx] = 1.0 ;
455- matrix[ idx] [ 0 ] = 1.0 ;
447+ for value in matrix[ 0 ] . iter_mut ( ) . skip ( 1 ) {
448+ * value = 1.0 ;
449+ }
450+ for row in matrix. iter_mut ( ) . skip ( 1 ) {
451+ row[ 0 ] = 1.0 ;
456452 }
457453 for row in 0 ..n {
458454 for col in 0 ..n {
0 commit comments