From cd97cad52dd3586efaed73f772c148cd7ecfe257 Mon Sep 17 00:00:00 2001 From: Yannis Guyon Date: Mon, 8 Aug 2022 22:41:05 +0200 Subject: [PATCH] Use T as temp var type in polyanticlockwise() To match the input data type. Cast inner computation to double to prevent int overflows for any input type. --- modules/mcc/src/common.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/mcc/src/common.hpp b/modules/mcc/src/common.hpp index aa4c383f5..224459eb1 100644 --- a/modules/mcc/src/common.hpp +++ b/modules/mcc/src/common.hpp @@ -79,10 +79,10 @@ void polyanticlockwise(std::vector &points) // Sort the points in anti-clockwise order // Trace a line between the first and second point. // If the third point is at the right side, then the points are anti-clockwise - cv::Point v1 = points[1] - points[0]; - cv::Point v2 = points[2] - points[0]; + T v1 = points[1] - points[0]; + T v2 = points[2] - points[0]; - double o = (v1.x * v2.y) - (v1.y * v2.x); + double o = ((double)v1.x * v2.y) - ((double)v1.y * v2.x); if (o < 0.0) //if the third point is in the left side, then sort in anti-clockwise order std::swap(points[1], points[3]); @@ -93,10 +93,10 @@ void polyclockwise(std::vector &points) // Sort the points in clockwise order // Trace a line between the first and second point. // If the third point is at the right side, then the points are clockwise - cv::Point v1 = points[1] - points[0]; - cv::Point v2 = points[2] - points[0]; + T v1 = points[1] - points[0]; + T v2 = points[2] - points[0]; - double o = (v1.x * v2.y) - (v1.y * v2.x); + double o = ((double)v1.x * v2.y) - ((double)v1.y * v2.x); if (o > 0.0) //if the third point is in the left side, then sort in clockwise order std::swap(points[1], points[3]);