bool SortConfig::operator()(const Config &x, const Config &y) const { #define SORT(attribute) \ if (x.attribute != y.attribute) \ { \ return x.attribute < y.attribute; \ } META_ASSERT(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG); SORT(mConfigCaveat); META_ASSERT(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER); SORT(mColorBufferType); // By larger total number of color bits, only considering those that are requested to be > 0. EGLint xComponentsSize = wantedComponentsSize(x); EGLint yComponentsSize = wantedComponentsSize(y); if (xComponentsSize != yComponentsSize) { return xComponentsSize > yComponentsSize; } SORT(mBufferSize); SORT(mSampleBuffers); SORT(mSamples); SORT(mDepthSize); SORT(mStencilSize); SORT(mAlphaMaskSize); SORT(mNativeVisualType); SORT(mConfigID); #undef SORT return false; }
bool operator()(const Config &x, const Config &y) const { #define SORT(attribute) \ if (x.attribute != y.attribute) \ { \ return x.attribute < y.attribute; \ } static_assert(EGL_NONE < EGL_SLOW_CONFIG && EGL_SLOW_CONFIG < EGL_NON_CONFORMANT_CONFIG, "Unexpected EGL enum value."); SORT(configCaveat); static_assert(EGL_RGB_BUFFER < EGL_LUMINANCE_BUFFER, "Unexpected EGL enum value."); SORT(colorBufferType); // By larger total number of color bits, only considering those that are requested to be > 0. EGLint xComponentsSize = wantedComponentsSize(x); EGLint yComponentsSize = wantedComponentsSize(y); if (xComponentsSize != yComponentsSize) { return xComponentsSize > yComponentsSize; } SORT(bufferSize); SORT(sampleBuffers); SORT(samples); SORT(depthSize); SORT(stencilSize); SORT(alphaMaskSize); SORT(nativeVisualType); SORT(configID); #undef SORT return false; }
static inline void lock3(struct Locker *l1, struct Locker *l2, struct Locker *l3) { SORT(l1,l2); SORT(l1,l3); SORT(l2,l3); lock(l1); LOCK(l1,l2); LOCK(l2,l3); }
int main(int argc, char *argv[]){ char s[] = "hello"; int e, e_size; int i = 4; DEBUG_VALUE(SIG_ERR); DEBUG_VALUE(SIGKILL); DEBUG_VALUE(123); SORT(1)(s, e, e_size); SORT(3)(s, e, e_size); SORT(2)(s, e, e_size); /* SORT(i/2)(s, e, e_size);*/ /* cannot pass the compiler: "routine030.c", line 35.9: 1506-045 (S) Undeclared identifier sort_functioni*/ }/*main*/
static inline void lock4(struct Locker *l1, struct Locker *l2, struct Locker *l3, struct Locker *l4) { // Batcher's Merge-Exchange N=4 (5 compare, 3 parallel steps) SORT(l1,l3); SORT(l2,l4); SORT(l1,l2); SORT(l3,l4); SORT(l2,l3); lock(l1); LOCK(l1,l2); LOCK(l3,l4); LOCK(l2,l3); }
int main(int argc,char *argv[]){ int i,n=0,a[MAX_N],*p; FILE *fp=fopen(argv[1],"r"); if (fp == NULL){ puts("ファイルオープンエラー"); exit(0); } p = a; while (1){ if (fscanf(fp,"%d",p) == EOF){ // エラー又はファイル終端 if (ferror(fp)){ puts("ファイル読み込みエラー"); exit(0); } else if (feof(fp)) break; else { // たまたま読み込んだ値が EOF と等しかった場合 n++; p++; } } else { n++; p++; } } fclose(fp); //for (i=0;i<n;i++) printf("%d ",a[i]); //puts(""); SORT(a,n); for (i=0;i<n;i++) printf("%d ",a[i]); puts(""); return 0; }
static inline void lock2(struct Locker *l1, struct Locker *l2) { SORT(l1,l2); lock(l1); LOCK(l1,l2); }
Datum _int_same(PG_FUNCTION_ARGS) { ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); int na, nb; int n; int *da, *db; bool result; bool avoid; bool bvoid; CHECKARRVALID(a); CHECKARRVALID(b); avoid = ARRISVOID(a); bvoid = ARRISVOID(b); if (avoid || bvoid) return (avoid && bvoid) ? TRUE : FALSE; na = ARRNELEMS(a); nb = ARRNELEMS(b); da = ARRPTR(a); db = ARRPTR(b); result = FALSE; if (na == nb) { SORT(a); SORT(b); result = TRUE; for (n = 0; n < na; n++) if (da[n] != db[n]) { result = FALSE; break; } } pfree(a); pfree(b); PG_RETURN_BOOL(result); }
void Sort::heapsort(int *a, int count) { uint64_t start = mach_absolute_time(); auto heap = Heap(a, count); heap.SORT(); printf("total : %f\n",MachTimeToSecs(mach_absolute_time()-start)); }
void main() { BUILD(); SORT(); OUT(); system("pause"); return 0; }
Datum _int_same(PG_FUNCTION_ARGS) { ArrayType *a = (ArrayType *) PG_GETARG_ARRAYTYPE_P_COPY(0); ArrayType *b = (ArrayType *) PG_GETARG_ARRAYTYPE_P_COPY(1); int na, nb; int n; int *da, *db; bool result; CHECKARRVALID(a); CHECKARRVALID(b); na = ARRNELEMS(a); nb = ARRNELEMS(b); da = ARRPTR(a); db = ARRPTR(b); result = FALSE; if (na == nb) { SORT(a); SORT(b); result = TRUE; for (n = 0; n < na; n++) { if (da[n] != db[n]) { result = FALSE; break; } } } pfree(a); pfree(b); PG_RETURN_BOOL(result); }
Datum _int_inter(PG_FUNCTION_ARGS) { ArrayType *a = (ArrayType *) PG_GETARG_ARRAYTYPE_P_COPY(0); ArrayType *b = (ArrayType *) PG_GETARG_ARRAYTYPE_P_COPY(1); ArrayType *result; CHECKARRVALID(a); CHECKARRVALID(b); SORT(a); SORT(b); result = inner_int_inter(a, b); pfree(a); pfree(b); PG_RETURN_POINTER(result); }
Bool apc_gp_set_clip_rect( Handle self, Rect clipRect) { DEFXX; Region region; XRectangle r; if ( !XF_IN_PAINT(XX)) return false; SORT( clipRect. left, clipRect. right); SORT( clipRect. bottom, clipRect. top); r. x = clipRect. left; r. y = REVERT( clipRect. top); r. width = clipRect. right - clipRect. left+1; r. height = clipRect. top - clipRect. bottom+1; XX-> clip_rect = r; XX-> clip_mask_extent. x = r. width; XX-> clip_mask_extent. y = r. height; region = XCreateRegion(); XUnionRectWithRegion( &r, region, region); if ( XX-> paint_region) XIntersectRegion( region, XX-> paint_region, region); if ( XX-> btransform. x != 0 || XX-> btransform. y != 0) { XOffsetRegion( region, XX-> btransform. x, -XX-> btransform. y); } XSetRegion( DISP, XX-> gc, region); if ( XX-> flags. kill_current_region) XDestroyRegion( XX-> current_region); XX-> flags. kill_current_region = 1; XX-> current_region = region; XX-> flags. xft_clip = 0; #ifdef USE_XFT if ( XX-> xft_drawable) prima_xft_update_region( self); #endif #ifdef HAVE_X11_EXTENSIONS_XRENDER_H if ( XX-> argb_picture ) XRenderSetPictureClipRegion(DISP, XX->argb_picture, region); #endif return true; }
Datum _int_inter(PG_FUNCTION_ARGS) { ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); ArrayType *result; CHECKARRVALID(a); CHECKARRVALID(b); if (ARRISVOID(a) || ARRISVOID(b)) PG_RETURN_POINTER(new_intArrayType(0)); SORT(a); SORT(b); result = inner_int_inter(a, b); pfree(a); pfree(b); PG_RETURN_POINTER(result); }
/* _int_overlap -- does a overlap b? */ Datum _int_overlap(PG_FUNCTION_ARGS) { ArrayType *a = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); ArrayType *b = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); bool result; CHECKARRVALID(a); CHECKARRVALID(b); if (ARRISVOID(a) || ARRISVOID(b)) return FALSE; SORT(a); SORT(b); result = inner_int_overlap(a, b); pfree(a); pfree(b); PG_RETURN_BOOL(result); }
/* _int_overlap -- does a overlap b? */ Datum _int_overlap(PG_FUNCTION_ARGS) { ArrayType *a = (ArrayType *) PG_GETARG_ARRAYTYPE_P_COPY(0); ArrayType *b = (ArrayType *) PG_GETARG_ARRAYTYPE_P_COPY(1); bool result; CHECKARRVALID(a); CHECKARRVALID(b); if (ARRISEMPTY(a) || ARRISEMPTY(b)) return FALSE; SORT(a); SORT(b); result = inner_int_overlap(a, b); pfree(a); pfree(b); PG_RETURN_BOOL(result); }
static inline void lock5(struct Locker *l1, struct Locker *l2, struct Locker *l3, struct Locker *l4, struct Locker *l5) { // Batcher's Merge-Exchange N=5 (9 compare, 5 parallel steps) SORT(l1,l5); SORT(l2,l4); SORT(l1,l3); SORT(l3,l5); SORT(l1,l2); SORT(l3,l4); SORT(l2,l5); SORT(l2,l3); SORT(l4,l5); lock(l1); LOCK(l1,l2); LOCK(l3,l4); LOCK(l2,l3); LOCK(l4,l5); }
int main(void) { sf::RenderWindow window(sf::VideoMode(1920,1080), "TEST"); int word[8] = {7,3,6,2,6,9,1,6}; printArr(word, 8); SORT(word, word + 8); printArr(word, 8); char numbers[6] = "54321"; SORT(numbers, numbers + 5); printf("%s\n", numbers); sf::Sprite sprite; sf::Texture texture; texture.loadFromFile("../../bin/tileSheets/walkSequence.png"); //texture.loadFromFile("../../bin/planet.png"); sprite.setTexture(texture); sprite.setTextureRect(sf::IntRect(6144-512,512,512,512)); HitBoxBase<sf::FloatRect> hbox = *(HitBoxBase<sf::FloatRect>*)GenerateHitBox(sprite); printv(hbox._hbox.top); printv(hbox._hbox.left); printv(hbox._hbox.width); printv(hbox._hbox.height); while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) window.close(); } window.clear(); window.draw(sprite); window.display(); } return 0; }
int main (int argc, char *argv[]) { bson_t *bson; char *json; bson = COL_VIEW_CREATE ( SORT ("a", BCON_INT32 (1)), QUERY ("hello", "world"), LIMIT (10)); json = bson_as_canonical_extended_json (bson, NULL); printf ("%s\n", json); bson_free (json); bson_destroy (bson); return 0; }
int main() { const char words[][10] = { {"Barco"}, {"Carro"}, {"Abelha"} }; char *palavras[3]; palavras[0] = (char*)malloc(sizeof(char)*strlen(words[0])+1); strcpy(palavras[0],words[0]); palavras[1] = (char*)malloc(sizeof(char)*strlen(words[1])+1); strcpy(palavras[1],words[1]); palavras[2] = (char*)malloc(sizeof(char)*strlen(words[2])+1); strcpy(palavras[2],words[2]); palavras[3] = NULL; SORT(palavras,&compare); int i; for(i=0; i < 3; ++i) fprintf(stdout,"%s.\n",palavras[i]); return 0; }
int main() { FILE *in , *out; in = fopen("prz.in","r"); out = fopen("prz.out","w"); Int int_begin,int_end; int i = 0; while(fscanf(in , "%d%d",&int_begin,&int_end) != EOF){ Array[i] = malloc(sizeof(struct interval)); Array[i]->begin = int_begin; Array[i]->end = int_end; i++; } fclose(in); int total_Intval = i; SORT(Array,total_Intval); i = 0; while( i < total_Intval){ // invarint : Every time we reach this line, variable i indicates the position of Interval from which next cluster begin . struct Cluster cluster; cluster.Cluster_begin = Array[i]->begin; cluster.Cluster_end = Array[i]->end; i++; //Interval * max_end = Array[i]; // do{ // for( ; (Array[i]->begin <= cluster.end) && (i < total_Intval); i++) // push(PQ , Array[i]); // max_end = pop(PQ); // }while(max_end->int_end > cluster.end); while((i < total_Intval) &&(Array[i]->begin <= cluster.Cluster_end) ){ cluster.Cluster_end = Array[i]->end > cluster.Cluster_end ? Array[i]->end : cluster.Cluster_end; i++; } fprintf(out,"%d %d\n",cluster.Cluster_begin , cluster.Cluster_end); } fclose(out); }
int main() { size_t i; int *pool = malloc(sizeof(int) * SIZE); srand(SEED); for(i = 0; i < SIZE; i++){ pool[i] = i; } permute(pool, SIZE); print_array(pool, SIZE); printf("\n"); clock_t start = clock(); SORT(pool, SIZE); printf("cpu time: %f s\n", (double)(clock()-start)/CLOCKS_PER_SEC); print_array(pool, SIZE); printf("\n"); if(checksort(pool, SIZE, 0) == 0) printf("check ok!\n"); else printf("check fail!\n"); free(pool); return 0; }
int main() { /* if you segfault here, comment out _FASTSORT_STACK */ /* this happens because your system stack ownt take a 2 or 4meg stack variable */ /*#define _FASTSORT_STACK */ #ifdef _FASTSORT_STACK unsigned int random_array[RANDOM_SIZE]; #else unsigned int* random_array = malloc(RANDOM_SIZE * sizeof(unsigned int)); #endif int i; srand(SEED); for(i = 0; i < RANDOM_SIZE; i++) { random_array[i] = rand(); } SORT(random_array, RANDOM_SIZE); #ifndef _FASTSORT_STACK free(random_array); #endif return 0; }
/* Process 4OP Integer instructions */ bool eval_4OP_Int(struct lilith* vm, struct Instruction* c) { #ifdef DEBUG char Name[20] = "ILLEGAL_4OP"; #endif switch(c->raw_XOP) { case 0x00: /* ADD.CI */ { #ifdef DEBUG strncpy(Name, "ADD.CI", 19); #elif TRACE record_trace("ADD.CI"); #endif ADD_CI(vm, c); break; } case 0x01: /* ADD.CO */ { #ifdef DEBUG strncpy(Name, "ADD.CO", 19); #elif TRACE record_trace("ADD.CO"); #endif ADD_CO(vm, c); break; } case 0x02: /* ADD.CIO */ { #ifdef DEBUG strncpy(Name, "ADD.CIO", 19); #elif TRACE record_trace("ADD.CIO"); #endif ADD_CIO(vm, c); break; } case 0x03: /* ADDU.CI */ { #ifdef DEBUG strncpy(Name, "ADDU.CI", 19); #elif TRACE record_trace("ADDU.CI"); #endif ADDU_CI(vm, c); break; } case 0x04: /* ADDU.CO */ { #ifdef DEBUG strncpy(Name, "ADDU.CO", 19); #elif TRACE record_trace("ADDU.CO"); #endif ADDU_CO(vm, c); break; } case 0x05: /* ADDU.CIO */ { #ifdef DEBUG strncpy(Name, "ADDU.CIO", 19); #elif TRACE record_trace("ADDU.CIO"); #endif ADDU_CIO(vm, c); break; } case 0x06: /* SUB.BI */ { #ifdef DEBUG strncpy(Name, "SUB.BI", 19); #elif TRACE record_trace("SUB.BI"); #endif SUB_BI(vm, c); break; } case 0x07: /* SUB.BO */ { #ifdef DEBUG strncpy(Name, "SUB.BO", 19); #elif TRACE record_trace("SUB.BO"); #endif SUB_BO(vm, c); break; } case 0x08: /* SUB.BIO */ { #ifdef DEBUG strncpy(Name, "SUB.BIO", 19); #elif TRACE record_trace("SUB.BIO"); #endif SUB_BIO(vm, c); break; } case 0x09: /* SUBU.BI */ { #ifdef DEBUG strncpy(Name, "SUBU.BI", 19); #elif TRACE record_trace("SUBU.BI"); #endif SUBU_BI(vm, c); break; } case 0x0A: /* SUBU.BO */ { #ifdef DEBUG strncpy(Name, "SUBU.BO", 19); #elif TRACE record_trace("SUBU.BO"); #endif SUBU_BO(vm, c); break; } case 0x0B: /* SUBU.BIO */ { #ifdef DEBUG strncpy(Name, "SUBU.BIO", 19); #elif TRACE record_trace("SUBU.BIO"); #endif SUBU_BIO(vm, c); break; } case 0x0C: /* MULTIPLY */ { #ifdef DEBUG strncpy(Name, "MULTIPLY", 19); #elif TRACE record_trace("MULTIPLY"); #endif MULTIPLY(vm, c); break; } case 0x0D: /* MULTIPLYU */ { #ifdef DEBUG strncpy(Name, "MULTIPLYU", 19); #elif TRACE record_trace("MULTIPLYU"); #endif MULTIPLYU(vm, c); break; } case 0x0E: /* DIVIDE */ { #ifdef DEBUG strncpy(Name, "DIVIDE", 19); #elif TRACE record_trace("DIVIDE"); #endif DIVIDE(vm, c); break; } case 0x0F: /* DIVIDEU */ { #ifdef DEBUG strncpy(Name, "DIVIDEU", 19); #elif TRACE record_trace("DIVIDEU"); #endif DIVIDEU(vm, c); break; } case 0x10: /* MUX */ { #ifdef DEBUG strncpy(Name, "MUX", 19); #elif TRACE record_trace("MUX"); #endif MUX(vm, c); break; } case 0x11: /* NMUX */ { #ifdef DEBUG strncpy(Name, "NMUX", 19); #elif TRACE record_trace("NMUX"); #endif NMUX(vm, c); break; } case 0x12: /* SORT */ { #ifdef DEBUG strncpy(Name, "SORT", 19); #elif TRACE record_trace("SORT"); #endif SORT(vm, c); break; } case 0x13: /* SORTU */ { #ifdef DEBUG strncpy(Name, "SORTU", 19); #elif TRACE record_trace("SORTU"); #endif SORTU(vm, c); break; } default: { illegal_instruction(vm, c); break; } } #ifdef DEBUG fprintf(stdout, "# %s reg%u reg%u reg%u reg%u\n", Name, c->reg0, c->reg1, c->reg2, c->reg3); #endif return false; }
int main(int argc, char **argv) { data d; glam2_aln *alns; int r; prog_name = "glam2"; /* for error messages */ getargs(&d.a, argc, argv); init(&d); fputs("GLAM2: Gapped Local Alignment of Motifs\nVersion " #include "glam2_version.h" "\n\n", d.out); printargs(d.out, argc, argv); print_misc_info(d.out, &d); putc('\n', d.out); XMALLOC(alns, d.a.runs); for (r = 0; r < d.a.runs; ++r) { glam2_aln *aln = &alns[r]; if (!d.a.quiet) { fprintf(stderr, "Run %d... ", r+1); fflush(stderr); } aln_init(aln, d.seqs.seqnum, d.a.max_width, d.alph.size); d.sm.underflow_flag = 1; /* do we care about underflow in start_aln? */ start_aln(aln, &d); optimise_aln(aln, &d); if (d.sm.underflow_flag < (d.a.algorithm == 2 ? DBL_EPSILON : DBL_MIN)) fprintf(stderr, "%s: accuracy loss due to numeric underflow (%g)\nIf the alignment looks suspect, try rerunning with higher -u, or maybe lower -b\n", prog_name, d.sm.underflow_flag); if (d.a.profile) print_aln_info(d.out, aln, &d); } if (!d.a.quiet) putc('\n', stderr); SORT(alns, d.a.runs, aln_cmp); if (!d.a.profile) print_alns(d.out, alns, &d); xfclose(d.out); // close text output file // Create the HTML output and MEME format output char *glam2html, *glam2psfm, *command; int command_length, command_ret; // create the paths to the programs glam2html = make_path_to_file(get_meme_bin_dir(), "glam2html"); glam2psfm = make_path_to_file(get_meme_bin_dir(), "glam2psfm"); // allocate memory for the command command_length = strlen(glam2html) + strlen(d.txt_filename) + strlen(d.html_filename) + 50; command = xmalloc(command_length); // run glam2html sprintf(command, "%s < %s > %s", glam2html, d.txt_filename, d.html_filename); if ((command_ret = system(command)) != 0) { report_external_failure("glam2html", command_ret); fprintf(stderr, "Warning: failed to convert output to HTML!\n"); } // run glam2psfm sprintf(command, "%s < %s > %s", glam2psfm, d.txt_filename, d.psfm_filename); if ((command_ret = system(command)) != 0) { report_external_failure("glam2psfm", command_ret); fprintf(stderr, "Warning: failed to convert output to MEME format motif!\n"); } free(command); free(glam2psfm); free(glam2html); return 0; }
int NoDivTriTriIsect(double V0[3],double V1[3],double V2[3], double U0[3],double U1[3],double U2[3]) { double E1[3],E2[3]; double N1[3],N2[3],d1,d2; double du0,du1,du2,dv0,dv1,dv2; double D[3]; double isect1[2], isect2[2]; double du0du1,du0du2,dv0dv1,dv0dv2; short index; double vp0,vp1,vp2; double up0,up1,up2; double bb,cc,max; double a,b,c,x0,x1; double d,e,f,y0,y1; double xx,yy,xxyy,tmp; /* compute plane equation of triangle(V0,V1,V2) */ SUB(E1,V1,V0); SUB(E2,V2,V0); CROSS(N1,E1,E2); d1=-DOT(N1,V0); /* plane equation 1: N1.X+d1=0 */ /* put U0,U1,U2 into plane equation 1 to compute signed distances to the plane*/ du0=DOT(N1,U0)+d1; du1=DOT(N1,U1)+d1; du2=DOT(N1,U2)+d1; /* coplanarity robustness check */ #if USE_EPSILON_TEST==TRUE if(FABS(du0)<EPSILON) du0=0.0; if(FABS(du1)<EPSILON) du1=0.0; if(FABS(du2)<EPSILON) du2=0.0; #endif du0du1=du0*du1; du0du2=du0*du2; if(du0du1>0.0f && du0du2>0.0f) /* same sign on all of them + not equal 0 ? */ return 0; /* no intersection occurs */ /* compute plane of triangle (U0,U1,U2) */ SUB(E1,U1,U0); SUB(E2,U2,U0); CROSS(N2,E1,E2); d2=-DOT(N2,U0); /* plane equation 2: N2.X+d2=0 */ /* put V0,V1,V2 into plane equation 2 */ dv0=DOT(N2,V0)+d2; dv1=DOT(N2,V1)+d2; dv2=DOT(N2,V2)+d2; #if USE_EPSILON_TEST==TRUE if(FABS(dv0)<EPSILON) dv0=0.0; if(FABS(dv1)<EPSILON) dv1=0.0; if(FABS(dv2)<EPSILON) dv2=0.0; #endif dv0dv1=dv0*dv1; dv0dv2=dv0*dv2; if(dv0dv1>0.0f && dv0dv2>0.0f) /* same sign on all of them + not equal 0 ? */ return 0; /* no intersection occurs */ /* compute direction of intersection line */ CROSS(D,N1,N2); /* compute and index to the largest component of D */ max=(double)FABS(D[0]); index=0; bb=(double)FABS(D[1]); cc=(double)FABS(D[2]); if(bb>max) max=bb,index=1; if(cc>max) max=cc,index=2; /* this is the simplified projection onto L*/ vp0=V0[index]; vp1=V1[index]; vp2=V2[index]; up0=U0[index]; up1=U1[index]; up2=U2[index]; /* compute interval for triangle 1 */ NEWCOMPUTE_INTERVALS(vp0,vp1,vp2,dv0,dv1,dv2,dv0dv1,dv0dv2,a,b,c,x0,x1); /* compute interval for triangle 2 */ NEWCOMPUTE_INTERVALS(up0,up1,up2,du0,du1,du2,du0du1,du0du2,d,e,f,y0,y1); xx=x0*x1; yy=y0*y1; xxyy=xx*yy; tmp=a*xxyy; isect1[0]=tmp+b*x1*yy; isect1[1]=tmp+c*x0*yy; tmp=d*xxyy; isect2[0]=tmp+e*xx*y1; isect2[1]=tmp+f*xx*y0; SORT(isect1[0],isect1[1]); SORT(isect2[0],isect2[1]); if(isect1[1]<isect2[0] || isect2[1]<isect1[0]) return 0; return 1; }
int tri_tri_intersect(double V0[3],double V1[3],double V2[3], double U0[3],double U1[3],double U2[3]) { double E1[3],E2[3]; double N1[3],N2[3],d1,d2; double du0,du1,du2,dv0,dv1,dv2; double D[3]; double isect1[2], isect2[2]; double du0du1,du0du2,dv0dv1,dv0dv2; short index; double vp0,vp1,vp2; double up0,up1,up2; double b,c,max; /* compute plane equation of triangle(V0,V1,V2) */ SUB(E1,V1,V0); SUB(E2,V2,V0); CROSS(N1,E1,E2); d1=-DOT(N1,V0); /* plane equation 1: N1.X+d1=0 */ /* put U0,U1,U2 into plane equation 1 to compute signed distances to the plane*/ du0=DOT(N1,U0)+d1; du1=DOT(N1,U1)+d1; du2=DOT(N1,U2)+d1; /* coplanarity robustness check */ #if USE_EPSILON_TEST==TRUE if(fabs(du0)<EPSILON) du0=0.0; if(fabs(du1)<EPSILON) du1=0.0; if(fabs(du2)<EPSILON) du2=0.0; #endif du0du1=du0*du1; du0du2=du0*du2; if(du0du1>0.0f && du0du2>0.0f) /* same sign on all of them + not equal 0 ? */ return 0; /* no intersection occurs */ /* compute plane of triangle (U0,U1,U2) */ SUB(E1,U1,U0); SUB(E2,U2,U0); CROSS(N2,E1,E2); d2=-DOT(N2,U0); /* plane equation 2: N2.X+d2=0 */ /* put V0,V1,V2 into plane equation 2 */ dv0=DOT(N2,V0)+d2; dv1=DOT(N2,V1)+d2; dv2=DOT(N2,V2)+d2; #if USE_EPSILON_TEST==TRUE if(fabs(dv0)<EPSILON) dv0=0.0; if(fabs(dv1)<EPSILON) dv1=0.0; if(fabs(dv2)<EPSILON) dv2=0.0; #endif dv0dv1=dv0*dv1; dv0dv2=dv0*dv2; if(dv0dv1>0.0f && dv0dv2>0.0f) /* same sign on all of them + not equal 0 ? */ return 0; /* no intersection occurs */ /* compute direction of intersection line */ CROSS(D,N1,N2); /* compute and index to the largest component of D */ max=fabs(D[0]); index=0; b=fabs(D[1]); c=fabs(D[2]); if(b>max) max=b,index=1; if(c>max) max=c,index=2; /* this is the simplified projection onto L*/ vp0=V0[index]; vp1=V1[index]; vp2=V2[index]; up0=U0[index]; up1=U1[index]; up2=U2[index]; /* compute interval for triangle 1 */ COMPUTE_INTERVALS(vp0,vp1,vp2,dv0,dv1,dv2,dv0dv1,dv0dv2,isect1[0],isect1[1]); /* compute interval for triangle 2 */ COMPUTE_INTERVALS(up0,up1,up2,du0,du1,du2,du0du1,du0du2,isect2[0],isect2[1]); SORT(isect1[0],isect1[1]); SORT(isect2[0],isect2[1]); if(isect1[1]<isect2[0] || isect2[1]<isect1[0]) return 0; return 1; }
int main() { //Create two vectors to hold data from XML-Files std::vector<Node> collection; std::vector<Node> collection1; //variables to count time for reading,sorting and output data clock_t begin, end; //objects to read from XML-Files XmlTextReader^ reader = gcnew XmlTextReader("XMLFile.xml"); XmlTextReader^ reader1 = gcnew XmlTextReader("XMLFile1.xml"); //root names in both XML-Files std::string rootName; std::string rootName1; System::Console::WriteLine("First let's try to do this with one thread: "); //Read from XML-File until we finally find Element-Node while (reader->NodeType != XmlNodeType::Element) { reader->Read(); } if (reader->NodeType == XmlNodeType::Element) { rootName = msclr::interop::marshal_as< std::string >(reader->Name); } reader->Close(); //Continue reading all data until the end of the file, count seconds begin = clock(); read(collection); end = clock(); System::Console::WriteLine("First File was read for {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); //repeat same actions with second file while (reader1->NodeType != XmlNodeType::Element) { reader1->Read(); } if (reader1->NodeType == XmlNodeType::Element) { rootName1 = msclr::interop::marshal_as< std::string >(reader1->Name); } reader1->Close(); begin = clock(); read( collection1); end = clock(); System::Console::WriteLine("Second File was read for {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); //clear collections for reading files again,but now with two threads collection.clear(); collection1.clear(); System::Console::WriteLine("Now let's do it with two threads: "); //Try to create mutex to hold thread in function call if ((gMutex = CreateMutex(NULL, FALSE, NULL))==NULL) { System::Console::WriteLine("Mutex creation failed...{0}",GetLastError()); } //open XML-Files again to read from begin reader = gcnew XmlTextReader("XMLFile1.xml"); reader1 = gcnew XmlTextReader("XMLFile1.xml"); while (reader->NodeType != XmlNodeType::Element) { reader->Read(); } if (reader->NodeType == XmlNodeType::Element) { rootName = msclr::interop::marshal_as< std::string >(reader->Name); } begin = clock(); //Try to create second thread andread witj it from first XML-file to first collection if ((gThread=CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)read, &collection, 0, 0))==NULL) { System::Console::WriteLine("Thread creation failed...{0}",GetLastError()); } //When thread reads first file,we try to read second file read(collection1); WaitForSingleObject(gThread, INFINITE); end = clock(); System::Console::WriteLine("Both files were read for {0}", (end - begin) / (double)CLOCKS_PER_SEC); //Close second thread CloseHandle(gThread); System::Console::WriteLine("Now we'll sort both documents! First with one thread: "); begin = clock(); //Try to sort both collections with one thread sort(collection.begin(), collection.end()); sort(collection1.begin(), collection1.end()); end = clock(); System::Console::WriteLine("They were sorted for {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); System::Console::WriteLine("Now with both threads:"); begin = clock(); //Create second thread and repeat sorting gThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SORT, &collection, 0, 0); if (gThread == NULL) { System::Console::WriteLine("Thread creation failed...{0}", GetLastError()); } SORT(collection1); WaitForSingleObject(gThread, INFINITE); end = clock(); System::Console::WriteLine("They were sorted for {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); CloseHandle(gThread); //close XML-Files to give access to XML-writers to files reader->Close(); reader1->Close(); System::Console::WriteLine("Now we will try to change first values in each Node! First with one thread:"); //change first values in each element's first_value field //with one thread first begin = clock(); SemaphoreDataHolder holder(collection, (std::string)"000000000"); SemaphoreDataHolder holder1(collection1, (std::string)"000000000"); changeDATA(holder); changeDATA(holder1); end = clock(); System::Console::WriteLine("Values were changed for {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); //Create Semaphore for changeDATA function gSemaphore = CreateSemaphore(NULL, 1, 2, (LPCWSTR)"Sam_Winchester"); //Now with two threads System::Console::WriteLine("Now with two threads:"); SemaphoreDataHolder hold(collection, (std::string)"555555555"); SemaphoreDataHolder hold1(collection1, (std::string)"555555555"); begin = clock(); gThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)changeDATA, &hold, 0, 0); if (gThread == NULL) { System::Console::WriteLine("thread creation failed {0}", GetLastError()); } changeDATA(hold1); WaitForSingleObject(gThread, INFINITE); end = clock(); System::Console::WriteLine("Both were changed with {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); //Now try to run sort and changeDATA function at the same time with one two threads with turned mutex off System::Console::WriteLine("Entering dangerous area: "); //CloseHandle(gMutex); begin = clock(); gThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SORT, &collection, 0, 0); if (gThread == NULL) { System::Console::WriteLine("Thread creation failed {0}", GetLastError()); } changeDATA(hold); end = clock(); System::Console::WriteLine("value changed for {0} seconds", (end - begin) / (double)CLOCKS_PER_SEC); CloseHandle(gMutex); CloseHandle(gSemaphore); CloseHandle(gThread); //create xml-writers objects XmlTextWriter^ writer = gcnew XmlTextWriter("XMLFile.xml", nullptr); XmlTextWriter^ writer1 = gcnew XmlTextWriter("XMLFile1.xml", nullptr); //set file's begin and root elements by Xml-writers writer->Formatting=Formatting::Indented; writer->WriteStartDocument(); writer1->Formatting = Formatting::Indented; writer1->WriteStartDocument(); System::String^ help = gcnew System::String(rootName.c_str()); writer->WriteStartElement(help); help = gcnew System::String(rootName1.c_str()); writer1->WriteStartElement(help); //just call outputXML function to output data from collections to XML-Files outputXML(collection, writer); outputXML(collection1, writer1); //end XML-Files with end elements writer->WriteEndElement(); writer1->WriteEndElement(); //close XML-Files to save changes writer->Close(); writer1->Close(); system("pause"); }
bool MFCollision_TriTriTest(const MFVector& V0, const MFVector& V1, const MFVector& V2, const MFVector& U0, const MFVector& U1, const MFVector& U2) { MFVector E1, E2; MFVector N1, N2; MFVector D; float d1,d2; float du0,du1,du2,dv0,dv1,dv2; float isect1[2], isect2[2]; float du0du1,du0du2,dv0dv1,dv0dv2; short index; float vp0,vp1,vp2; float up0,up1,up2; float bb,cc,max; float a,b,c,x0,x1; float d,e,f,y0,y1; float xx,yy,xxyy,tmp; /* compute plane equation of triangle(V0,V1,V2) */ E1 = V1-V0; E2 = V2-V0; N1.Cross3(E1, E2); d1 = -N1.Dot3(V0); /* plane equation 1: N1.X+d1=0 */ /* put U0,U1,U2 into plane equation 1 to compute signed distances to the plane*/ du0 = N1.Dot3(U0) + d1; du1 = N1.Dot3(U1) + d1; du2 = N1.Dot3(U2) + d1; /* coplanarity robustness check */ if(fabsf(du0)<MFALMOST_ZERO) du0=0.0f; if(fabsf(du1)<MFALMOST_ZERO) du1=0.0f; if(fabsf(du2)<MFALMOST_ZERO) du2=0.0f; du0du1 = du0*du1; du0du2 = du0*du2; if(du0du1>0.0f && du0du2>0.0f) /* same sign on all of them + not equal 0 ? */ return false; /* no intersection occurs */ /* compute plane of triangle (U0,U1,U2) */ E1 = U1 - U0; E2 = U2 - U0; N2.Cross3(E1, E2); d2 = -N2.Dot3(U0); /* plane equation 2: N2.X+d2=0 */ /* put V0,V1,V2 into plane equation 2 */ dv0 = N2.Dot3(V0) + d2; dv1 = N2.Dot3(V1) + d2; dv2 = N2.Dot3(V2) + d2; if(fabsf(dv0)<MFALMOST_ZERO) dv0=0.0; if(fabsf(dv1)<MFALMOST_ZERO) dv1=0.0; if(fabsf(dv2)<MFALMOST_ZERO) dv2=0.0; dv0dv1 = dv0*dv1; dv0dv2 = dv0*dv2; if(dv0dv1>0.0f && dv0dv2>0.0f) /* same sign on all of them + not equal 0 ? */ return false; /* no intersection occurs */ /* compute direction of intersection line */ D.Cross3(N1, N2); /* compute and index to the largest component of D */ max = fabsf(D.x); index = 0; bb = fabsf(D.y); cc = fabsf(D.z); if(bb>max) max = bb, index = 1; if(cc>max) max = cc, index = 2; /* this is the simplified projection onto L*/ vp0 = V0[index]; vp1 = V1[index]; vp2 = V2[index]; up0 = U0[index]; up1 = U1[index]; up2 = U2[index]; /* compute interval for triangle 1 */ NEWCOMPUTE_INTERVALS(vp0,vp1,vp2,dv0,dv1,dv2,dv0dv1,dv0dv2,a,b,c,x0,x1); /* compute interval for triangle 2 */ NEWCOMPUTE_INTERVALS(up0,up1,up2,du0,du1,du2,du0du1,du0du2,d,e,f,y0,y1); xx=x0*x1; yy=y0*y1; xxyy=xx*yy; tmp=a*xxyy; isect1[0]=tmp+b*x1*yy; isect1[1]=tmp+c*x0*yy; tmp=d*xxyy; isect2[0]=tmp+e*xx*y1; isect2[1]=tmp+f*xx*y0; SORT(isect1[0],isect1[1]); SORT(isect2[0],isect2[1]); if(isect1[1]<isect2[0] || isect2[1]<isect1[0]) return false; return true; }
void Init_Huffman_Decoder_SV7 ( void ) { Init_Huffman_Encoder_SV7 (); SORT ( HuffHdr , 5 ); SORT ( HuffSCFI , 0 ); SORT ( HuffDSCF , 7 ); SORT ( HuffQ1[0], 0 ); SORT ( HuffQ1[1], 0 ); SORT ( HuffQ2[0], 0 ); SORT ( HuffQ2[1], 0 ); #ifdef USE_SV8 SORT ( HuffN3[0], 0 ); SORT ( HuffN3[1], 0 ); #endif SORT ( HuffQ3[0], Dc[3] ); SORT ( HuffQ3[1], Dc[3] ); SORT ( HuffQ4[0], Dc[4] ); SORT ( HuffQ4[1], Dc[4] ); SORT ( HuffQ5[0], Dc[5] ); SORT ( HuffQ5[1], Dc[5] ); SORT ( HuffQ6[0], Dc[6] ); SORT ( HuffQ6[1], Dc[6] ); SORT ( HuffQ7[0], Dc[7] ); SORT ( HuffQ7[1], Dc[7] ); #ifdef USE_SV8 SORT ( HuffN8[0], Dc[8] ); SORT ( HuffN8[1], Dc[8] ); #endif LOOKUP ( HuffQ1[0], LUT1_0 ); LOOKUP ( HuffQ1[1], LUT1_1 ); LOOKUP ( HuffQ2[0], LUT2_0 ); LOOKUP ( HuffQ2[1], LUT2_1 ); LOOKUP ( HuffQ3[0], LUT3_0 ); LOOKUP ( HuffQ3[1], LUT3_1 ); LOOKUP ( HuffQ4[0], LUT4_0 ); LOOKUP ( HuffQ4[1], LUT4_1 ); LOOKUP ( HuffQ5[0], LUT5_0 ); LOOKUP ( HuffQ5[1], LUT5_1 ); LOOKUP ( HuffQ6[0], LUT6_0 ); LOOKUP ( HuffQ6[1], LUT6_1 ); LOOKUP ( HuffQ7[0], LUT7_0 ); LOOKUP ( HuffQ7[1], LUT7_1 ); LOOKUP ( HuffDSCF , LUTDSCF ); }