Skip to content

Commit 6a637b0

Browse files
committed
Changed to resolve edge case of duplicate points.
1 parent c46039d commit 6a637b0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

contents/jarvis_march/code/c++/jarvis_march.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ struct Point
1010
{
1111
return x == b.x && y == b.y;
1212
}
13+
14+
bool operator!=(const Point& b) const
15+
{
16+
return !(*this == b);
17+
}
1318
};
1419

1520
std::vector<Point> jarvis_march(const std::vector<Point>& points)
@@ -38,13 +43,14 @@ std::vector<Point> jarvis_march(const std::vector<Point>& points)
3843
}
3944
);
4045
}
41-
while(next_point_it != first_point_it);
46+
while(*next_point_it != *first_point_it);
4247

4348
return hull_points;
4449
}
4550

4651
int main() {
4752
std::vector<Point> points = {
53+
{ 1.0, 3.0 },
4854
{ 1.0, 3.0 },
4955
{ 2.0, 4.0 },
5056
{ 4.0, 0.0 },

0 commit comments

Comments
 (0)