Beispiel #1
0
void test_cast_ray(void){
   struct sphere s[2];
   struct color c1 = create_color(1,0,.3);
   s[0] = create_sphere(create_point(1.4,2.6,0), 2, c1);
   s[1] = create_sphere(create_point(4.5, 5, 0), 1,c1);

   struct ray r = create_ray(create_point(0,0,0), 
                             create_vector(1.4,2.6,0));

   struct ray r2 = create_ray(create_point(-123.2,-4,-.3),
                             create_vector(1.3,-2.9,-.3));

   struct ray r3 = create_ray(create_point(-4.5,-4.3,0),
                             create_vector(-23,-100,-100));

   checkit_int(cast_ray(r,s,2).r, 1);
   checkit_int(cast_ray(r,s,2).g, 0);
   checkit_int(cast_ray(r,s,2).b, .3);

   checkit_int(cast_ray(r2,s,2).r, 1);
   checkit_int(cast_ray(r2,s,2).g, 1);
   checkit_int(cast_ray(r2,s,2).b, 1);

   checkit_int(cast_ray(r3,s,2).r, 1);
   checkit_int(cast_ray(r3,s,2).g, 1);
   checkit_int(cast_ray(r3,s,2).b, 1);

}
Beispiel #2
0
struct point input_eye(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-eye")!= 0){
      if(i>=argc-1)
         return create_point(0,0,-14);
      i++;
   }
   double x = 0;
   double y = 0;
   double z = -14;
 
      if(i+1<argc && !equalToFlag(argc,in,i+1))
         x = convert_double(in[i+1],0);
      else
         return create_point(x,y,z);

      if(i+2<argc && !equalToFlag(argc,in,i+2))
         y = convert_double(in[i+2],0);
      else
         return create_point(x,y,z);

      if(i+3<argc && !equalToFlag(argc,in,i+3))
         z = convert_double(in[i+3],-14);
      else
         return create_point(x,y,z);
   
   

   return create_point(x,y,z);
}
Beispiel #3
0
void test_distance(void){
   struct point s[3];
   s[0] = create_point(1,1,0);
   s[1] = create_point(1,0,0);
   s[2] = create_point(2.3,4.4,-1.3);
    
   checkit_double(distance(s[1],s[2]),4.768648);
   checkit_double(distance(s[1],s[0]),1);

}
Beispiel #4
0
void test_distance_all()
{
   struct point p1 = create_point(-2.3,1.1);
   struct point p2 = create_point(-3.3,-4.5);
   struct point p3 = create_point(3.6,1.2);
   struct point input5[]={p1,p2,p3};
   double result5[3];
   distance_all(input5,3,result5);
   checkit_double(result5[0],2.54950976);
   checkit_double(result5[1],5.580322571);
   checkit_double(result5[2],3.79473319220);

   struct point p4 = create_point(4.5,2.2);
   struct point p5 = create_point(0,-3.2);
   struct point p6 = create_point(-2.2,1.9);
   struct point p7 = create_point(3.4,-6.5);
   struct point p8 = create_point(-6.6,-7.7);
   struct point p9 = create_point(2.1,0);
   struct point input6[]={p4,p5,p6,p7,p8,p9};
   double result6[6];
   distance_all(input6,6,result6);
   checkit_double(result6[0],5.00899191454);
   checkit_double(result6[1],3.2);
   checkit_double(result6[2],2.906883);
   checkit_double(result6[3],7.3355299);
   checkit_double(result6[4],10.14149890);
   checkit_double(result6[5],2.1);

}
Beispiel #5
0
void test_cast_all_rays(void){
   struct color	c = create_color(.3,.5,.9);

   struct sphere s[2];
   s[0] = create_sphere(create_point(1,1,0), 2,c);
   s[1] = create_sphere(create_point(.5, 1.5, -3.0), .5,c);
   struct point eye = create_point(0,0,-14);
   
   cast_all_rays(-10,10,-7.5,7.5,1024,768,eye,s,2);

}
Beispiel #6
0
void test_create_point(void){
   struct point p1 = create_point(1.5,2.5,3.5);
   checkit_double(p1.x,1.5);
   checkit_double(p1.y,2.5);
   checkit_double(p1.z,3.5);

   struct point p2 =  create_point(23.2,35.4,12.32);
   checkit_double(p2.x,23.2);
   checkit_double(p2.y,35.4);
   checkit_double(p2.z,12.32);
}
Beispiel #7
0
int main () {
    printf("Hello cairo!\n");
    
    cairo_surface_t *surface = 
    cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
    cairo_t *context = cairo_create(surface);
    
    cairo_set_line_width (context, 10.0);
    cairo_set_source_rgb (context, 1, 1, 1);
    cairo_rectangle(context, 0, 0, width, height);
    cairo_fill_preserve(context);
    cairo_set_source_rgb (context, 0, 0, 1);
    cairo_stroke(context);
     
    cairo_set_source_rgb (context, 1, 1, 1);
    cairo_rectangle(context, 100, 100, 50, 50);
    cairo_fill(context);
    
    Color c1 = {1, 0.5, 0.5, 1.0};
    create_point(context, 100, 100, c1);
    create_point(context, 150, 150, c1);
    create_point(context, 200, 200, c1);
    create_point(context, 250, 250, c1);
    create_point(context, 300, 300, c1);
    
    cairo_set_source_rgba (context, 1, 1, 0, 0.2);
    cairo_rectangle(context, 125, 125, 50, 50);
    cairo_fill(context);
    
    Point p1 = {100, 100};
    Point p2 = {150, 250};
    Point p3 = {200, 300};
    Point p4 = {250, 50};
    Point p5 = {300, 80};
    Point p6 = {-1, -1};
    
    Line l1;
    l1.points = malloc(6*sizeof(Point));
    l1.points[0] = p1;
    l1.points[1] = p2;
    l1.points[2] = p3;
    l1.points[3] = p4;
    l1.points[4] = p5;
    l1.points[5] = p6;
    
    draw_line(context, l1);
    
    cairo_surface_write_to_png(surface, "hello.png");
    cairo_destroy(context);
    cairo_surface_destroy(surface);
    return 0;
}
Beispiel #8
0
void test_sphere_intersection_point(void){

   struct ray r = create_ray(create_point(0,0,0),create_vector(1.3,0,0));
   struct sphere s = create_sphere(create_point(2.5,0,0),1.2);
   struct maybe_point test = sphere_intersection_point(r,s);
   checkit_double(test.p.x,1.3);
   checkit_double(test.p.y,0);
   checkit_double(test.p.z,0);
   checkit_int(test.isPoint,1);
   
   struct ray r2 = create_ray(create_point(-2.4,-2.9,-4.4),create_vector(-1,0,0));
   struct sphere s2 = create_sphere(create_point(2.3,5.7,8.2),1);
   struct maybe_point test2 = sphere_intersection_point(r2,s2);
   checkit_int(test2.isPoint,0);
   
   
   struct ray r3 = create_ray(create_point(-4.3,0,4.7),create_vector(3.5,0,0));
   struct sphere s3 = create_sphere(create_point(2.1,0,0),4.7);
   struct maybe_point test3 = sphere_intersection_point(r3,s3);
   checkit_int(test3.isPoint,1); 
   

   struct ray r4 = create_ray(create_point(1.2,-5.4,4.2),create_vector(1.1,1.2,1.3));
   struct sphere s4 = create_sphere(create_point(4.7,6.4,2.2),13.5);
   struct maybe_point test4 = sphere_intersection_point(r4,s4);
   checkit_double(test4.p.x,9.871860);
   checkit_double(test4.p.y,4.060210);
   checkit_double(test4.p.z,14.448561);
   checkit_int(test4.isPoint,1);
}
Beispiel #9
0
void test_create_sphere(void){
   struct sphere s = create_sphere(create_point(1.9,3.9,7.9), 45.55);
   checkit_double(s.center.x,1.9);
   checkit_double(s.center.y,3.9);
   checkit_double(s.center.z,7.9);
   checkit_double(s.radius,45.55);

struct sphere s2 = create_sphere(create_point(5.8,9.8,1.8), 23.23);
   checkit_double(s2.center.x,5.8);
   checkit_double(s2.center.y,9.8);
   checkit_double(s2.center.z,1.8);
   checkit_double(s2.radius,23.23);

}
Beispiel #10
0
void points_loader::load_points(){

    //
    if( check_badpath() )
        return;

    //  Read line by line of the obsrv and points files.
    //
    while( _reader_obsrv.goto_next_line() && _reader_points.goto_next_line() )
        create_point( _reader_obsrv.line_tokens(), _reader_points.line_tokens() );
    create_point( _reader_obsrv.line_tokens(), _reader_points.line_tokens() );


}
Beispiel #11
0
struct maybe_point sphere_intersection_point(struct ray r, struct sphere s){
   struct maybe_point p;
   double A = dot_vector(r.dir,r.dir);
   double B = 2 * dot_vector(difference_point(r.p,s.center), r.dir);
   double C = dot_vector(difference_point(r.p,s.center),
              difference_point(r.p, s.center)) - s.radius*s.radius;

