Exemple #1
0
extern domain_t* cf_domain(double w, double h)
{
  bbox_t b = {{-w/2, w/2},
	      {-h/2, h/2}};
  vector_t v = {0, 0};
  polyline_t p1, p2;
  double R = w/10.0;

  if ((polyline_rect(b, &p1) != 0) || (polyline_ngon(R, v, 32, &p2) != 0))
    return NULL;

  domain_t* dom;

  dom = domain_insert(NULL, &p1);
  dom = domain_insert(dom, &p2);

  polyline_clear(&p1);
  polyline_clear(&p2);

  if (domain_orientate(dom) != 0)
    {
      domain_destroy(dom);
      return NULL;
    }

  return dom;
}
Exemple #2
0
extern domain_t* cylf_domain(cylf_t cylf)
{
  bbox_t b = {{-1, 1}, {-1, 1}};
  vector_t v = {cylf.x, cylf.y};

  polyline_t p1, p2;

  if ((polyline_rect(b, &p1) != 0) ||
      (polyline_ngon(cylf.radius, v, 32, &p2) != 0))
    return NULL;

  domain_t* dom;

  dom = domain_insert(NULL, &p1);
  dom = domain_insert(dom, &p2);

  polyline_clear(&p1);
  polyline_clear(&p2);

  if (domain_orientate(dom) != 0)
    {
      domain_destroy(dom);
      return NULL;
    }

  return dom;
}
/*
De-allocates/allocates space as necessary in the destination Polyline data structure and copies the
vertex data from the source polyline (from) to the destination (to).
*/
void polyline_copy(Polyline *to, Polyline *from){
    if(NULL != to && NULL != from){
        polyline_clear(to);
        to->vertex = malloc(sizeof(Point)*from->numVertex);
        int i;
        for (i=0; i < from->numVertex; i++)
        {
          to->vertex[i] = from->vertex[i];
        }
        to->numVertex = from->numVertex;
        to->zBuffer = from->zBuffer;
    }
}
Exemple #4
0
/*
 * free the element and the object it contains, as appropriate.
 */
void element_delete(Element *e){
	if(!e){
		printf("Null e passed to element_delete\n");
		return;
	}
	//printf("deleting element of type %d\n", e->type);
	switch(e->type){
		case ObjPolyline:
			polyline_clear(&(e->obj.polyline));
			break;
		case ObjPolygon:
			polygon_clear(&(e->obj.polygon));
			break;
		default:
			//printf("ObjectType %d is not handled in element_delete\n",e->type);
			break;
	}
	free(e);
}
Exemple #5
0
// draw some random lines, then two boxes
int main(int argc, char *argv[]) {
  const int nPoints = 1000;

  Polyline thing1;
  Polyline *thing2;
  Point p[nPoints];
  int i;
  int rows = 500;
  int cols = 500;
  Image *src;
  Color Blue;
  Color Red;
  Color Green;

  Color_set( &Blue, 0.1, 0.15, 0.7 );
  Color_set( &Red, 0.8, 0.2, 0.1 );
  Color_set( &Green, 0.2, 0.6, 0.2 );
  
  printf("Startup\n");
  for(i=0;i<nPoints;i++) {
    point_set2D( &(p[i]), drand48()*cols/2, drand48()*rows/2 );
  }

  // init is necessary, because otherwise the fields are full of garbage
  printf("Polyline init and set\n");
  polyline_init( &thing1 );
  polyline_set( &thing1, 20, &( p[42] ) );

  printf("Polyline create\n");
  thing2 = polyline_createp( 10, &(p[105] ) );
  
  printf("Creating image\n");
  src = image_create( rows, cols );

  printf("Drawing poly-lines\n");
  // draw some random lines
  polyline_draw( &thing1, src, Blue );
  polyline_draw( thing2, src, Red );

  // draw a box going counter-clockwise, should be ok
  point_set2D( &(p[500]), 50, 300 );
  point_set2D( &(p[501]), 50, 350 );
  point_set2D( &(p[502]), 100, 350 );
  point_set2D( &(p[503]), 100, 300 );
  point_set2D( &(p[504]), 50, 300 );

  printf("Counter-clockwise box\n");
  polyline_set( thing2, 5, &(p[500]) );
  polyline_draw( thing2, src, Green );

  // draw a box going clockwise, should not be ok
  point_set2D( &(p[500]), 350, 300 );
  point_set2D( &(p[501]), 400, 300 );
  point_set2D( &(p[502]), 400, 350 );
  point_set2D( &(p[503]), 350, 350 );
  point_set2D( &(p[504]), 350, 300 );

  printf("Clockwise box\n");
  polyline_set( thing2, 5, &(p[500]) );
  polyline_draw( thing2, src, Green );

  image_write( src, "test3c.ppm");

  printf("Cleanup\n");
  polyline_clear( &thing1 );
    printf("clear\n");
  polyline_free( thing2 );
    printf("free\n");
  image_free( src );

  return(0);
}