Bool find_folding(float A[3],float B[3],float C[3], float D[3],float E[3],float F[3], float V[3]) /* set V so that AV is the line, where AD meets AE while AD and AE are rotarted around AB and AC respectively, and F and V are on the same side of the plane ABC. */ { float A1[3], A2[3], B1[3], B2[3], K[3]; if(vector_eq(A,B)) { printf("FOLDING REFUSED: A=B !!!\n"); return False; } vector_sub(B,A, A1); vector_normalize(A1); if(vector_eq(A,C)) { printf("FOLDING REFUSED: A=C !!!\n"); return False; } vector_sub(C,A, A2); vector_normalize(A2); if(vector_eq(A,D)) { printf("FOLDING REFUSED: A=D !!!\n"); return False; } vector_sub(D,A, B1); vector_normalize(B1); if(vector_eq(A,E)) { printf("FOLDING REFUSED: A=E !!!\n"); return False; } vector_sub(E,A, B2); vector_normalize(B2); vector_sub(F,A, K); if(find_centered_folding(A1,A2, B1,B2, K,V)) { vector_add(A,V, V); return True; } else return False; }
static void __bounding_get_effective_position(const Bounding *b, Vector *result) { assert(b && "Bad bounding pointer."); assert(b->origin && b->previous_origin && b->orientation && b->direction && "Bad bounding data."); assert(result && "Bad result pointer."); Vector p = *b->origin, t, side; if (!vector_eq(b->orientation, b->direction)) { vector_vector_mul(b->orientation, b->direction, &side); } else { vector_get_orthogonal(b->direction, &side); } VECTOR_NORMALIZE(&side); double sx, sy, sz; vector_scale(b->direction, b->offset.x, &t); sx = vector_length(&t); vector_scale(&side, b->offset.y, &t); sy = vector_length(&t); vector_scale(b->orientation, b->offset.z, &t); sz = vector_length(&t); p.x += sx; p.y += sy; p.z += sz; *result = p; }
Bool line_triangle_solve( float A[3], float B[3], float C[3], float D[3], float E[3], float X[3], double *t) { /* sets X to the intersection of line AB with triangle CDE */ float m[3][3]; double d, d1; if(vector_eq(A,B)) { printf("intersection of AB with CDE not found: A=B !!!\n"); return False; } if(vector_eq(C,D) ||vector_eq(C,E) || vector_eq(D,E) ) { printf("intersection of AB with CDE not found: CDE is not a triangle !!!\n"); return False; } vector_sub(D,C, m[0]); vector_sub(E,C, m[1]); vector_sub(A,B, m[2]); d=matrix3_det(m); if(d==0) { printf("intersection of AB with CDE not found: AB and CDE are parallel !!!\n"); return False; } vectorcpy(X, m[2]); vector_sub(A,C, m[2]); d1=matrix3_det(m); *t=d1/d; vector_scale(-d1/d, X); vector_add(A,X, X); return True; }
void constr_scale_in_direction(float A[3], float B[3], float C[3], float D[3], float E[3], float F[3], float fixed_point[3], int g) /* scales group by |AB|/|CD| in direction EF */ { double lAB,lCD,s; float AB[3], CD[3], EF[3], v[3], tmp[3]; double sp; int i; if(vector_eq(E,F)) { printf("scaling in direction EF refused: EF = 0 !!!\n"); return; } vector_sub(B, A, AB); vector_sub(D, C, CD); vector_sub(F, E, EF); vector_normalize(EF); lAB=vector_length(AB); lCD=vector_length(CD); if(lCD==0) { printf("scaling refused: |CD| = 0 !!!\n"); return; } s=lAB/lCD; if(s== 1.0) { printf("scaling by 1 does not change anything !!!\n"); return; } backup(); for(i=0; i<VERTEX_MAX; i++) if(vertex_used[i] && group[i]==g) { vector_sub(vertex[i], fixed_point, v); sp=scalar_product(EF,v); vectorcpy(tmp, EF); vector_scale((s-1)*sp, tmp); vector_add(v,tmp, v); vector_add(v, fixed_point, vertex[i]); } }
static void __bounding_get_intersection_axes(const Bounding *b, Vector *axes) { assert(b && "Bad bounding pointer."); assert(bounding_composite != b->bounding_type && "Can't get axes of composite bounding."); assert(axes && "Bad axes pointer."); axes[0] = *b->direction; axes[1] = *b->orientation; if (!vector_eq(b->direction, b->orientation)) { vector_vector_mul(b->direction, b->orientation, &axes[2]); } else { vector_get_orthogonal(b->direction, &axes[2]); } VECTOR_NORMALIZE(&axes[2]); }
void test_ts_betweenness(tsppi::TsPpiGraph& tsppi) { LOG("Testing graph: " << tsppi.ppi_name); LOG("Testing Betweenness: Naive"); std::vector<std::vector<double> > naive_ts_bw = tsppi::algo::subgraph_betweenness(tsppi.subgraphs); LOG("Testing Betweenness: Fast"); std::vector<std::vector<double> > fast_ts_bw = tsppi::algo::subgraph_betweenness_fast(tsppi.subgraphs); LOG("Checking if results are equal"); if(vector_eq(naive_ts_bw[0], fast_ts_bw[0])) { LOG("Testing SUCCESSFUL!"); } else { LOG("Testing FAILED!"); } }
bool vector_vector_eq(const std::vector<std::vector<T> >& v1, const std::vector<std::vector<T> >& v2) { if (v1.size() != v2.size()) { std::cerr << "ERROR: differing in size" << std::endl; return false; } bool all_equal = true; for (unsigned int j = 0; j < v1.size(); ++j) { if (v1[j].size() != v2[j].size()) { std::cerr << "ERROR: inner array j=" << j << " differing in size" << std::endl; all_equal = false; } else if (!vector_eq(v1[j], v2[j])) { std::cerr << "ERROR: j=" << j << ": v1[j] != v2[j]" << std::endl; all_equal = false; } } return all_equal; }
bool intersection_test(const Bounding *b1, const Bounding *b2, double *intersection_time) { assert(b1 && b2 && "Bad bounding pointers."); assert(intersection_time && "Bad intersection time pointer."); *intersection_time = nan(NULL); if (bounding_composite == b2->bounding_type && bounding_composite != b1->bounding_type) { const Bounding *t = b1; b1 = b2; b2 = t; } if (bounding_composite == b1->bounding_type) { size_t intersections_count = b1->data.composite_data.children_count; double *intersection_times = _alloca(intersections_count * sizeof(double)); // compiler bug? bool *intersection_facts = _alloca(intersections_count * sizeof(bool)); // compiler bug? bool composite_intersection_result = false; for (size_t i = 0; i < intersections_count; i++) { intersection_times[i] = nan(NULL); intersection_facts[i] = intersection_test(b2, &b1->data.composite_data.children[i], &intersection_times[i]); composite_intersection_result |= intersection_facts[i]; } *intersection_time = __get_min_intersection_time(intersection_times, intersection_facts, intersections_count); return composite_intersection_result; } assert(bounding_composite != b1->bounding_type && bounding_composite != b2->bounding_type && "Can't test composite boundings."); Vector axes[6]; double intersection_times[15]; // 6 + 3 * 3. bool intersection_facts[15]; __bounding_get_intersection_axes(b1, &axes[0]); __bounding_get_intersection_axes(b2, &axes[3]); bool intersection_result = true; for (size_t i = 0; i < 6; i++) { intersection_times[i] = nan(NULL); intersection_facts[i] = __bounding_axis_test(b1, b2, &axes[i], &intersection_times[i]); intersection_result &= intersection_facts[i]; } size_t intersection_times_counter = 6; for (size_t i = 0; i < 3; i++) { for (size_t j = 3; j < 6; j++) { if (vector_eq(&axes[i], &axes[j])) { continue; } Vector t; if (!(vector_tolerance_eq(0.0, vector_angle(&axes[i], &axes[j])) || vector_tolerance_eq(M_PI, vector_angle(&axes[i], &axes[j])))) { vector_vector_mul(&axes[i], &axes[j], &t); } else { vector_get_orthogonal(&axes[i], &t); } VECTOR_NORMALIZE(&t); intersection_facts[intersection_times_counter] = __bounding_axis_test(b1, b2, &t, &intersection_times[intersection_times_counter]); intersection_result &= intersection_facts[intersection_times_counter]; intersection_times_counter++; } } *intersection_time = __get_min_intersection_time(intersection_times, intersection_facts, intersection_times_counter); return intersection_result; }
int vertex_used_find(float v[]) { int i; for(i=0; i<VERTEX_MAX && (!vertex_used[i]>0 || !vector_eq(v,vertex[i])); i++); return (i<VERTEX_MAX)? i : -1 ; }
int vertex_find(float v[]) { int i; for(i=0; i<VERTEX_MAX && !(vector_eq(v,vertex[i]) && group[i]== group_current); i++); return (i<VERTEX_MAX)? i : -1 ; }