void convex_hull(poly &v,poly &p) { p.clear() ; sort(v.begin(),v.end()) ; v.resize(unique(v.begin(),v.end())-v.begin()) ; int n=v.size() ; int sz=0 ; for(int i=0;i<n;i++) { while(sz>=2 && dcmp(cross(st[sz-2],st[sz-1],v[i]))<0) sz-- ; st[sz++]=v[i] ; } for(int i=0;i<sz;i++) p.push_back(st[i]) ; sz=0 ; for(int i=0;i<n;i++) { while(sz>=2 && dcmp(cross(st[sz-2],st[sz-1],v[i])>0)) sz-- ; st[sz++]=v[i] ; } for(int i=sz-1;i>=0;i--) { if(i==sz-1 && st[i]==p.back()) continue ; if(i==0 && st[i]==p[0]) continue ; p.push_back(st[i]) ; } }
void convex_hull(poly & t, poly & r) { unsigned i; Compare order; // Search leftmost vertex order.p0 = t[0]; for (i = 1; i < t.size(); ++i) if (t[i].real() < order.p0.real()) order.p0 = t[i]; sort(t.begin(), t.end(), order); for (i = 0; i < t.size(); ++i) { r.push_back(t[i]); // Pop vertices that become internal while (r.size() > 3u && angle(r.end()[-3], r.end()[-2], r.end()[-1])) { r.end()[-2] = r.back(); r.pop_back(); } } return; }