Skip to content

Commit 7a42990

Browse files
authored
Merge pull request #3323 from y-guyon:fix_polyanticlockwise
Use T as temp var type in polyanticlockwise()
2 parents 4a91f2f + 94ca0c5 commit 7a42990

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

modules/mcc/src/common.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,30 @@ mace_center(const std::vector<cv::Point2f> &ps)
8686
return center;
8787
}
8888

89+
void polyanticlockwise(std::vector<cv::Point2f> &points)
90+
{
91+
// Sort the points in anti-clockwise order
92+
// Trace a line between the first and second point.
93+
// If the third point is at the right side, then the points are anti-clockwise
94+
cv::Point2f v1 = points[1] - points[0];
95+
cv::Point2f v2 = points[2] - points[0];
96+
97+
//if the third point is in the left side, then sort in anti-clockwise order
98+
if ((v1.x * v2.y) - (v1.y * v2.x) < 0.0)
99+
std::swap(points[1], points[3]);
100+
}
101+
void polyclockwise(std::vector<cv::Point2f> &points)
102+
{
103+
// Sort the points in clockwise order
104+
// Trace a line between the first and second point.
105+
// If the third point is at the right side, then the points are clockwise
106+
cv::Point2f v1 = points[1] - points[0];
107+
cv::Point2f v2 = points[2] - points[0];
108+
109+
//if the third point is in the left side, then sort in clockwise order
110+
if ((v1.x * v2.y) - (v1.y * v2.x) > 0.0)
111+
std::swap(points[1], points[3]);
112+
}
113+
89114
} // namespace mcc
90115
} // namespace cv

modules/mcc/src/common.hpp

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,9 @@ void unique(const std::vector<T> &A, std::vector<T> &U)
7373
U.push_back(Tm[i]);
7474
}
7575

76-
template <typename T>
77-
void polyanticlockwise(std::vector<T> &points)
78-
{
79-
// Sort the points in anti-clockwise order
80-
// Trace a line between the first and second point.
81-
// If the third point is at the right side, then the points are anti-clockwise
82-
cv::Point v1 = points[1] - points[0];
83-
cv::Point v2 = points[2] - points[0];
84-
85-
double o = (v1.x * v2.y) - (v1.y * v2.x);
76+
void polyanticlockwise(std::vector<cv::Point2f> &points);
77+
void polyclockwise(std::vector<cv::Point2f> &points);
8678

87-
if (o < 0.0) //if the third point is in the left side, then sort in anti-clockwise order
88-
std::swap(points[1], points[3]);
89-
}
90-
template <typename T>
91-
void polyclockwise(std::vector<T> &points)
92-
{
93-
// Sort the points in clockwise order
94-
// Trace a line between the first and second point.
95-
// If the third point is at the right side, then the points are clockwise
96-
cv::Point v1 = points[1] - points[0];
97-
cv::Point v2 = points[2] - points[0];
98-
99-
double o = (v1.x * v2.y) - (v1.y * v2.x);
100-
101-
if (o > 0.0) //if the third point is in the left side, then sort in clockwise order
102-
std::swap(points[1], points[3]);
103-
}
10479
// Does lexical cast of the input argument to string
10580
template <typename T>
10681
std::string ToString(const T &value)

0 commit comments

Comments
 (0)