   double E = (-B+sqrt(B*B-4*A*C))/2/A;
   double F = (-B-sqrt(B*B-4*A*C))/2/A;

   if((E>0&& F>0)){
      p.isPoint = 1;
      if(E>F)
          p.p = translate_point(r.p, scale_vector(r.dir,F));
      else
          p.p = translate_point(r.p, scale_vector(r.dir,E));
    
   }else if((E>0||F>0)){
      p.isPoint = 1;
      if(E>0)
           p.p = translate_point(r.p, scale_vector(r.dir,E));
      else
           p.p = translate_point(r.p, scale_vector(r.dir,F));
     
   }else{
       p.isPoint =0;
       p.p = create_point(0,0,0);
   }

   return p;
}
Beispiel #12
0
void input_spheres(char **argv, struct sphere s[], int c[]){

   c[0] = 0;
   FILE *fp;
   fp= fopen(argv[1],"r");
  
   if (fp == NULL) {
       perror("usage: a.out <filename> [-eye x y z] [-view min_x max_x min_y max_y width height] [-light x y z r g b] [-ambient r g b]\n");
   }

   double x, y,z, radius,r,g, b,a,d, sp, ro;
   int index = 0;   

   while (fscanf(fp, "%lf %lf%lf %lf%lf %lf%lf %lf%lf %lf%lf ", 
                       &x, &y, &z,&radius, &r, &g,&b, &a, &d,&sp, &ro) != EOF &&
                 index<10000) {
      struct sphere sphere =  create_sphere(create_point(x,y,z),
                                            radius,
                                            create_color(r,g,b),
                                            create_finish(a,d,sp,ro));
      s[index] = sphere;
      index++;
   }
   c[0] = index;
   fclose(fp);

}
Beispiel #13
0
/**
 * Raster the color triangle to the screen.  Points are in
 * NDC coordinates (converted to screen coordinates).
 *
 * colors correspond to the respective points.
 */
