// Calculate one step and max corrections double calculation(const int iterate) { // Vt + Vr + Vb + Vl - 4Vx = 0 int y, x; double maxStepSize, pde, stepSize; d("Calculation step (iterate: %d)", iterate); maxStepSize = 0; for (y = 1; y < segment_size_y - 1; ++y) { for (x = 1; x < segment_size_x - 1; ++x) { // We're using checkerboard to calculate values. if ((y + x + iterate) % 2 == 0 || is_outside(x, y) || is_wire(x, y) ) { continue; } pde = data[bottom_point(x, y)] + data[top_point(x, y)] + data[left_point(x, y)] + data[right_point(x, y)]; pde *= .25; stepSize = abs(pde - data[y * segment_size_x + x]); if (stepSize > maxStepSize) { maxStepSize = stepSize; } data[y * segment_size_x + x] = pde; } } return maxStepSize; }
void process_point(){ /* debug_printf("process_point_s"); */ // Get the next point at the top of the queue (with smaller x coordinate) point_t p = top_point(); pop_point(); front_insert(p); /* debug_printf("process_point_end"); */ }
void generate_voronoi(struct point *p_array, int num){ init_voronoi(); // printf("init memory succed\n"); X0=0; Y0=0; X1=2000; Y1=2000; if(num >= POINT_POOL_SIZE){ v_error("the number of points is out of bound"); return; } int i; for (i=0; i<num; i++){ push_point(p_array[i]); // printf("%f, %f\n", p_array[i].x, p_array[i].y); if(p_array[i].x < X0) X0 = p_array[i].x; if(p_array[i].y < Y0) Y0 = p_array[i].y; if(p_array[i].x > X1) X1 = p_array[i].x; if(p_array[i].y > Y1) Y1 = p_array[i].y; } add_virtual_obstacles(); points_quicksort(); /* X0=0; */ /* Y0=0; */ /* X1=2500; */ /* Y1=2500; */ // printf("quicksort finished \n"); // printf("%f, %f, %f, %f\n\n\n", X0, Y0, X1,Y1); //add 20% margins to the bounding box /* double dx = (X1-X0+1)/5.0; */ /* double dy = (Y1-Y0+1)/5.0; */ /* X0 -= dx; */ /* X1 += dx; */ /* Y0 -= dy; */ /* Y1 += dy; */ // printf("%f, %f, %f, %f\n\n\n", X0, Y0, X1,Y1); while (!is_pp_empty()){ if(!is_ep_empty()){ event_t * top_e = top_event(); point_t top_p = top_point(); if(top_e->x <= top_p.x){ process_event(); }else{ process_point(); } }else{ process_point(); } } // print_arc_list(); while(!is_ep_empty()){ process_event(); } finish_edges(); rebuild_seg_list(&seg_list); int k; char *buf=malloc(sizeof(char)*1024); int pcount=0; for(k=0;k<seg_list.segs_count;k++){ pcount+=sprintf(&buf[pcount],"%d;%d;%d;%d",k,seg_list.segs[k]->start.x,seg_list.segs[k]->start.y,seg_list.segs[k]->end.x,seg_list.segs[k]->end.y); } send_raw_eth_chn(34,buf,603); }