@@ -564,15 +564,16 @@ void tns::TreeNSearch::_update_world_AABB_simd()
564564 const int thread_n_points = end - begin;
565565 if (thread_n_points > 0 ) {
566566
567- // We compute two points at the same time: [x, y, z, z , y, z, ., .]
567+ // We compute two points at the same time: [x, y, z, x , y, z, ., .]
568568 // Therefore, to not overflow, the remainder is 3
569- for (int point_i = begin; point_i < end - 3 ; point_i += 2 ) {
569+ int point_i = begin;
570+ for (; point_i < end - 3 ; point_i += 2 ) {
570571 const __m256 p = _mm256_loadu_ps (&points[3 * point_i]);
571572 b_simd = _mm256_min_ps (b_simd, p);
572573 t_simd = _mm256_max_ps (t_simd, p);
573574 }
574575
575- for (int point_i = end - 3 ; point_i < end; point_i++) {
576+ for (; point_i < end; point_i++) {
576577 const int base = 3 * point_i;
577578 const __m256 p = _mm256_setr_ps (points[base + 0 ], points[base + 1 ], points[base + 2 ], 0 .0f , 0 .0f , 0 .0f , 0 .0f , 0 .0f );
578579 b_simd = _mm256_min_ps (b_simd, p);
@@ -582,13 +583,6 @@ void tns::TreeNSearch::_update_world_AABB_simd()
582583 thread_domain_simd[thread_id][0 ] = _mm256_min_ps (thread_domain_simd[thread_id][0 ], b_simd);
583584 thread_domain_simd[thread_id][1 ] = _mm256_max_ps (thread_domain_simd[thread_id][1 ], t_simd);
584585 }
585-
586- // AABB is the first point
587- else {
588- const __m256 p = _mm256_loadu_ps (&points[3 * begin]);
589- thread_domain_simd[thread_id][0 ] = _mm256_min_ps (thread_domain_simd[thread_id][0 ], p);
590- thread_domain_simd[thread_id][1 ] = _mm256_max_ps (thread_domain_simd[thread_id][1 ], p);
591- }
592586 }
593587 }
594588
@@ -692,7 +686,7 @@ void tns::TreeNSearch::_points_to_cells()
692686
693687 // Find the set of the first point
694688 int begin_set = 0 ;
695- while (this ->set_offsets [begin_set + 1 ] < begin_thread_point) {
689+ while (this ->set_offsets [begin_set + 1 ] <= begin_thread_point) {
696690 begin_set++;
697691 }
698692
@@ -786,7 +780,7 @@ void tns::TreeNSearch::_points_to_cells()
786780 }
787781 this ->cells .n_cells = n_cells;
788782 this ->cells .offsets [n_cells] = this ->get_total_n_points ();
789- this ->avg_points_per_cell = this ->get_total_n_points () / n_cells;
783+ this ->avg_points_per_cell = (n_cells > 0 ) ? this ->get_total_n_points () / n_cells : 0 ;
790784
791785
792786 // Variable radius
@@ -875,7 +869,7 @@ void tns::TreeNSearch::_points_to_cells_simd()
875869
876870 // Find the set of the first point
877871 int begin_set = 0 ;
878- while (this ->set_offsets [begin_set + 1 ] < begin_thread_point) {
872+ while (this ->set_offsets [begin_set + 1 ] <= begin_thread_point) {
879873 begin_set++;
880874 }
881875
@@ -1054,7 +1048,7 @@ void tns::TreeNSearch::_points_to_cells_simd()
10541048 }
10551049 this ->cells .n_cells = n_cells;
10561050 this ->cells .offsets [n_cells] = this ->get_total_n_points ();
1057- this ->avg_points_per_cell = this ->get_total_n_points () / n_cells;
1051+ this ->avg_points_per_cell = (n_cells > 0 ) ? this ->get_total_n_points () / n_cells : 0 ;
10581052
10591053
10601054 // Variable radius
0 commit comments