void raster_triangle(point *a, point *b, point *c, color ca,
		color cb, color cc, int xres, int yres, color** grid,
		float** depth_grid) {
	point screen_a = NDC_to_screen(a, xres, yres);
	point screen_b = NDC_to_screen(b, xres, yres);
	point screen_c = NDC_to_screen(c, xres, yres);

	float x_min = min_x(&screen_a, &screen_b, &screen_c);
	float x_max = max_x(&screen_a, &screen_b, &screen_c);
	float y_min = min_y(&screen_a, &screen_b, &screen_c);
	float y_max = max_y(&screen_a, &screen_b, &screen_c);

	x_max = x_max > xres ? xres : x_max;
	y_max = y_max > yres ? yres : y_max;

	for (int x = x_min; x < x_max; x++) {
		for (int y = y_min; y < y_max; y++) {
			point curr_point = create_point(x, y, 0);
			float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point);
			float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point);
			float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point);
			curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z;

			if (valid_parameters(alpha, beta, gamma) && depth_grid[x][y] > curr_point.z) {
				color col = compute_color(ca, cb, cc, alpha, beta, gamma);
				grid[x][y].r = col.r;
				grid[x][y].g = col.g;
				grid[x][y].b = col.b;

				depth_grid[x][y] = curr_point.z;
			}
		}
	}
}
Beispiel #14
0
void test(void){

   struct point p1 = create_point(1,3);
   struct point p2 = create_point(3,6);
   struct point p3 = create_point(5,0);
   struct point p4 = create_point(7,1);

   checkit_int(p1.x,1);
   checkit_int(p2.y,6);

   struct rect r1 = create_rect(p1, 3,2);
   struct rect r2 = create_rect(p2, 4,1);
   struct rect r3 = create_rect(p3,1,1);
   struct rect r4 = create_rect(p4,1,1);
      
   checkit_int(r1.w, 3);
   checkit_int(r2.h, 1);

   checkit_double(distance(p1,p3),5);
   
   struct rect r[3] = {r1,r2,r3};
   checkit_int(largest_rect(r,3),0);
   
   struct point p[2];
   closest_corners(r1,r2,p);
   checkit_int(p[0].x,4);
   checkit_int(p[0].y,5);   
   checkit_int(p[1].x,3);
   checkit_int(p[1].y,6);

   struct point pt[2];
   closest_corners(r2,r3,pt);
   checkit_int(pt[0].x,3);
   checkit_int(pt[0].y,6);
   checkit_int(pt[1].x,5);
   checkit_int(pt[1].y,1);

   struct point pts[2];
   closest_corners(r3,r4,pts);
   checkit_int(pts[0].x,6);
   checkit_int(pts[0].y,1);
   checkit_int(pts[1].x,7);
   checkit_int(pts[1].y,1);


}
Beispiel #15
0
void test_create_ray(void){
   struct ray r = create_ray(create_point(2.3,4.3,2.1),create_vector(2.5,3.5,4.5));
   checkit_double(r.p.x, 2.3);
   checkit_double(r.p.y, 4.3);
   checkit_double(r.p.z, 2.1);
   checkit_double(r.dir.x,2.5);
   checkit_double(r.dir.y,3.5);
   checkit_double(r.dir.z,4.5);
   
   struct ray r2 = create_ray(create_point(3.4,4.5,2.5),create_vector(1.1,4.1,5.1));
   checkit_double(r2.p.x, 3.4);
   checkit_double(r2.p.y, 4.5);
   checkit_double(r2.p.z, 2.5);
   checkit_double(r2.dir.x,1.1);
   checkit_double(r2.dir.y,4.1);
   checkit_double(r2.dir.z,5.1);
}
Beispiel #16
0
 point_type create_point(const osmium::NodeRef& node_ref) {
     try {
         return create_point(node_ref.location());
     } catch (osmium::geometry_error& e) {
         e.set_id("node", node_ref.ref());
         throw;
     }
 }
