mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Fix pointPolygonTest for large coordinate values (#10222)
* Add test that fails * Fix integer pointPolygonTest for large coordinate values * Review fixes: - change type from long long to int64 - move test code to test_contours.cpp, and make it C++98 compliant * Hopefully fix compiler error by using push_back instead of emplace_back
This commit is contained in:
committed by
Vadim Pisarevsky
parent
5ce38e516e
commit
5b41599911
@@ -119,7 +119,6 @@ double cv::pointPolygonTest( InputArray _contour, Point2f pt, bool measureDist )
|
||||
|
||||
for( i = 0; i < total; i++ )
|
||||
{
|
||||
int dist;
|
||||
v0 = v;
|
||||
v = cnt[i];
|
||||
|
||||
@@ -133,7 +132,8 @@ double cv::pointPolygonTest( InputArray _contour, Point2f pt, bool measureDist )
|
||||
continue;
|
||||
}
|
||||
|
||||
dist = (ip.y - v0.y)*(v.x - v0.x) - (ip.x - v0.x)*(v.y - v0.y);
|
||||
int64 dist = static_cast<int64>(ip.y - v0.y)*(v.x - v0.x)
|
||||
- static_cast<int64>(ip.x - v0.x)*(v.y - v0.y);
|
||||
if( dist == 0 )
|
||||
return 0;
|
||||
if( v.y < v0.y )
|
||||
|
||||
@@ -485,4 +485,18 @@ TEST(Imgproc_FindContours, border)
|
||||
ASSERT_TRUE(norm(img - img_draw_contours, NORM_INF) == 0.0);
|
||||
}
|
||||
|
||||
TEST(Imgproc_PointPolygonTest, regression_10222)
|
||||
{
|
||||
vector<Point> contour;
|
||||
contour.push_back(Point(0, 0));
|
||||
contour.push_back(Point(0, 100000));
|
||||
contour.push_back(Point(100000, 100000));
|
||||
contour.push_back(Point(100000, 50000));
|
||||
contour.push_back(Point(100000, 0));
|
||||
|
||||
const Point2f point(40000, 40000);
|
||||
const double result = cv::pointPolygonTest(contour, point, false);
|
||||
EXPECT_GT(result, 0) << "Desired result: point is inside polygon - actual result: point is not inside polygon";
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
||||
Reference in New Issue
Block a user