Ejemplo n.º 1
0
bool Polygon::insidePoly(Point p)
{
	if (p.x<minPoint.x-0.001 || p.x>maxPoint.x+0.001 || p.y<minPoint.y-0.001 || p.y>maxPoint.y+0.001)
		return false;
	int sum = 0;
	Point p1 = pointList[0] - p;
	int t1 = p1.x>=0 ?(p1.y>=0?0:3) :(p1.y>=0?1:2);
	if (equalZero(p1.x) && equalZero(p1.y)) return true;
	int i;
	for (i = 0;i<pointList.size();i++)
	{
		Point p2 = pointList[nextPointIndex(i)] - p;
		if(equalZero(p2.x) && equalZero(p2.y)) break;
		float f = p2.y * p1.x - p2.x * p1.y;
		if(equalZero(f) && p1.x*p2.x <= 0 && p1.y*p2.y <= 0) break;
		int t2 = p2.x>=0 ?(p2.y>=0?0:3) :(p2.y>=0?1:2);
		if(t2 ==(t1 + 1) % 4) sum += 1;
		else if(t2 ==(t1 + 3) % 4) sum -= 1;
		else if(t2 ==(t1 + 2) % 4)
		{
			if(f > 0) sum += 2;
		    else sum -= 2;
		}
		t1 = t2;
		p1 = p2;
	}
	if(i<pointList.size() || sum)
		return true;
	return false;
}
Ejemplo n.º 2
0
static int checkConvergence(double *beta, double *beta_old, double eps,
                            int len)
{
  int i, converged = 1;
  for (i = 0; i <= len; i++)
  {
    if (!equalZero(beta[i]) && !equalZero(beta_old[i]))
    {
      if (fabs((beta[i]-beta_old[i]) / beta_old[i]) > eps)
      {
        converged = 0;
        break;
      }
    }
    else if (!equalZero(beta[i]) && equalZero(beta_old[i]))
    {converged = 0;break;}
    else if (equalZero(beta[i]) && !equalZero(beta_old[i]))
    {converged = 0;break;}
  }
  return(converged);
}