Beispiel #17
0
void test_sphere_normal_at_point(void){
   struct sphere s = create_sphere(create_point(4.2,3.5,6.5),5.715767665);
   struct point p = create_point(5.3,2.4,5.4);
   struct vector v = sphere_normal_at_point(s,p);
   checkit_double(v.x,.57735);
   checkit_double(v.y,-.57735);
   checkit_double(v.z,-.57735);

   struct sphere s2 = create_sphere(create_point(1.2,0,0),4.45);
   struct point p2 = create_point(6.65,0,0);
   struct vector v2 = sphere_normal_at_point(s2,p2);
   checkit_double(v2.x,1);
   checkit_double(v2.y,0);
   checkit_double(v2.z,0);



}
Beispiel #18
0
int main(int argc, char** argv) {
    
//    if(argc != 7){
//        printf("not a triangle");
//        return 0;
//    }
    
    Point points[3];
    points[0] = create_point(argv[1], argv[2]);
    points[1] = create_point(argv[3], argv[4]);
    points[2] = create_point(argv[5], argv[6]);
    
    char* triangle_type = find_triangle_type(points);
    
    printf("%s\n", triangle_type);

    return (EXIT_SUCCESS);
}
Beispiel #19
0
int read_config_file(EllipticCurveParameter *parameters, const char* filename)
{
    FILE *fp;
    fp = fopen(filename, "r");
    if(fp == NULL)
    {
	    return CONFIG_COULD_NOT_OPEN_FILE;
    }

    char buf[BUFFER_SIZE];
    
    int i = 0;
    BigInt p, a, b, g_x, g_y, n, h;
    Point g;
    while (fgets (buf, sizeof(buf), fp) != NULL)
    {
	    int length = strlen(buf);
	    // remove \n
	    buf[length-1] = '\0';
	    char *key;
	    char *val;
	
	    if(parse_line(buf, &key, &val) && is_valid_key(key, i))
	    {
	        if(!is_valid_hex_string(val))
	        {
		        fclose(fp);
		        return CONFIG_INVALID_FORMAT;
	        }
	        switch(i)
	        {
	            case 0: p = bigint_from_hex_string(BI_PARAMS_P_TAG, val); break;
	            case 1: a = bigint_from_hex_string(BI_PARAMS_A_TAG, val); break;
	            case 2: b = bigint_from_hex_string(BI_PARAMS_B_TAG, val); break;
	            case 3: g_x = bigint_from_hex_string(BI_PARAMS_GX_TAG, val); break;
	            case 4: g_y = bigint_from_hex_string(BI_PARAMS_GY_TAG, val); break;
	            case 5: n = bigint_from_hex_string(BI_PARAMS_N_TAG, val); break;
	            case 6: h = bigint_from_hex_string(BI_PARAMS_H_TAG, val); break;
	        }
	    }
	    else
	    {
	        fclose(fp);
	        return CONFIG_INVALID_FORMAT;
	    }
	    ++i;
	    free(key);
	    free(val);
    }

    create_point(&g, g_x, g_y);
    ec_create_parameters(parameters, p, a, b, &g, n, h);

    fclose(fp);
    return CONFIG_SUCCESS;
}
Beispiel #20
0
void
toggle_polyline_polygon(F_line *line, F_point *previous_point, F_point *selected_point)
{
  F_point *point, *last_pt;
  
  last_pt = last_point(line->points);

  if (line->type == T_POLYLINE)
    {

      if (line->points->next == NULL || line->points->next->next == NULL) {
	  put_msg("Not enough points for a polygon");
	  beep();
	  return;  /* less than 3 points - don't close the polyline */
      }
      if ((point = create_point()) == NULL)
	  return;
      
      point->x = last_pt->x;
      point->y = last_pt->y;
      point->next = line->points;
      line->points = point;
      
      line->type = T_POLYGON;
      clean_up();
      set_last_arrows(line->for_arrow, line->back_arrow);
      line->back_arrow = line->for_arrow = NULL;
    }
  else if (line->type == T_POLYGON)
    {
      point = line->points;
      line->points = point->next;           /* unchain the first point */
      free((char *) point);
            
      if ((line->points != selected_point) && (previous_point != NULL))
	{
	  last_pt->next = line->points;     /* let selected point become */
	  previous_point->next = NULL;      /* first point */
	  line->points = selected_point;
	}
      line->type = T_POLYLINE;
      clean_up();
    }
  redisplay_line(line);
  set_action_object(F_OPEN_CLOSE, O_POLYLINE);
  set_last_selectedpoint(line->points);
  set_last_prevpoint(NULL);
  set_latestline(line);
  set_modifiedflag();
}
Beispiel #21
0
struct light input_light(int argc, char *in[]){
   int i = 0;
   while(strcmp(in[i],"-light")!= 0){
      if(i>=argc-1)
         return create_light(create_point(-100,100,-100),create_color(1.5,1.5,1.5));
      i++;
   }
   double x = -100;
   double y = 100;
   double z = -100;
   
