Repository: opencv/opencv
File: modules/imgproc/src/geometry.cpp (C++)

Code before:
        const int nlanes = VTraits<v_float32>::vlanes()/2;
        for (; i < npoints; i += nlanes)
        {
            if (i > npoints - nlanes)
            {
                if (i == 0)
                    break;
                i = npoints - nlanes;
            }
            v_float32 ptXY2 = vx_load(pts + 2 * i);
            minval = v_min(ptXY2, minval);
            maxval = v_max(ptXY2, maxval);
        }
        constexpr int max_nlanes = VTraits<v_int32>::max_nlanes;
        float arr_minval[max_nlanes], arr_maxval[max_nlanes];
        vx_store(arr_minval, minval);
        vx_store(arr_maxval, maxval);
        for (int j = 0; j < nlanes; j++)
        {
            int _xmin = cvFloor(arr_minval[2*j]), _ymin = cvFloor(arr_minval[2*j+1]);
            int _xmax = cvFloor(arr_maxval[2*j]), _ymax = cvFloor(arr_maxval[2*j+1]);
            if (xmin > _xmin) xmin = _xmin;
            if (ymin > _ymin) ymin = _ymin;
            if (xmax < _xmax) xmax = _xmax;
            if (ymax < _ymax) ymax = _ymax;
        }
#endif
        for( ; i < npoints; i++ )
        {
            // because right and bottom sides of the bounding rectangle are not inclusive
            // (note +1 in width and height calculation below), cvFloor is used here instead of cvCeil
            int pt_x = cvFloor(pts[2*i]);
            int pt_y = cvFloor(pts[2*i+1]);

            if( xmin > pt_x )
                xmin = pt_x;

            if( xmax < pt_x )
                xmax = pt_x;

            if( ymin > pt_y )
                ymin = pt_y;

            if( ymax < pt_y )
                ymax = pt_y;
        }
    }

    return Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1);
}


Review comment (suggestion):
CV_TOGGLE_FLT replaced by cvFloor for floats. It may change the function behaviour. Need to discuss.

Code after:
                i = npoints - nlanes;
            }
            v_float32 ptXY2 = vx_load(pts + 2 * i);
            minval = v_min(ptXY2, minval);
            maxval = v_max(ptXY2, maxval);
        }
        constexpr int max_nlanes = VTraits<v_int32>::max_nlanes;
        float arr_minval[max_nlanes], arr_maxval[max_nlanes];
        vx_store(arr_minval, minval);
        vx_store(arr_maxval, maxval);
        for (int j = 0; j < nlanes; j++)
        {
            int _xmin = cvFloor(arr_minval[2*j]), _ymin = cvFloor(arr_minval[2*j+1]);
            int _xmax = cvFloor(arr_maxval[2*j]), _ymax = cvFloor(arr_maxval[2*j+1]);
            xmin = std::min(xmin, _xmin);
            ymin = std::min(ymin, _ymin);
            xmax = std::max(xmax, _xmax);
            ymax = std::max(ymax, _ymax);
        }
#endif
        for( ; i < npoints; i++ )
        {
            // because right and bottom sides of the bounding rectangle are not inclusive
            // (note +1 in width and height calculation below), cvFloor is used here instead of cvCeil
            int pt_x = cvFloor(pts[2*i]);
            int pt_y = cvFloor(pts[2*i+1]);

            xmin = std::min(xmin, pt_x);
            xmax = std::max(xmax, pt_x);
            ymin = std::min(ymin, pt_y);
            ymax = std::max(ymax, pt_y);
        }
    }

    return Rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1);
}


cv::Rect cv::boundingRect(InputArray array)
{
    CV_INSTRUMENT_REGION();

    Mat m = array.getMat();
    return m.depth() <= CV_8U ? maskBoundingRect(m) : pointSetBoundingRect(m);
}


/* Calculates bounding rectangle of a point set or retrieves already calculated */
CV_IMPL  CvRect
cvBoundingRect( CvArr* array, int update )
{