Ejemplo n.º 1
0
static void
find_three_point_rectangle_triangle (Rectangle *r,
                                     Point      points[4],
                                     gint       p)
{
  Point a = points[p % 4];        /* 0 1 2 3 */
  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
  Point i1;                       /* intersection point */
  Point i2;                       /* intersection point */
  Point mid;

  mid.x = (a.x + b.x) / 2.0;
  mid.y = (a.y + b.y) / 2.0;

  if (intersect_x (b, c, mid, &i1) &&
      intersect_y (a, d, mid, &i2))
    add_rectangle (points, r, mid, mid, i1, i2);

  if (intersect_y (b, c, mid, &i1) &&
      intersect_x (a, d, mid, &i2))
    add_rectangle (points, r, mid, mid, i1, i2);

  if (intersect_x (a, d, mid, &i1) &&
      intersect_y (b, c, mid, &i2))
    add_rectangle (points, r, mid, mid, i1, i2);

  if (intersect_y (a, d, mid, &i1) &&
      intersect_x (b, c, mid, &i2))
    add_rectangle (points, r, mid, mid, i1, i2);
}
Ejemplo n.º 2
0
static void
find_three_point_rectangle_corner (Rectangle *r,
                                   Point      points[4],
                                   gint       p)
{
  Point a = points[p       % 4];  /* 0 1 2 3 */
  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
  Point c = points[(p + 2) % 4];  /* 2 3 0 2 */
  Point d = points[(p + 3) % 4];  /* 3 0 2 1 */
  Point i1;                       /* intersection point */
  Point i2;                       /* intersection point */

  if (intersect_x (b, c, a , &i1) &&
      intersect_y (c, d, i1, &i2))
    add_rectangle (points, r, a, a, i1, i2);

  if (intersect_y (b, c, a , &i1) &&
      intersect_x (c, d, i1, &i2))
    add_rectangle (points, r, a, a, i1, i2);

  if (intersect_x (c, d, a , &i1) &&
      intersect_y (b, c, i1, &i2))
    add_rectangle (points, r, a, a, i1, i2);

  if (intersect_y (c, d, a , &i1) &&
      intersect_x (b, c, i1, &i2))
    add_rectangle (points, r, a, a, i1, i2);
}
Ejemplo n.º 3
0
static void
find_two_point_rectangle (Rectangle *r,
                          Point      points[4],
                          gint       p)
{
  Point a = points[ p      % 4];  /* 0 1 2 3 */
  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
  Point i1;                       /* intersection point */
  Point i2;                       /* intersection point */
  Point mid;                      /* Mid point */

  add_rectangle (points, r, a, a, c, c);
  add_rectangle (points, r, b, b, d, d);

  if (intersect_x (c, b, a, &i1) &&
      intersect_y (c, b, a, &i2))
    {
      mid.x = ( i1.x + i2.x ) / 2.0;
      mid.y = ( i1.y + i2.y ) / 2.0;

      add_rectangle (points, r, a, a, mid, mid);
    }
}
Ejemplo n.º 4
0
Archivo: t.c Proyecto: choupi/puzzle
int ray_trace(int h,int w,double x0, double y0, double k0, int p, double D)
{
	int px,py,pp=(p*k0>0?1:-1);
	double nx0,ny0,nx1,ny1,nx,ny,d0,d1;
	printf("%d %d %.4lf %.4lf %.6lf %d %.4lf\n", h,w,x0,y0,k0,p,D);
	if(D<=0) return 0;
	if(hmap[h][w]=='X' && x0!=mx && y0!=my && equal(my,k0*(mx-x0)+y0)) {
		d0=distance(x0,y0,mx,my);
	printf("@@@%.4lf %.4lf\n",D,d0);
		if(d0<D || equal(d0,D)) return 1;
		else return 0;
	}
//	printf(">%c %.4lf s:%.7lf\n",hmap[h][w],d0,fabs(my-k0*(mx-x0)-y0));

	if(p>0) nx0=floor(x0+1);
	else nx0=ceil(x0-1);
	if(pp>0) ny1=floor(y0+1);
	else ny1=ceil(y0-1);
	ny0=intersect_x(x0,y0,k0,nx0); nx1=intersect_y(x0,y0,k0,ny1);
	d0=distance(x0,y0,nx0,ny0); d1=distance(x0,y0,nx1,ny1);
//	printf("n0: %.4lf %.4lf %.4lf ", nx0, ny0, d0);
//	printf("n1: %.4lf %.4lf %.4lf\n", nx1, ny1,d1);
	if(equal(d0,d1)) {
		if(hmap[h+p][w+pp]=='#') {
			if(hmap[h+p][w]=='#' && hmap[h][w+pp]=='#')
				return ray_trace(h,w,nx0,ny0,k0,-1*p,D-d0);
			else if(hmap[h+p][w]=='#') 
				return ray_trace(h+p,w,nx0,ny0,ref_x(k0),p,D-d0);
			else if(hmap[h][w+pp]=='#')
				return ray_trace(h,w+pp,nx0,ny0,ref_y(k0),-1*p,D-d0);
			else return 0;
		} else return ray_trace(h+p,w+pp,nx0,ny0,k0,p,D-d0);
	}	
	if(d0<d1) {
		if(hmap[h+p][w]=='#') 
			return ray_trace(h,w,nx0,ny0,ref_x(k0),p,D-d0);
		else return ray_trace(h+p,w,nx0,ny0,k0,p,D-d0);
	} else {
		if(hmap[h][w+pp]=='#') 
			return ray_trace(h,w,nx1,ny1,ref_y(k0),-1*p,D-d1);
		else return ray_trace(h,w+pp,nx1,ny1,k0,p,D-d1);
	}
}
Ejemplo n.º 5
0
static void
find_maximum_aspect_rectangle (Rectangle *r,
                               Point      points[4],
                               gint       p)
{
  Point a = points[ p      % 4];  /* 0 1 2 3 */
  Point b = points[(p + 1) % 4];  /* 1 2 3 0 */
  Point c = points[(p + 2) % 4];  /* 2 3 0 1 */
  Point d = points[(p + 3) % 4];  /* 3 0 1 2 */
  Point i1;                       /* intersection point */
  Point i2;                       /* intersection point */
  Point i3;                       /* intersection point */

  if (intersect_x (b, c, a, &i1))
    {
      i2.x = i1.x + 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (c, d, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      i2.x = i1.x - 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (c, d, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);
    }

  if (intersect_y (b, c, a, &i1))
    {
      i2.x = i1.x + 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (c, d, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      i2.x = i1.x - 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (c, d, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);
    }

  if (intersect_x (c, d, a,  &i1))
    {
      i2.x = i1.x + 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (b, c, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      i2.x = i1.x - 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (b, c, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);
    }

  if (intersect_y (c, d, a,  &i1))
    {
      i2.x = i1.x + 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (b, c, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      i2.x = i1.x - 1.0 * r->aspect;
      i2.y = i1.y + 1.0;

      if (intersect (d, a, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (a, b, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);

      if (intersect (b, c, i1, i2, &i3))
        add_rectangle (points, r, i1, i3, i1, i3);
    }
}