int characterCount::linearDifference(const characterCount& c) const { int count1 = 0; int count2 = 0; int count3 = 0; int count4 = 0; int tmp1; int tmp2; int tmp3; int tmp4; const short* from = &(c.m_buckets[0]); const short* to = &(this->m_buckets[0]); const short* end = &(this->m_buckets[sizeof(char) << 8]); for( ; to < end; ) { tmp1 = *to - *from; tmp2 = *(to+1) - *(from+1); tmp3 = *(to+2) - *(from+2); tmp4 = *(to+3) - *(from+3); count1 += ABSV( tmp1 ); count2 += ABSV( tmp2 ); count3 += ABSV( tmp3 ); count4 += ABSV( tmp4 ); from += 4; to += 4; } return ((count1 + count2) + (count3 + count4)); }
bool isInBetw(vector pt, vector begin, vector end) { float dot, crossLength, eBLength; vector eB, pB, cross; SUBV(eB, end, begin); SUBV(pB, pt, begin); DOTVP(dot, eB, pB); CROSSVP(cross, eB, pB); ABSV(eBLength, eB); ABSV(crossLength, cross); return (crossLength < 0.0001f && dot >= 0.0000f && dot < eBLength * eBLength); }
void set_val_sphere(t_env *env, double t, t_ray *ray) { OBJ.new_start = vector_add(ray->start, vector_scale(t, ray->dir)); OBJ.normal = vector_sub(OBJ.new_start, SP_POS(OBJ.cur_sphere)); if (vector_dot(OBJ.normal, OBJ.normal) == 0) { env->br = 1; return ; } OBJ.normal = vector_scale(1.0f / ABSV(OBJ.normal), OBJ.normal); OBJ.cur_mat = env->obj.mats[SPHERES[OBJ.cur_sphere].shape.material]; }
void set_val_tri(t_env *env, float t, t_ray ray) { t_vector scaled; scaled = vector_scale(t, &ray.dir); OBJ.new_start = vector_add(&ray.start, &scaled); OBJ.normal = TRI[OBJ.cur_tri].normal; if (vector_dot(&OBJ.normal, &OBJ.normal) == 0) { env->br = 1; return ; } OBJ.normal = vector_scale(1.0f / ABSV(OBJ.normal), &OBJ.normal); OBJ.cur_mat = env->obj.mats[TRI[OBJ.cur_tri].shape.material]; }
void set_val_sphere(t_env *env, float t, t_ray ray) { t_vector scaled; scaled = vector_scale(t, &ray.dir); OBJ.new_start = vector_add(&ray.start, &scaled); OBJ.normal = vector_sub(&OBJ.new_start, &SP_POS(OBJ.cur_sphere)); if (vector_dot(&OBJ.normal, &OBJ.normal) == 0) { env->br = 1; return ; } OBJ.normal = vector_scale(1.0f / ABSV(OBJ.normal), &OBJ.normal); OBJ.cur_mat = env->obj.mats[SPHERES[OBJ.cur_sphere].shape.material]; }
void set_val_cone(t_env *env, float t, t_ray ray) { t_vector scaled; scaled = vector_scale(t, &ray.dir); OBJ.new_start = vector_add(&ray.start, &scaled); OBJ.normal = vector_sub(&OBJ.new_start, &CN_POS(OBJ.cur_cone)); unrotate_vec2(env, OBJ.cur_cone, &OBJ.normal); OBJ.normal.y *= -1.0f; rotate_vec_x(CONES[OBJ.cur_cone].rot.x, &OBJ.normal); rotate_vec_y(CONES[OBJ.cur_cone].rot.y, &OBJ.normal); rotate_vec_z(CONES[OBJ.cur_cone].rot.z, &OBJ.normal); if (vector_dot(&OBJ.normal, &OBJ.normal) == 0) { env->br = 1; return ; } OBJ.normal = vector_scale(1.0f / ABSV(OBJ.normal), &OBJ.normal); vector_norm(&OBJ.normal); OBJ.cur_mat = env->obj.mats[CONES[OBJ.cur_cone].shape.material]; }
int main (int argc,char *argv[]) { int number, j, i, l, k, n, mid, iter; long idem=-1; char arg[64], outfn[64], *eqptr; double *data, *olddata, h, h1, h2, p, lr, dt, dp, rp; if( argc > 1 ) { for(i = 1; i < argc; i++) { eqptr = strchr(argv[i], '='); strcpy(arg, eqptr + 1); switch(argv[i][0]) { case 'p': case 'P': p = atof(arg); break; case 'n': case 'N': number = atoi(arg); break; case 'h': case 'H': h = atof(arg); break; case 'o': case 'O': strcpy(outfn, arg); break; } } } printf("Input parameters: %f %d %f %s\n", p, number, h, outfn); /* We need number to be odd so it easier to devide to 2 */ if(number%2==0) number++; data=(double*)malloc(sizeof(double)); olddata=(double*)malloc(sizeof(double)); if( (data==NULL)&&(olddata==NULL) ) { printf("Could not allocate memory!\n"); exit(-1); } /* Estimate number of iteration needed to get number points */ iter=(int)(log2(number)); if(argc>0) /* enough arguments? */ { olddata[0]=h; for(i=1; i<=iter; i++) { printf("Iteration %d . ", i); n=(int)pow(2.0, (double)i); mid=n/2; k=0; data=realloc(data, n*sizeof(double)); for(j=0; j<mid; j++) { idem=(long)(-ABSV(ran3(&idem))); lr=ran3(&idem); dp=gasdev((int*)(&idem)); rp=p+(dp/10); cascade(olddata[j], &h1, &h2, rp, lr); /*printf("%.3f %3.3f %3.3f |",rp,h1,h2);*/ data[2*j]=h1; data[2*j+1]=h2; if((j>0)&&(j%(10000*mid)==0)) printf(". "); } printf("completed\n"); olddata=(double*)realloc(olddata, n*sizeof(double)); for(j=0; j<n; j++) olddata[j]=data[j]; } /* Now write this out */ out = fopen(outfn, "w"); dt=1/number; for(i=0; i <number; i++) fprintf(out,"%f %f\n", (double)i, data[i]); } fclose(out); free(data); free(olddata); return (0); /* for lint formalities */ }