Repository: opencv/opencv
File: modules/imgproc/test/test_convhull.cpp (C++)

Code before:
#include "opencv2/core/hal/interface.h"
#include "opencv2/ts.hpp"
#include "opencv2/ts/cuda_test.hpp"
#include "test_precomp.hpp"

namespace opencv_test { namespace {

/****************************************************************************************\
*                                 minEnclosingCircle Test 3                              *
\****************************************************************************************/

TEST(minEnclosingCircle, basic_test)
{
    const float EPS = 1.0e-3f;
    Point2f center;
    float radius;

    // pts[2] is within the circle with diameter pts[0] - pts[1].
    //        2
    // 0             1
    // NB: The triangle is obtuse, so the only pts[0] and pts[1] are on the circle.
    {
        vector<Point2f> pts;
        pts.push_back(Point2f(0, 0));
        pts.push_back(Point2f(10, 0));
        pts.push_back(Point2f(5, 1));
        minEnclosingCircle(pts, center, radius);
        EXPECT_NEAR(center.x, 5, EPS);
        EXPECT_NEAR(center.y, 0, EPS);
        EXPECT_NEAR(5, radius, EPS);
    }

    // pts[2] is on the circle with diameter pts[0] - pts[1].
    //  2
    // 0 1
    {
        vector<Point2f> pts;
        pts.push_back(Point2f(0, 0));
        pts.push_back(Point2f(10, 0));
        pts.push_back(Point2f(5, 5));
        minEnclosingCircle(pts, center, radius);
        EXPECT_NEAR(center.x, 5, EPS);
        EXPECT_NEAR(center.y, 0, EPS);
        EXPECT_NEAR(5, radius, EPS);
    }

    // pts[2] is outside the circle with diameter pts[0] - pts[1].
    //   2
    //
    //
    // 0   1

Review comment (refactor):
You can simplify the code here and bellow with initializer list:
```
vector<Point2f> pts = { {0, 0}, {10, 0}, {5, 1} };

Code after:
#include "opencv2/core/hal/interface.h"
#include "opencv2/ts.hpp"
#include "opencv2/ts/cuda_test.hpp"
#include "test_precomp.hpp"

namespace opencv_test { namespace {

/****************************************************************************************\
*                                 minEnclosingCircle Test 3                              *
\****************************************************************************************/

TEST(minEnclosingCircle, basic_test)
{
    const float EPS = 1.0e-3f;
    Point2f center;
    float radius;

    // pts[2] is within the circle with diameter pts[0] - pts[1].
    //        2
    // 0             1
    // NB: The triangle is obtuse, so the only pts[0] and pts[1] are on the circle.
    {
        const vector<Point2f> pts = { {0, 0}, {10, 0}, {5, 1} };
        minEnclosingCircle(pts, center, radius);
        EXPECT_NEAR(center.x, 5, EPS);
        EXPECT_NEAR(center.y, 0, EPS);
        EXPECT_NEAR(5, radius, EPS);
    }

    // pts[2] is on the circle with diameter pts[0] - pts[1].
    //  2
    // 0 1
    {
        const vector<Point2f> pts = { {0, 0}, {10, 0}, {5, 5} };
        minEnclosingCircle(pts, center, radius);
        EXPECT_NEAR(center.x, 5, EPS);
        EXPECT_NEAR(center.y, 0, EPS);
        EXPECT_NEAR(5, radius, EPS);
    }

    // pts[2] is outside the circle with diameter pts[0] - pts[1].
    //   2
    //
    //
    // 0   1
    // NB: The triangle is acute, so all 3 points are on the circle.
    {
        const vector<Point2f> pts = { {0, 0}, {10, 0}, {5, 10} };
        minEnclosingCircle(pts, center, radius);
        EXPECT_NEAR(center.x, 5, EPS);
        EXPECT_NEAR(center.y, 3.75, EPS);