1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #26022 from Kumataro:fix26016

Imgproc: use double to determine whether the corners points are within src #26022

close #26016
Related https://github.com/opencv/opencv_contrib/pull/3778

### Pull Request Readiness Checklist

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
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Kumataro
2024-08-23 18:35:13 +09:00
committed by GitHub
parent 916724e2a0
commit a3bdbf5553
5 changed files with 78 additions and 8 deletions
+16 -1
View File
@@ -908,7 +908,22 @@ TYPED_TEST_P(Rect_Test, Overflows) {
EXPECT_EQ(R(), R(20, 0, 10, 10) & R(0, num_lowest, 10, 10));
EXPECT_EQ(R(), R(num_lowest, 0, 10, 10) & R(0, num_lowest, 10, 10));
}
REGISTER_TYPED_TEST_CASE_P(Rect_Test, Overflows);
// See https://github.com/opencv/opencv/issues/26016
// Rect_<int>.contains(Point_<float/double>) needs template specialization.
// This is test for a point on the edge and its nearest points.
template<typename T> T cv_nexttoward(T v, T v2);
template<> int cv_nexttoward<int>(int v, int v2) { CV_UNUSED(v); return v2; }
template<> float cv_nexttoward<float>(float v, float v2) { return std::nextafter(v,v2); }
template<> double cv_nexttoward<double>(double v, double v2) { return std::nexttoward(v,v2); }
TYPED_TEST_P(Rect_Test, OnTheEdge) {
Rect_<int> rect(0,0,500,500);
TypeParam h = static_cast<TypeParam>(rect.height);
ASSERT_TRUE ( rect.contains( Point_<TypeParam>(250, cv_nexttoward(h, h - 1))));
ASSERT_FALSE( rect.contains( Point_<TypeParam>(250, cv_nexttoward(h, h ))));
ASSERT_FALSE( rect.contains( Point_<TypeParam>(250, cv_nexttoward(h, h + 1))));
}
REGISTER_TYPED_TEST_CASE_P(Rect_Test, Overflows, OnTheEdge);
typedef ::testing::Types<int, float, double> RectTypes;
INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Rect_Test, RectTypes);