int find_displacement(struct cars *car1, struct cars *car2, float *rx, float *ry) { if (car1 == NULL || car2 == NULL || car1 == car2) { return -1; } float x, y, w, h; x = car1->my_car.car_x - (car1->my_car.car->w/2) - (car2->my_car.car_x + (car2->my_car.car->w/2)); y = car1->my_car.car_y - (car1->my_car.car->h/2) - (car2->my_car.car_y + (car2->my_car.car->h/2)); w = car1->my_car.car->w + car2->my_car.car->w; h = car1->my_car.car->h + car2->my_car.car->h; struct points *p1 = NULL; struct points *p2 = NULL; p1 = get_coords(&car1->my_car); p2 = get_coords(&car2->my_car); struct points *diff = NULL; diff = minkowski_difference(p1, p2); struct points *hull = NULL; hull = convex_hull(diff); mk_minimum_displacement(hull, rx, ry); free_points(&p1); free_points(&p2); free_points(&diff); free_points(&hull); return 0; }
my_bool CRT_GAMAL_SUM_160_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { // For each row, the current value is added to the sum EC_POINT **curR, **curS; int numCiphers; sum_state *state = (sum_state *) initid->ptr; size_t encodedLength = (size_t) args->lengths[0]; char *encoded = (char *) args->args[0]; if(check_encoding_size(encodedLength)) { strcpy(error, "Wrong Cipher Size"); return 1; } numCiphers = get_num_points(encodedLength); if(state->isFirst) { init_sum_state(state, numCiphers); } else { if(numCiphers!=state->numCiphers) { strcpy(error, "Number of ciphers missmatch"); return 1; } } if(decode_points(state->group, encoded, encodedLength, numCiphers, &curR, &curS)) { strcpy(error, "Error while decoding"); return 1; } add_points_up(state->group,state->curSumR, state->curSumS, state->curSumR, state->curSumS, curR, curS, state->numCiphers); free_points(curR, curS, numCiphers); return 0; }
void free_sum_state(sum_state *state) { if(state->numCiphers>0) { EC_GROUP_free(state->group); free_points(state->curSumR, state->curSumS, state->numCiphers); } free(state); }
void get_intermediatepoint(int x, int y, int shift) { /* in freehand mode call unconstrained_line explicitely to move the mouse */ if (freehand_line) { unconstrained_line(x,y); /* pointer must move by at least freehand_resolution in any direction */ if (abs(fix_x-cur_x) < appres.freehand_resolution && (abs(fix_y-cur_y) < appres.freehand_resolution)) return; } else { /* otherwise call the (possibly) constrained movement procedure */ (*canvas_locmove_proc) (x, y); } /* don't allow coincident consecutive points */ if (fix_x == cur_x && fix_y == cur_y) return; num_point++; fix_x = cur_x; fix_y = cur_y; elastic_line(); if (cur_cursor != null_cursor) { set_cursor(null_cursor); } if (shift && num_point > 2) { F_point *p; num_point -= 2; p = prev_point(first_point, cur_point); p->next = NULL; /* erase the newest segment */ pw_vector(canvas_win, fix_x, fix_y, cur_point->x, cur_point->y, INV_PAINT, 1, RUBBER_LINE, 0.0, DEFAULT); /* and segment drawn before */ pw_vector(canvas_win, p->x, p->y, cur_point->x, cur_point->y, INV_PAINT, 1, RUBBER_LINE, 0.0, DEFAULT); /* and draw new elastic segment */ pw_vector(canvas_win, fix_x, fix_y, p->x, p->y, PAINT, 1, RUBBER_LINE, 0.0, DEFAULT); fix_x = p->x; fix_y = p->y; free_points(cur_point); cur_point = p; } else { append_point(fix_x, fix_y, &cur_point); } if (num_point == min_num_points - 1) { if (freehand_line) set_mousefun("", "final point", "cancel", "del point", "", ""); else set_mousefun("next point", "final point", "cancel", "del point", "", ""); draw_mousefun_canvas(); canvas_middlebut_proc = (FCallBack)canvas_middlebut_save; } }
void free_splinestorage(F_spline *s) { free_points(s->points); free_sfactors(s->sfactors); if (s->for_arrow) free((char *) s->for_arrow); if (s->back_arrow) free((char *) s->back_arrow); if (s->comments) free(s->comments); free((char *) s); }
int main() { data_adapter_t da; unsigned char file_name[][64] = { "test.pcd1", "test.jpg", "test.gif", "/data/local/tmp/test.sprite" }; da_open(&da, file_name[3], W, H, E_DWRITE); //data_adapter_t *da, e_uint8 *name, int mode point_array = malloc_points(PNT_TYPE_GRAY,H); points_gray = (point_gray_t*)point_array->mem; for (int i = 0; i < H; i++) points_gray[i].gray = 80; for (int i = 0; i < W; i++) da_write_column(&da,i, point_array, 0); for (int i = 0; i < H; i++) points_gray[i].gray = 160; for (int i = 0; i < W; i++) da_write_column(&da, W - i - 1, point_array, 1); // point_array = malloc_points(PNT_TYPE_XYZ, H); // points = (point_xyz_t*) point_array->mem; // // for (int i = 0; i < H; i++) { // points[i].x = H * sin(i * M_PI / H); // points[i].y = H * cos(i * M_PI / H); // points[i].z = H * sin(M_PI - i * M_PI / H); // } // // for (int i = 0; i < W; i++) // da_append_points(&da, point_array, H, 0); // // for (int i = 0; i < H; i++) { // points[i].x += 100; // points[i].y += 100; // points[i].z += 100; // } // // for (int i = 0; i < W; i++) // da_append_points(&da, point_array, H, 1); // da_close(&da); free_points(point_array); printf("ALL TEST PASSED!\n"); return 0; }
void cancel_line_drawing(int a, int b) { elastic_line(); /* erase last lengths if appres.showlengths is true */ erase_lengths(); cur_x = fix_x; cur_y = fix_y; if (cur_point != first_point) elastic_moveline(first_point); /* erase control vector */ free_points(first_point); first_point = NULL; return_proc(); draw_mousefun_canvas(); }
int main(void){ //tests(); POLYGON temp; assert(get_size(&temp.size_points)==TRUE); alloc_points(&temp.max_of_x,&temp.points,temp.size_points); temp.segments=create_segments(temp.size_points); add_segments(temp.points,temp.segments,temp.size_points); draw_polygon(temp); triangulal_polygol(temp); printf("Potrzeba %d straznikow\n",coloring_sl(temp.points,temp.segments,temp.size_points)); print_colors(temp.points,temp.size_points); draw_polygon(temp); free_segments(temp.segments,temp.size_points); free_points(temp.points); return EXIT_SUCCESS; }
void free_linestorage(F_line *l) { free_points(l->points); if (l->for_arrow) free((char *) l->for_arrow); if (l->back_arrow) free((char *) l->back_arrow); if (l->pic) { free_picture_entry(l->pic->pic_cache); if (l->pic->pixmap != 0) XFreePixmap(tool_d, l->pic->pixmap); l->pic->pixmap = (Pixmap) 0; if (l->pic->mask != 0) XFreePixmap(tool_d, l->pic->mask); l->pic->mask = (Pixmap) 0; free((char *) l->pic); } if (l->comments) free(l->comments); free((char *) l); }
void Vehicle::crossover(Vehicle *veh1, Vehicle *veh2, Vehicle *veh3, Vehicle *veh4) { // Преобразование машины в ДНК QVector <double> dna1 = (veh1 -> getDNA()); QVector <double> dna2 = (veh2 -> getDNA()); QVector <double> dna3(dna1.size()); QVector <double> dna4(dna1.size()); int sz = std::min(dna1.size(), dna2.size()); int point_num = veh1 -> pointsNum; // Сам кроссинговер int minLength = (dna1.size() < dna2.size()) ? dna1.size() : dna2.size(); int rnd_point = qrand() % minLength; for(int i = 0; i < rnd_point; ++i) { double tmp = dna1[i]; dna1[i] = dna2[i]; dna2[i] = tmp; } switch(recombinationType) { case Genetic::DISCRETE: { for(int i = 0; i < sz; ++i) { if(rand() & 1) { dna3[i] = dna1[i]; } else { dna3[i] = dna2[i]; } if(rand() & 1) { dna4[i] = dna1[i]; } else { dna4[i] = dna2[i]; } } break; } case Genetic::INTERMEDIATE: { for(int i = 0; i < sz; ++i) { double alpha1 = static_cast<double>(rand() % 1000) / 1000.0 * (1.0 + 2.0 * recombine_param) - recombine_param; double alpha2 = static_cast<double>(rand() % 1000) / 1000.0 * (1.0 + 2.0 * recombine_param) - recombine_param; double v[2]; v[0] = dna1[i] + alpha1 * (dna2[i] - dna1[i]); v[1] = dna1[i] + alpha2 * (dna2[i] - dna1[i]); dna3[i] = v[0]; dna4[i] = v[1]; } break; } case Genetic::LINE: { double alpha1 = static_cast<double>(rand() % 1000) / 1000.0 * (1.0 + 2.0 * recombine_param) - recombine_param; double alpha2 = static_cast<double>(rand() % 1000) / 1000.0 * (1.0 + 2.0 * recombine_param) - recombine_param; for(int i = 0; i < sz; ++i) { double v[2]; v[0] = dna1[i] + alpha1 * (dna2[i] - dna1[i]); v[1] = dna1[i] + alpha2 * (dna2[i] - dna1[i]); dna3[i] = v[0]; dna4[i] = v[1]; } break; } case Genetic::CROSSOVER: { int crossover_points_num = recombine_param; assert(sz > 1); assert(sz >= crossover_points_num); assert(crossover_points_num > 0); // Setting dividing points std::vector <int> free_points(sz); std::vector <int> crossover_points(crossover_points_num); for(int i = 0; i < free_points.size(); ++i) { free_points[i] = i; } for(int i = 0; i < crossover_points_num; ++i) { int choosed_point_id = rand() % free_points.size(); int choosed_point = free_points[choosed_point_id]; free_points.erase(free_points.begin() + choosed_point_id); crossover_points[i] = choosed_point; } std::sort(crossover_points.begin(), crossover_points.end()); if(crossover_points[crossover_points.size() - 1] != sz - 1) { crossover_points.push_back(dna1.size() - 1); } int last_crossover_point = 0; int next_crossover_point; bool current_inverse = false; for(int i = 0; i < crossover_points.size(); ++i) { int crossover_point = crossover_points[i]; next_crossover_point = (i < crossover_points_num - 1) ? crossover_points[i + 1] : sz; if(current_inverse) { for(int j = last_crossover_point; j <= crossover_point; ++j) { dna3[j] = dna2[j]; dna4[j] = dna1[j]; } } else { for(int j = last_crossover_point; j <= crossover_point; ++j) { dna3[j] = dna1[j]; dna4[j] = dna2[j]; } } last_crossover_point = crossover_point; current_inverse = !current_inverse; } break; } case Genetic::UNIFORM_CROSSOVER: { for(int i = 0; i < sz; ++i) { if(rand() & 1) { dna1[i] = dna1[i]; dna2[i] = dna2[i]; } else { dna1[i] = dna2[i]; dna2[i] = dna1[i]; } } break; } case Genetic::SHUFFLER_CROSSOVER: { for(int i = 0; i < sz; ++i) { if(rand() & 1) { std::swap(dna1[i], dna2[i]); } } // recombine(parent_Individual1, parent_Individual2, // child_Individual1, child_Individual2, &ts); for(int i = 0; i < sz; ++i) { if(rand() & 1) { std::swap(dna1[i], dna2[i]); } } break; } } // // Пересчитывается количество колёс, чтобы не привысить максимальное. // QVector <int> veh1Wheels; // QVector <int> veh2Wheels; // Восстановление машин из ДНК for(int i = 0; i < point_num; ++i) { veh1 -> vectors[i].angle = dna1[i * 8]; veh1 -> vectors[i].length = dna1[i * 8 + 1]; veh1 -> vectors[i].r = dna1[i * 8 + 2]; veh1 -> vectors[i].g = dna1[i * 8 + 3]; veh1 -> vectors[i].b = dna1[i * 8 + 4]; veh1 -> vectors[i].wheel = dna1[i * 8 + 5]; veh1 -> vectors[i].radius = dna1[i * 8 + 6]; veh1 -> vectors[i].motorSpeed = dna1[i * 8 + 7]; veh2 -> vectors[i].angle = dna2[i * 8]; veh2 -> vectors[i].length = dna2[i * 8 + 1]; veh2 -> vectors[i].r = dna2[i * 8 + 2]; veh2 -> vectors[i].g = dna2[i * 8 + 3]; veh2 -> vectors[i].b = dna2[i * 8 + 4]; veh2 -> vectors[i].wheel = dna2[i * 8 + 5]; veh2 -> vectors[i].radius = dna2[i * 8 + 6]; veh2 -> vectors[i].motorSpeed = dna2[i * 8 + 7]; veh3 -> vectors[i].angle = dna3[i * 8]; veh3 -> vectors[i].length = dna3[i * 8 + 1]; veh3 -> vectors[i].r = dna3[i * 8 + 2]; veh3 -> vectors[i].g = dna3[i * 8 + 3]; veh3 -> vectors[i].b = dna3[i * 8 + 4]; veh3 -> vectors[i].wheel = dna3[i * 8 + 5]; veh3 -> vectors[i].radius = dna3[i * 8 + 6]; veh3 -> vectors[i].motorSpeed = dna3[i * 8 + 7]; veh4 -> vectors[i].angle = dna4[i * 8]; veh4 -> vectors[i].length = dna4[i * 8 + 1]; veh4 -> vectors[i].r = dna4[i * 8 + 2]; veh4 -> vectors[i].g = dna4[i * 8 + 3]; veh4 -> vectors[i].b = dna4[i * 8 + 4]; veh4 -> vectors[i].wheel = dna4[i * 8 + 5]; veh4 -> vectors[i].radius = dna4[i * 8 + 6]; veh4 -> vectors[i].motorSpeed = dna4[i * 8 + 7]; // Подсчёт количетсва колёс у каждого автомобиля // if(veh1 -> vectors[i].wheel) // { // veh1Wheels.push_back(i); // } // if(veh2 -> vectors[i].wheel) // { // veh2Wheels.push_back(i); // } // if(veh3 -> vectors[i].wheel) // { // veh3Wheels.push_back(i); // } // if(veh4 -> vectors[i].wheel) // { // veh4Wheels.push_back(i); // } } veh1 -> setDNA(dna1); veh2 -> setDNA(dna2); veh3 -> setDNA(dna3); veh4 -> setDNA(dna4); }
void draw_sphere(double x, double y, double z, double r, matrix * to_render) { struct point ** points = get_sphere_points(x, y, z, r); draw_triangles_in_sphere(points, to_render); free_points(points); }
float closestpoints(Points ps) { if (ps.size < 100) { return naive(ps); } float y = select_y(ps); // aboves = filter (above y) pts // belows = filter (below y) pts Points aboves = alloc_points(ps.size); int aboves_size = 0; Points belows = alloc_points(ps.size); int belows_size = 0; for (int i = 0; i != ps.size; ++i) { if (ps.ys[i] < y) { aboves.xs[aboves_size] = ps.xs[i]; aboves.ys[aboves_size] = ps.ys[i]; aboves_size++; } if (ps.ys[i] >= y) { belows.xs[belows_size] = ps.xs[i]; belows.ys[belows_size] = ps.ys[i]; belows_size++; } } aboves.size = aboves_size; belows.size = belows_size; float above_ = closestpoints(aboves); float below_ = closestpoints(belows); free_points(aboves); free_points(belows); float border = minf(above_, below_); // aboveB = filter (above y && below (y-border)) pts // belowB = filter (below y && above (y+border)) pts Points aboveB = alloc_points(ps.size); int aboveB_size = 0; Points belowB = alloc_points(ps.size); int belowB_size = 0; for (int i = 0; i != ps.size; ++i) { if (ps.ys[i] < y && ps.ys[i] >= (y-border)) { aboveB.xs[aboveB_size] = ps.xs[i]; aboveB.ys[aboveB_size] = ps.ys[i]; aboveB_size++; } if (ps.ys[i] >= y && ps.ys[i] < (y+border)) { belowB.xs[belowB_size] = ps.xs[i]; belowB.ys[belowB_size] = ps.ys[i]; belowB_size++; } } aboveB.size = aboveB_size; belowB.size = belowB_size; // dists = V.concatMap (\p -> V.map (dist p) belowB) aboveB float min = border; for (int i = 0; i != aboveB.size; ++i) { for (int j = 0; j != belowB.size; ++j) { float d = dist( aboveB.xs[i], aboveB.ys[i] , belowB.xs[j], belowB.ys[j] ); min = minf(min, d); } } free_points(aboveB); free_points(belowB); return min; }
int chk_mov_Tt (struct table_text *pt) { struct table_text *ptb,*ptab; if (pt == NULL) return 0; for (ptb=ptab=&Tt_tab; ptab!=NULL && cmpnbl(pt->name,ptab->name)!=0; ptb=ptab,ptab=ptab->next); /* Check if it's trying to overwrite the default. */ if (ptab == &Tt_tab) { err_warn(1,fperr,"Error - can't replace the default (Tt_%s).\n", pt->name); free((char *)pt); return 0; } if (ptab == NULL) { ptb->next=ptab=pt; } else { /* if (pt->txfont != ptab->txfont ) printf("txfont diff %d,%d\n",pt->txfont, ptab->txfont); */ /* if (pt->txpr != ptab->txpr) printf("txpr diff %d,%d\n",pt->txpr, ptab->txpr); */ /* if (pt->txexp != ptab->txexp ) printf("txexp diff\n"); */ /* if (pt->txsp != ptab->txsp) printf("txsp diff\n"); */ /* if ( pt->txci != ptab->txci ) printf("txci diff %d,%d\n",pt->txci, ptab->txci); */ /* if ( pt->priority != ptab->priority ) printf("priority diff\n"); */ /* if (ptab->tvp[0] != pt->tvp[0] || ptab->tvp[1] != pt->tvp[1] || */ /* ptab->tvp[2] != pt->tvp[2] || ptab->tvp[3] != pt->tvp[3] ) printf("tvp diff\n"); */ /* if ( ptab->twc[0] != pt->twc[0] || ptab->twc[1] != pt->twc[1] || */ /* ptab->twc[2] != pt->twc[2] || ptab->twc[3] != pt->twc[3] ) printf("twc diff\n"); */ /* if (compare_points(ptab->tx, pt->tx )!=1) printf("tx difff\n"); */ /* if (compare_points(ptab->ty, pt->ty )!=1) printf("ty difff\n"); */ /* if (compare_strings(ptab->ts, pt->ts )!=1) printf("ts diff %s %s\n",ptab->ts,pt->ts); */ /* if (strcmp(ptab->proj,pt->proj) != 0) printf("proj diff\n"); */ if (pt->txfont != ptab->txfont || pt->txpr != ptab->txpr || pt->txexp != ptab->txexp || pt->txsp != ptab->txsp || pt->txci != ptab->txci || pt->txfci != ptab->txfci || pt->priority != ptab->priority || ptab->tvp[0] != pt->tvp[0] || ptab->tvp[1] != pt->tvp[1] || ptab->tvp[2] != pt->tvp[2] || ptab->tvp[3] != pt->tvp[3] || ptab->twc[0] != pt->twc[0] || ptab->twc[1] != pt->twc[1] || ptab->twc[2] != pt->twc[2] || ptab->twc[3] != pt->twc[3] || compare_points(ptab->tx, pt->tx )!=1 || compare_points(ptab->ty, pt->ty )!=1 || compare_strings(ptab->ts, pt->ts )!=1 || (strcmp(ptab->proj,pt->proj) != 0) ) { strcpy(ptab->proj,pt->proj); ptab->txfont=pt->txfont; ptab->txpr=pt->txpr; ptab->txexp=pt->txexp; ptab->txsp=pt->txsp; ptab->txci=pt->txci; ptab->txfci=pt->txfci; ptab->priority=pt->priority; ptab->tvp[0]=pt->tvp[0]; ptab->tvp[1]=pt->tvp[1]; ptab->tvp[2]=pt->tvp[2]; ptab->tvp[3]=pt->tvp[3]; ptab->twc[0]=pt->twc[0]; ptab->twc[1]=pt->twc[1]; ptab->twc[2]=pt->twc[2]; ptab->twc[3]=pt->twc[3]; free_points( &ptab->tx ); free_points( &ptab->ty ); free_strings( &ptab->ts ); if (copy_points( &ptab->tx, pt->tx) == 0) return 0; if (copy_points( &ptab->ty, pt->ty) == 0) return 0; if (copy_strings( &ptab->ts, pt->ts) == 0) return 0; free_points( &pt->tx ); free_points( &pt->ty ); free_strings( &pt->ts ); check_d_text(ptab->name); } free((char *)pt); pt=NULL; } if (!Inactive && fpout != NULL) prtTt(fpout,ptab); return 1; }
int chk_mov_Tl (struct table_line *pt) { float deflt=1.0; struct table_line *ptb,*ptab; extern int copy_points(); extern void free_points(); if (pt == NULL) return 0; for (ptb=ptab=&Tl_tab; ptab!=NULL && cmpnbl(pt->name,ptab->name)!=0; ptb=ptab,ptab=ptab->next); /* Check if it's trying to overwrite the default. */ if (ptab == &Tl_tab) { err_warn(1,fperr,"Error - can't replace the default (Tl_%s).\n", pt->name); free((char *)pt); return 0; } if (ptab == NULL) { ptb->next=ptab=pt; } else { if (pt->ltyp != ptab->ltyp || pt->lwsf != ptab->lwsf || pt->lci != ptab->lci || pt->priority != ptab->priority || ptab->lvp[0] != pt->lvp[0] || ptab->lvp[1] != pt->lvp[1] || ptab->lvp[2] != pt->lvp[2] || ptab->lvp[3] != pt->lvp[3] || ptab->lwc[0] != pt->lwc[0] || ptab->lwc[1] != pt->lwc[1] || ptab->lwc[2] != pt->lwc[2] || ptab->lwc[3] != pt->lwc[3] || ptab->lx != pt->lx || ptab->ly != pt->ly || (strcmp(ptab->proj,pt->proj) != 0) ) { strcpy(ptab->proj,pt->proj); copy_int_array( &ptab->ltyp,&pt->ltyp,&ptab->ltyp_size,pt->ltyp_size, 1 ); copy_float_array(&ptab->lwsf,&pt->lwsf,&ptab->lwsf_size,pt->lwsf_size,&deflt); copy_int_array( &ptab->lci, &pt->lci, &ptab->lci_size, pt->lci_size, 241 ); ptab->priority=pt->priority; ptab->lvp[0]=pt->lvp[0]; ptab->lvp[1]=pt->lvp[1]; ptab->lvp[2]=pt->lvp[2]; ptab->lvp[3]=pt->lvp[3]; ptab->lwc[0]=pt->lwc[0]; ptab->lwc[1]=pt->lwc[1]; ptab->lwc[2]=pt->lwc[2]; ptab->lwc[3]=pt->lwc[3]; free_points( &ptab->lx ); free_points( &ptab->ly ); if (copy_points( &ptab->lx, pt->lx) == 0) return 0; if (copy_points( &ptab->ly, pt->ly) == 0) return 0; free_points( &pt->lx ); free_points( &pt->ly ); if (pt->ltyp != NULL) free((char *) pt->ltyp); pt->ltyp = NULL; if (pt->lwsf != NULL) free((char *) pt->lwsf); pt->lwsf = NULL; if (pt->lci != NULL) free((char *) pt->lci); pt->lci = NULL; free((char *)pt); pt=NULL; check_d_line(ptab->name); } } if (!Inactive && fpout != NULL) prtTl(fpout,ptab); return 1; }