   double r = 1.5;
   double g = 1.5;
   double b = 1.5;

   if(i+1<argc && !equalToFlag(argc,in,i+1))
      x = convert_double(in[i+1],-100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 
 
   if(i+2<argc && !equalToFlag(argc,in,i+2))
      y = convert_double(in[i+2],100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+3<argc && !equalToFlag(argc,in,i+3))
      z = convert_double(in[i+3],-100);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+4<argc && !equalToFlag(argc,in,i+4))
      r = convert_double(in[i+4],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 
   
   if(i+5<argc && !equalToFlag(argc,in,i+5))
      g = convert_double(in[i+5],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   if(i+6<argc && !equalToFlag(argc,in,i+6))
      b = convert_double(in[i+6],1.5);
   else 
      return create_light(create_point(x,y,z),create_color(r,g,b)); 

   return create_light(create_point(x,y,z),create_color(r,g,b)); 
}
Beispiel #22
0
/**
 * Also has depth buffering and ignores points where normals point away
 *
 * Points a, b, c are in NDC
 */
void raster_triangle_Phong(point *a, point *b, point *c,
		point *world_a, point *world_b, point *world_c,
		point *normal_a, point *normal_b, point *normal_c,
		object_copy *obj, vector<light> *lights, camera *CAM,
		int xres, int yres, color** grid, float** depth_grid,
		MatrixXd *perspective, MatrixXd *inv_cam) {

	point screen_a = NDC_to_screen(a, xres, yres);
	point screen_b = NDC_to_screen(b, xres, yres);
	point screen_c = NDC_to_screen(c, xres, yres);

	float x_min = min_x(&screen_a, &screen_b, &screen_c);
	float x_max = max_x(&screen_a, &screen_b, &screen_c);
	float y_min = min_y(&screen_a, &screen_b, &screen_c);
	float y_max = max_y(&screen_a, &screen_b, &screen_c);

	x_max = x_max > xres ? xres : x_max;
	y_max = y_max > yres ? yres : y_max;
	x_min = x_min < 0 ? 0 : x_min;
	y_min = y_min < 0 ? 0 : y_min;

	// TODO: compute colors by normals

	for (int x = x_min; x < x_max; x++) {
		for (int y = y_min; y < y_max; y++) {
			// get alpha/beta/gamma
			point curr_point = create_point(x, y, 0);
			float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point);
			float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point);
			float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point);
			curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z;

			// compute interpolated point (in world view) and normal for the point
			point normal = (*normal_a) * alpha + (*normal_b) * beta + (*normal_c) * gamma;
			point coordinate = (*world_a) * alpha + (*world_b) * beta + (*world_c) * gamma;
			point ndc_coordinate = to_NDC(&coordinate, perspective, inv_cam);

			if (is_in_box(&ndc_coordinate) && valid_parameters(alpha, beta, gamma)
					&& depth_grid[x][y] > curr_point.z) {
				color col = lighting(&coordinate, &normal, obj, lights, CAM);
				grid[x][y].r = col.r;
				grid[x][y].g = col.g;
				grid[x][y].b = col.b;

				depth_grid[x][y] = curr_point.z;
			}
		}
	}
}
Beispiel #23
0
static void
tangent_normal_line(int x, int y, float vx, float vy)
{
    int dx, dy, xl, yl, xr, yr;
    F_line	   *line;
 
    dx = round(vx);
    dy = round(vy);   

    xl = x - dx;
    yl = y - dy;
    xr = x + dx;
    yr = y + dy;

    if ((first_point = create_point()) == NULL) 
        return;
    cur_point = first_point;
    first_point->x = xl;
    first_point->y = yl;
    first_point->next = NULL;
    append_point(x, y, &cur_point);
    append_point(xr, yr, &cur_point);
    
    if ((line = create_line()) == NULL)
        return; /* an error occured */
    line->type = T_POLYLINE;
    line->style = cur_linestyle;
    line->thickness = cur_linewidth;
    line->pen_color = cur_pencolor;
    line->fill_color = cur_fillcolor;
    line->depth = cur_depth;
    line->pen_style = -1;
    line->join_style = cur_joinstyle;
    line->cap_style = cur_capstyle;
    line->fill_style = cur_fillstyle;
    line->style_val = cur_styleval * (cur_linewidth + 1) / 2;
    line->points = first_point;
		/* polyline; draw any arrows */
    if (autoforwardarrow_mode)
	line->for_arrow = forward_arrow();
    /* arrow will be drawn in draw_line below */
    if (autobackwardarrow_mode)
	line->back_arrow = backward_arrow();
    /* arrow will be drawn in draw_line below */
    draw_line(line, PAINT);	/* draw final */
    add_line(line);
    toggle_linemarker(line);
}
struct maybe_point sphere_intersection_point(struct ray r, struct sphere s)
{
    double a = dot_vector(r.dir, r.dir);
    double b = 2 * dot_vector(difference_point(r.p, s.center), r.dir);
    double c = dot_vector(difference_point(r.p, s.center),
                          difference_point(r.p, s.center)) - (s.radius * s.radius);
    double disc = discriminant(a, b, c);
    double pos_result = pos_quadratic(a, b, c);
    double neg_result = neg_quadratic(a, b, c);
    double result;

