From 8f0373816aefac01cca3cc2e87166dd5016f66de Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 15 Oct 2025 09:48:49 +0300 Subject: [PATCH] Merge pull request #27900 from MaximSmolskiy:refactor-minEnclosingCircle-tests Refactor minEnclosingCircle tests #27900 ### Pull Request Readiness Checklist Separate input points for tests Before this, next input points depended on previous ones and it was not obvious which input points specific test checked See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/imgproc/test/test_convhull.cpp | 75 ++++++++++++++------------ 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index 654df9167d..90889db044 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -52,10 +52,6 @@ namespace opencv_test { namespace { TEST(minEnclosingCircle, basic_test) { - vector pts; - pts.push_back(Point2f(0, 0)); - pts.push_back(Point2f(10, 0)); - pts.push_back(Point2f(5, 1)); const float EPS = 1.0e-3f; Point2f center; float radius; @@ -64,19 +60,24 @@ TEST(minEnclosingCircle, basic_test) // 2 // 0 1 // NB: The triangle is obtuse, so the only pts[0] and pts[1] are on the circle. - minEnclosingCircle(pts, center, radius); - EXPECT_NEAR(center.x, 5, EPS); - EXPECT_NEAR(center.y, 0, EPS); - EXPECT_NEAR(5, radius, EPS); + { + const vector 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 - pts[2] = Point2f(5, 5); - minEnclosingCircle(pts, center, radius); - EXPECT_NEAR(center.x, 5, EPS); - EXPECT_NEAR(center.y, 0, EPS); - EXPECT_NEAR(5, radius, EPS); + { + const vector 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 @@ -84,32 +85,40 @@ TEST(minEnclosingCircle, basic_test) // // 0 1 // NB: The triangle is acute, so all 3 points are on the circle. - pts[2] = Point2f(5, 10); - minEnclosingCircle(pts, center, radius); - EXPECT_NEAR(center.x, 5, EPS); - EXPECT_NEAR(center.y, 3.75, EPS); - EXPECT_NEAR(6.25f, radius, EPS); + { + const vector pts = { {0, 0}, {10, 0}, {5, 10} }; + minEnclosingCircle(pts, center, radius); + EXPECT_NEAR(center.x, 5, EPS); + EXPECT_NEAR(center.y, 3.75, EPS); + EXPECT_NEAR(6.25f, radius, EPS); + } // The 3 points are colinear. - pts[2] = Point2f(3, 0); - minEnclosingCircle(pts, center, radius); - EXPECT_NEAR(center.x, 5, EPS); - EXPECT_NEAR(center.y, 0, EPS); - EXPECT_NEAR(5, radius, EPS); + { + const vector pts = { {0, 0}, {10, 0}, {3, 0} }; + minEnclosingCircle(pts, center, radius); + EXPECT_NEAR(center.x, 5, EPS); + EXPECT_NEAR(center.y, 0, EPS); + EXPECT_NEAR(5, radius, EPS); + } // 2 points are the same. - pts[2] = pts[1]; - minEnclosingCircle(pts, center, radius); - EXPECT_NEAR(center.x, 5, EPS); - EXPECT_NEAR(center.y, 0, EPS); - EXPECT_NEAR(5, radius, EPS); + { + const vector pts = { {0, 0}, {10, 0}, {10, 0} }; + minEnclosingCircle(pts, center, radius); + EXPECT_NEAR(center.x, 5, EPS); + EXPECT_NEAR(center.y, 0, EPS); + EXPECT_NEAR(5, radius, EPS); + } // 3 points are the same. - pts[0] = pts[1]; - minEnclosingCircle(pts, center, radius); - EXPECT_NEAR(center.x, 10, EPS); - EXPECT_NEAR(center.y, 0, EPS); - EXPECT_NEAR(0, radius, EPS); + { + const vector pts = { {10, 0}, {10, 0}, {10, 0} }; + minEnclosingCircle(pts, center, radius); + EXPECT_NEAR(center.x, 10, EPS); + EXPECT_NEAR(center.y, 0, EPS); + EXPECT_NEAR(0, radius, EPS); + } } TEST(Imgproc_minEnclosingCircle, regression_16051) {