Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

rewrite better in c++20 float coeffthreshbasedonboundingboxside(const tc::pointf&…

  1. User

    rewrite better in c++20

            float coeffthresh_basedon_bounding_box_side(const tc::point_f& image_center, const tc::rect_i& target) 
            {
                auto[cx, cy] = image_center;
                auto[xmax, ymax] = target.br();
                auto[xmin, min] = target.tl()
                
                const auto lowThreshCoeff = 0.25f;
                const auto higThreshCoeff = 0.5f;
    
                // top left
                if (xmin < cx && xmax < cx && ymin < cy && ymax < cy) {
                    return lowThreshCoeff;
                }
                // left
                else if (xmax < cx && ymin < cy && ymax > cy) {
                    return higThreshCoeff;
                }
                // bottom-left
                else if (xmin < cx && xmax < cx && ymin > cy && ymax > cy) {
                    return lowThreshCoeff;
                }
                // top
                else if (ymax < cy && xmin < cx && xmax > cx) {
                    return lowThreshCoeff;
                }
                // bottom 
                else if (ymin > cy && xmin < cx && xmax > cx) {
                    return lowThreshCoeff;
                }
                // top right
                else if (xmin > cx && xmax > cx && ymax < cy) {
                    return lowThreshCoeff;
                }
                // right
                else if (xmin > cx && ymin < cy && ymax > cy) {
                    return higThreshCoeff;
                }
                // bottom-right
                else if (xmin > cx && xmax > cx && ymin > cy) {
                    return lowThreshCoeff;
                }
                // centered
                else {
                    return higThreshCoeff;
                }
            }
    
  2. Assistant

    double coeffthresh_basedon_bounding_box_side(const tc::point_f& image_center, const tc::rect_i& target) { const double lowThreshCoeff = 0.25; const double highThreshCoeff = 0.5;

    const auto[xmin, ymin] = target.tl();
    const auto[xmax, ymax] = target.br();
    const auto[cx, cy] = image_center;
    
    if (xmin < cx && xmax < cx && ymin < cy && ymax < cy)
        return lowThreshCoeff; // top left
    else if (xmax < cx && ymin < cy && ymax > cy)
        return highThreshCoeff; // left
    else if (xmin < cx && xmax < cx && ymin > cy && ymax > cy)
        return lowThreshCoeff; // bottom-left
    else if (ymax < cy && xmin < cx && xmax > cx)
        return lowThreshCoeff; // top
    else if (ymin > cy && xmin < cx && xmax > cx)
        return lowThreshCoeff; // bottom
    else if (xmin > cx && xmax > cx && ymax < cy)
        return lowThreshCoeff; // top right
    else if (xmin > cx && ymin < cy && ymax > cy)
        return highThreshCoeff; // right
    else if (xmin > cx && xmax > cx && ymin > cy)
        return lowThreshCoeff; // bottom-right
    else
        return highThreshCoeff; // centered
    

    }