From 9239c9dedb0563aa00ffe12d08d54a44c574af47 Mon Sep 17 00:00:00 2001 From: Adrian-Diaz Date: Fri, 19 Jul 2019 17:13:44 -0600 Subject: [PATCH] patch niche rcb issue --- src/rcb.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/rcb.cpp b/src/rcb.cpp index 83cdccdf80..ac7ac60b1f 100644 --- a/src/rcb.cpp +++ b/src/rcb.cpp @@ -467,6 +467,38 @@ void RCB::compute(int dimension, int n, double **x, double *wt, } } + //check if zero box width is the result due to dots being on box vertices + //select half of the box in this case along the best dim + //the best dim is chosen according to the optimum volume (to minimize surface area) + + if(largest==0.0){ + double best_volume=0; + double current_volume; + int dim1o,dim2o; + for (dim = 0; dim < dimension; dim++){ + if(dim==0){ + dim1o=1; + dim2o=2; + } + if(dim==1){ + dim1o=0; + dim2o=2; + } + if(dim==2){ + dim1o=0; + dim2o=1; + } + valuehalf = 0.5*(lo[dim] + hi[dim]); + current_volume = (hi[dim1o]-lo[dim1o]) + *(hi[dim2o]-lo[dim2o])*(valuehalf-lo[dim]); + //chose cut that minimizes surface area by maximizing volume; + if(current_volume>best_volume){ best_volume = current_volume; + valuehalf_select = valuehalf; + dim_select = dim; + } + } + } + // copy results for best dim cut into dim,valuehalf,dotmark dim = dim_select;