@@ -132,9 +132,12 @@ inline void bisect(const coors_view_type &coors_1d, const value_type &init_min_v
132132 value_type min_val = init_min_val;
133133 value_type max_val = init_max_val;
134134 value_type p1_weight, p2_weight;
135- value_type prev_weight_ratio = 0 ;
136- value_type curr_weight_ratio;
137- while (1 ) {
135+ value_type weight_ratio;
136+ const int max_bisection_steps = 11 ;
137+ // For now, limit the number of times finding mid point to ten to make RCB work with Sierra T/F coordinates
138+ // TODO: - allow users to pass max_bisection_steps as an input parameter
139+ // - or switch to use the median, which is probably a better solution
140+ for (int bisection_step = 0 ; bisection_step < max_bisection_steps; ++bisection_step) {
138141 value_type mid_point = (max_val + min_val) / 2.0 ;
139142 p1_size = 0 ;
140143 p2_size = 0 ;
@@ -151,11 +154,9 @@ inline void bisect(const coors_view_type &coors_1d, const value_type &init_min_v
151154 p1_weight = static_cast <value_type>(p1_size);
152155 p2_weight = static_cast <value_type>(p2_size);
153156
154- curr_weight_ratio = std::max (p1_weight, p2_weight) / std::min (p1_weight, p2_weight);
157+ weight_ratio = std::max (p1_weight, p2_weight) / std::min (p1_weight, p2_weight);
155158
156- if (curr_weight_ratio < 1.1 )
157- break ;
158- else if (curr_weight_ratio == prev_weight_ratio)
159+ if (weight_ratio < 1.1 )
159160 break ;
160161 else {
161162 // Update min_val or max_val to calculate a new mid_point
@@ -164,7 +165,6 @@ inline void bisect(const coors_view_type &coors_1d, const value_type &init_min_v
164165 min_val = mid_point;
165166 else
166167 max_val = mid_point;
167- prev_weight_ratio = curr_weight_ratio;
168168 }
169169 }
170170}
0 commit comments