    if (disc < 0)
    {
        return create_maybe_point(0, create_point(0.0, 0.0, 0.0));
    }
    if (pos_result > 0 && neg_result > 0)
    {
        if (pos_result < neg_result)
        {
            result = pos_result;
        }
        else
        {
            result = neg_result;
        }
    }
    else if (pos_result > 0)
    {
        result = pos_result;
    }
    else if (neg_result > 0)
    {
        result = neg_result;
    }
    else
    {
        result = -1;
    }
    if (result > 0)
    {   /*point is valid*/
        return create_maybe_point(1, translate_point(r.p, scale_vector(r.dir, result)));
    }
    else
    {   /* point is invalid*/
        return create_maybe_point(0, translate_point(r.p, scale_vector(r.dir, result)));
    }
}
Beispiel #25
0
void test_find_intersection_points(void){
   struct sphere s1 = create_sphere(create_point(4.2,0,0),1.3);
   struct sphere s2 = create_sphere(create_point(2.6,0,0),5.4);
   struct ray r = create_ray(create_point(-23.2,0,0),create_vector(.2,0,0));
   struct sphere spheres[2] = {s1,s2};
   struct sphere hit[2];
   struct point pts[2];
   checkit_int(find_intersection_points(spheres,2,r,hit,pts),2);
   checkit_double(pts[0].x, 2.9);
   checkit_double(pts[0].y, 0);
   checkit_double(pts[0].z, 0);
   checkit_double(pts[1].x, -2.8);
   checkit_double(pts[1].y, 0);
   checkit_double(pts[1].z, 0);
   checkit_double(hit[0].center.x, 4.2);
   checkit_double(hit[0].center.y, 0);
   checkit_double(hit[0].center.z, 0);
   checkit_double(hit[0].radius, 1.3);
   checkit_double(hit[1].center.x, 2.6);
   checkit_double(hit[1].center.y, 0);
   checkit_double(hit[1].center.z, 0);
   checkit_double(hit[1].radius, 5.4);

   struct sphere s3 = create_sphere(create_point(4.5,1.4,3.2),1.8);
   struct sphere s4 = create_sphere(create_point(2,4.3,5.4),3.2);
   struct sphere s5 = create_sphere(create_point(2.9,3.4,2.1),2.3);
   struct ray r2 = create_ray(create_point(1,1.3,.5),create_vector(1.3,1.4,1.8));
   struct sphere spheres2[3] = {s3,s4,s5};
   struct sphere hit2[3];
   struct point pts2[3];
   checkit_int(find_intersection_points(spheres2,3,r2,hit2,pts2),2);

   checkit_double(pts2[0].x, 2.489528);
   checkit_double(pts2[0].y, 2.904107);
   checkit_double(pts2[0].z, 2.562423);  
   checkit_double(pts2[1].x, 1.492227);
   checkit_double(pts2[1].y, 1.830091);
   checkit_double(pts2[1].z, 1.181545);

   checkit_double(hit2[0].center.x, 2);
   checkit_double(hit2[0].center.y, 4.3);
   checkit_double(hit2[0].center.z, 5.4);
   checkit_double(hit2[0].radius, 3.2);
   checkit_double(hit2[1].center.x, 2.9);
   checkit_double(hit2[1].center.y, 3.4);
   checkit_double(hit2[1].center.z, 2.1);
   checkit_double(hit2[1].radius, 2.3);

}
Beispiel #26
0
void point_list_insert(CHpoints **PL, Point p) {
  CHpoints *temp;
  
  CHno++;                       /* increase the number of CHnodes by one */  
  temp=create_point(p);
  if ((*PL)==NULL) {
    temp->prev = temp;
    temp->next = temp;
    *PL=temp; }
  else {
    temp->next = *PL;
    (*PL)->prev->next = temp;
    temp->prev = (*PL)->prev;
    (*PL)->prev = temp;
    (*PL)=temp; }
  
}
Beispiel #27
0
void
init_trace_drawing(int x, int y)
{
    if ((first_point = create_point()) == NULL)
	return;

    cur_point = first_point;
    set_action_on();
    cur_point->x = fix_x = cur_x = x;
    cur_point->y = fix_y = cur_y = y;
    cur_point->next = NULL;
    canvas_leftbut_proc = (FCallBack)get_intermediatepoint;
    if (freehand_line) {
	canvas_locmove_proc = freehand_get_intermediatepoint;
    } else {
	/* only two points in a dimension line */
	if (dimension_line)
	    canvas_leftbut_proc = (FCallBack)create_lineobject;
	if (latexline_mode || latexarrow_mode) {
	    canvas_locmove_proc = latex_line;
	} else if (manhattan_mode || mountain_mode) {
	    canvas_locmove_proc = constrainedangle_line;
	} else {
	    canvas_locmove_proc = unconstrained_line;
	}
    }
    canvas_middlebut_save = create_lineobject;
    canvas_rightbut_proc = (FCallBack)cancel_line_drawing;
    return_proc = line_drawing_selected;
    num_point = 1;
    set_mousefun("next point", "", "cancel", "del point", "", "");
    if (dimension_line) {
	set_mousefun("final point", "", "cancel", "del point", "", "");
	canvas_middlebut_proc = (FCallBack)null_proc;
    } else if (num_point >= min_num_points - 1) {
	set_mousefun("next point", "final point", "cancel", "del point", "", "");
	canvas_middlebut_proc = (FCallBack)canvas_middlebut_save;
    }
	
    draw_mousefun_canvas();
    set_cursor(null_cursor);
    elastic_line();
}
Beispiel #28
0
 result_type operator()(T0 geom_type, T1 & coord, T2 & arcs, T3 & props) const
 {
     switch (geom_type)
     {
     case 1: //Point
         return create_point()(coord, props);
     case 2: //LineString
         return create_line_string()(arcs, props);
     case 3: //Polygon
         return create_polygon()(arcs, props);
     case 4: //MultiPoint
         return create_multi_point()(coord, props);
     case 5: //MultiLineString
         return create_multi_line_string()(arcs, props);
     case 6: //MultiPolygon
         return create_multi_polygon()(arcs, props);
     default:
         break;
     }
     return mapnik::topojson::geometry(); //empty
 }
