Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
template bool pt_in_polygon2(const T &test,const std::vector &polygon)
{
static const int q_patt[2][2]= { {0,1}, {3,2} };
if (polygon.size()<3) return false;
std::vector::const_iterator end=polygon.end();
T pred_pt=polygon.back();
pred_pt.x-=test.x;
pred_pt.y-=test.y;
int pred_q=q_patt[pred_pt.y<0][pred_pt.x<0];
int w=0;
for(std::vector::const_iterator iter=polygon.begin();iter!=end;++iter)
{
T cur_pt = *iter;
cur_pt.x-=test.x;
cur_pt.y-=test.y;
int q=q_patt[cur_pt.y<0][cur_pt.x<0];
switch (q-pred_q)
{
case -3:++w;break;
case 3:--w;break;
case -2:if(pred_pt.x*cur_pt.y>=pred_pt.y*cur_pt.x) ++w;break;
case 2:if(!(pred_pt.x*cur_pt.y>=pred_pt.y*cur_pt.x)) --w;break;
}
pred_pt = cur_pt;
pred_q = q;
}
return w!=0;
}