232's competitive-programming templates./geometry
(useless) furthestPoints (rotating calipers)
232-aka-pretty-pi
2024. 10. 23. 16:26
upd : now all in Geometry..
std::pair<Point, Point> furthestPoints(const std::vector<Point>& pts) {
assert(!pts.empty());
auto hull = getConvexHull(pts);
int n = hull.size();
G max_dist = -1;
std::pair<Point, Point> res;
for (int i = 0, j = 0; i < n; ++i) {
if (auto d = dist2(hull[i], hull[j]); max_dist < d) {
max_dist = d;
res = {hull[i], hull[j]};
}
while (ccw(hull[i], hull[(i + 1) % n], hull[(i + 1) % n] + hull[(j + 1) % n] - hull[j]) >= 0) {
j = (j + 1) % n;
if (auto d = dist2(hull[i], hull[j]); max_dist < d) {
max_dist = d;
res = {hull[i], hull[j]};
}
if (i == j) {
break;
}
}
}
return res;
}