Beispiel #29
0
int main(void) {
  llist* list = create_list();
  lnode* new_node;
  lnode* found_node;
  point* p = create_point(0, 0);
  list->head = NULL;

  /* test case 1 - what does an empty list contain? */
  printf("TEST CASE 1\n");
  traverse(list, print_point_node);
  printf("\n");

  /* test case 2 - what happens when you add a node to the
     front of an empty list? */
  printf("TEST CASE 2\n");
  new_node = create_node(create_point(2,5));
  add_front(list, new_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 3 - what happens when you add a node to the front
     of a list with one node? */
  printf("TEST CASE 3\n");
  new_node = create_node(create_point(3,7));
  add_front(list, new_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 4 - what happens when you add a node to the front
     of a list with more than one node? */
  printf("TEST CASE 4\n");
  new_node = create_node(create_point(1,4));
  add_front(list, new_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 5 - what happens when you remove a node from the front
     of a list with more than one node? */
  printf("TEST CASE 5\n");
  remove_front(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 6 - what happens when you remove a node from the front
     of a list with one node? */
  printf("TEST CASE 6\n");
  remove_front(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 7 - what happens when you remove a node from the front
     of an empty list? */
  printf("TEST CASE 7\n");
  remove_front(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 8 - what happens when you add a node to the
     back of an empty list? */
  printf("TEST CASE 8\n");
  new_node = create_node(create_point(2,5));
  add_back(list, new_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 9 - what happens when you add a node to the back
     of a list with one node? */
  printf("TEST CASE 9\n");
  new_node = create_node(create_point(3,7));
  add_back(list, new_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 10 - what happens when you add a node to the back
     of a list with more than one node? */
  printf("TEST CASE 10\n");
  new_node = create_node(create_point(1,4));
  add_back(list, new_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 11 - what happens when you remove a node from the back
     of a list with more than one node? */
  printf("TEST CASE 11\n");
  remove_back(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 12 - what happens when you remove a node from the back
     of a list with one node? */
  printf("TEST CASE 12\n");
  remove_back(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 13 - what happens when you remove a node from the back
     of an empty list? */
  printf("TEST CASE 13\n");
  remove_back(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 14 - what happens when you try to find an occurrence
     of a given data point in an empty list? */
  printf("TEST CASE 14\n");
  p->x = 3;
  p->y = 7;
  found_node = find_occurrence(list, p, compare_point_data);
  print_point_node(found_node);
  printf("\n");

  /* test case 15 - what happens when you try to find an occurrence
     of a given data point in a list of that one node? */
  printf("TEST CASE 15\n");
  p->x = 3;
  p->y = 7;
  new_node = create_node(create_point(3, 7));
  add_front(list, new_node);
  found_node = find_occurrence(list, p, compare_point_data);
  print_point_node(found_node);
  printf("\n");
  
  /* test case 16 - what happens when you try to find an occurrence
     of a given data point in a list of one different node? */
  printf("TEST CASE 16\n");
  p->x = 5;
  p->y = 14;
  found_node = find_occurrence(list, p, compare_point_data);
  print_point_node(found_node);
  printf("\n");

  /* test case 17 - what happens when you try to find an occurrence
     of a given data point in a list of lots of nodes (one matching)?
     NOTE: if your list contains multiple nodes with matching data,
     returning any of them is fine.
  */
  printf("TEST CASE 17\n");
  new_node = create_node(create_point(5,2));
  add_front(list, new_node);
  new_node = create_node(create_point(6,30));
  add_back(list, new_node);
  new_node = create_node(create_point(1,1));
  add_front(list, new_node);
  p->x = 3;
  p->y = 7;
  found_node = find_occurrence(list, p, compare_point_data);
  print_point_node(found_node);
  printf("\n");

  /* test case 18 - what happens when you try to find an occurrence
     of a given data point in a list of lots of nodes (none matching)? */
  printf("TEST CASE 18\n");
  p->x = 5;
  p->y = 14;
  found_node = find_occurrence(list, p, compare_point_data);
  print_point_node(found_node);
  printf("\n");

  /* test case 19 - what happens when you try to free a list
     of lots of nodes? YOU WILL HAVE TO RUN VALGRIND TO MAKE
     SURE YOU GET NO ERRORS HERE. Memory leaks are otherwise
     invisible!
  */
  printf("TEST CASE 19\n");
  free_list(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 20 - what happens when you try to free a list
     of one node? YOU WILL HAVE TO RUN VALGRIND TO MAKE
     SURE YOU GET NO ERRORS HERE. 
  */
  printf("TEST CASE 20\n");
  new_node = create_node(create_point(7,14));
  add_front(list, new_node);
  free_list(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");

  /* test case 21 - what happens when you try to free an empty list?
     YOU WILL HAVE TO RUN VALGRIND TO MAKE SURE YOU GET NO ERRORS HERE.
  */
  printf("TEST CASE 21\n");
  free_list(list, free_point_node);
  traverse(list, print_point_node);
  printf("\n");
  

	free(p);
  free(list);
  return 0;
}
Beispiel #30
0
 point_type create_point(const osmium::NodeRef& node_ref) {
     return create_point(node_ref.location());
 }