/// //Frees resources allocated by a force state // //Parameters: // state: A pointer to the state to free void State_Force_Free(State* state) { struct State_Force_Members* members = (struct State_Force_Members*)state->members; Vector_Free(members->force); Vector_Free(members->radius); free(members); }
/// //Frees a material //Does not free the associated texture!! // //Parameters: // mat: A pointer to the material to free void Material_Free(Material* mat) { Matrix_Free(mat->colorMatrix); Vector_Free(mat->tile); free(mat); }
TEST_F(RangeTest, testRangeTree) { NumericRangeTree *t = NewNumericRangeTree(); ASSERT_TRUE(t != NULL); for (size_t i = 0; i < 50000; i++) { NumericRangeTree_Add(t, i + 1, (double)(1 + prng() % 5000)); } ASSERT_EQ(t->numRanges, 16); ASSERT_EQ(t->numEntries, 50000); struct { double min; double max; } rngs[] = {{0, 100}, {10, 1000}, {2500, 3500}, {0, 5000}, {4999, 4999}, {0, 0}}; for (int r = 0; rngs[r].min || rngs[r].max; r++) { Vector *v = NumericRangeTree_Find(t, rngs[r].min, rngs[r].max); ASSERT_TRUE(Vector_Size(v) > 0); // printf("Got %d ranges for %f..%f...\n", Vector_Size(v), rngs[r].min, rngs[r].max); for (int i = 0; i < Vector_Size(v); i++) { NumericRange *l; Vector_Get(v, i, &l); ASSERT_TRUE(l); // printf("%f...%f\n", l->minVal, l->maxVal); ASSERT_FALSE(l->minVal > rngs[r].max); ASSERT_FALSE(l->maxVal < rngs[r].min); } Vector_Free(v); } NumericRangeTree_Free(t); }
/// //Frees the memory consumed by a Rendering Buffer // //Parameters: // buffer: The buffer to free static void RenderingManager_FreeBuffer(RenderingBuffer* buffer) { ShaderProgram_Free(buffer->shaderPrograms[0]); free(buffer->shaderPrograms); Camera_Free(buffer->camera); Vector_Free(buffer->directionalLightVector); }
int main(int argc, char **argv) { int myints[] = {10, 20, 30, 5, 15}; Vector *v = NewVector(int, 5); for (int i = 0; i < 5; i++) { Vector_Push(v, myints[i]); } Make_Heap(v, 0, v->top, cmp); int n; Vector_Get(v, 0, &n); assert(30 == n); Heap_Pop(v, 0, v->top, cmp); v->top = 4; Vector_Get(v, 0, &n); assert(20 == n); Vector_Push(v, 99); Heap_Push(v, 0, v->top, cmp); Vector_Get(v, 0, &n); assert(99 == n); Vector_Free(v); printf("PASS!\n"); return 0; }
Vector::~Vector() { if (this->m_handle != 0 && this->ownedByMe ) Vector_Free(this->m_handle); }
void Free_AST_OrderNode(AST_OrderNode *orderNode) { if(orderNode != NULL) { for(int i = 0; i < Vector_Size(orderNode->columns); i++) { AST_ColumnNode *c = NULL; Vector_Get(orderNode->columns, i , &c); Free_AST_ColumnNode(c); } Vector_Free(orderNode->columns); free(orderNode); } }
void Free_AST_GraphEntity(AST_GraphEntity *graphEntity) { if(graphEntity->label != NULL) { free(graphEntity->label); } if(graphEntity->alias != NULL) { free(graphEntity->alias); } if(graphEntity->properties != NULL) { for(int i = 0; i < Vector_Size(graphEntity->properties); i++) { SIValue *val; Vector_Get(graphEntity->properties, i, &val); SIValue_Free(val); free(val); } Vector_Free(graphEntity->properties); } free(graphEntity); }
/// //Rotates the rendering manager's camera according to change in mouse position // //Parameters: // GO: The game object this state is attached to // state: The First person camera state updating the gameObject void State_FirstPersonCamera_Rotate(GObject* GO, State* state) { Camera* cam = RenderingManager_GetRenderingBuffer().camera; if(InputManager_GetInputBuffer().mouseLock) { float dt = TimeManager_GetDeltaSec(); int deltaMouseX = (InputManager_GetInputBuffer().mousePosition[0] - InputManager_GetInputBuffer().previousMousePosition[0]); int deltaMouseY = (InputManager_GetInputBuffer().mousePosition[1] - InputManager_GetInputBuffer().previousMousePosition[1]); Vector* axis = Vector_Allocate(); Vector_Initialize(axis, 3); if (deltaMouseX != 0) { axis->components[1] = 1.0f; Camera_Rotate(cam, axis, state->members->rotationSpeed * deltaMouseX); axis->components[1] = 0.0f; } if (deltaMouseY != 0) { axis->components[0] = 1.0f; Camera_Rotate(cam, axis, state->members->rotationSpeed * deltaMouseY); axis->components[0] = 0.0f; } Vector_Free(axis); } }
/// //Frees members in a runner controller state // //Parameters: // state: A pointer to the state to free the members of void State_RunnerController_Free(State* state) { struct State_RunnerController_Members* members = (struct State_RunnerController_Members*)state->members; Vector_Free(members->wallNormal); free(members); }
/* Compute integer hull of truncated linear cone C, i.e., of C with * the origin removed. * Here, we do this by first computing the Hilbert basis of C * and then discarding elements from this basis that are rational * overconvex combinations of other elements in the basis. */ Matrix *Cone_Hilbert_Integer_Hull(Polyhedron *C, struct barvinok_options *options) { int i, j, k; Matrix *hilbert = Cone_Hilbert_Basis(C, options->MaxRays); Matrix *rays, *hull; unsigned dim = C->Dimension; Value tmp; unsigned MaxRays = options->MaxRays; /* When checking for redundant points below, we want to * check if there are any _rational_ solutions. */ POL_UNSET(options->MaxRays, POL_INTEGER); POL_ENSURE_VERTICES(C); rays = Matrix_Alloc(C->NbRays-1, C->Dimension); for (i = 0, j = 0; i < C->NbRays; ++i) { if (value_notzero_p(C->Ray[i][1+C->Dimension])) continue; Vector_Copy(C->Ray[i]+1, rays->p[j++], C->Dimension); } /* We only sort the pointers into the big Value array */ qsort(rays->p, rays->NbRows, sizeof(Value *), lex_cmp); qsort(hilbert->p, hilbert->NbRows, sizeof(Value *), lex_cmp); /* Remove rays from Hilbert basis */ for (i = 0, j = 0, k = 0; i < hilbert->NbRows && j < rays->NbRows; ++i) { if (Vector_Equal(hilbert->p[i], rays->p[j], C->Dimension)) ++j; else hilbert->p[k++] = hilbert->p[i]; } hilbert->NbRows = k; /* Now remove points that are overconvex combinations of other points */ value_init(tmp); for (i = 0; hilbert->NbRows > 1 && i < hilbert->NbRows; ++i) { Matrix *LP; Vector *obj; int nray = rays->NbRows; int npoint = hilbert->NbRows; enum lp_result result; LP = Matrix_Alloc(dim + 1 + nray + (npoint-1), 2 + nray + (npoint-1)); for (j = 0; j < dim; ++j) { for (k = 0; k < nray; ++k) value_assign(LP->p[j][k+1], rays->p[k][j]); for (k = 0; k < npoint; ++k) { if (k == i) value_oppose(LP->p[j][1+nray+npoint-1], hilbert->p[k][j]); else value_assign(LP->p[j][1+nray+k-(k>i)], hilbert->p[k][j]); } } value_set_si(LP->p[dim][0], 1); for (k = 0; k < nray+npoint-1; ++k) value_set_si(LP->p[dim][1+k], 1); value_set_si(LP->p[dim][LP->NbColumns-1], -1); for (k = 0; k < LP->NbColumns-2; ++k) { value_set_si(LP->p[dim+1+k][0], 1); value_set_si(LP->p[dim+1+k][1+k], 1); } /* Somewhat arbitrary objective function. */ obj = Vector_Alloc(LP->NbColumns-1); value_set_si(obj->p[0], 1); value_set_si(obj->p[obj->Size-1], 1); result = constraints_opt(LP, obj->p, obj->p[0], lp_min, &tmp, options); /* If the LP is not empty, the point can be discarded */ if (result != lp_empty) { hilbert->NbRows--; if (i < hilbert->NbRows) hilbert->p[i] = hilbert->p[hilbert->NbRows]; --i; } Matrix_Free(LP); Vector_Free(obj); } value_clear(tmp); hull = Matrix_Alloc(rays->NbRows + hilbert->NbRows, dim+1); for (i = 0; i < rays->NbRows; ++i) { Vector_Copy(rays->p[i], hull->p[i], dim); value_set_si(hull->p[i][dim], 1); } for (i = 0; i < hilbert->NbRows; ++i) { Vector_Copy(hilbert->p[i], hull->p[rays->NbRows+i], dim); value_set_si(hull->p[rays->NbRows+i][dim], 1); } Matrix_Free(rays); Matrix_Free(hilbert); options->MaxRays = MaxRays; return hull; }
// Rotation for the character controller // This should need no changes? void State_CharacterController_Rotate(GObject* GO, State* state) { // create a camera object Camera* cam = RenderingManager_GetRenderingBuffer()->camera; //Get members struct State_CharacterController_Members* members = (struct State_CharacterController_Members*)state->members; // if player's mouse is locked if(InputManager_GetInputBuffer().mouseLock) { // Gets the time per second float dt = TimeManager_GetDeltaSec(); int deltaMouseX = (InputManager_GetInputBuffer().mousePosition[0] - InputManager_GetInputBuffer().previousMousePosition[0]); int deltaMouseY = (InputManager_GetInputBuffer().mousePosition[1] - InputManager_GetInputBuffer().previousMousePosition[1]); Vector* axis = Vector_Allocate(); Vector_Initialize(axis,3); if(deltaMouseX != 0) { axis->components[1] = 1.0f; // rotate the camera //Camera_Rotate(cam,axis,state->members->rotationSpeed * deltaMouseX); Camera_ChangeYaw(cam, members->rotationSpeed * deltaMouseX); axis->components[1] = 0.0f; } if (deltaMouseY != 0) { Vector forwardVector; Vector_INIT_ON_STACK(forwardVector, 3); Matrix_SliceRow(&forwardVector, cam->rotationMatrix, 2, 0, 3); // Keep camera from overextending it's boundaries. if (deltaMouseY > 0) { if (Vector_DotProduct(&forwardVector, &Vector_E2) < 0.7f) { axis->components[0] = 1.0f; Camera_ChangePitch(cam, members->rotationSpeed * deltaMouseY); axis->components[0] = 0.0f; } } else if (deltaMouseY < 0) { if (Vector_DotProduct(&forwardVector, &Vector_E2) > -0.7f) { axis->components[0] = 1.0f; Camera_ChangePitch(cam, members->rotationSpeed * deltaMouseY); axis->components[0] = 0.0f; } } } Vector_Free(axis); } }
int main(int argc, char **argv) { isl_ctx *ctx; int i, nbPol, nbVec, nbMat, func, j, n; Polyhedron *A, *B, *C, *D, *E, *F, *G; char s[128]; struct barvinok_options *options = barvinok_options_new_with_defaults(); argc = barvinok_options_parse(options, argc, argv, ISL_ARG_ALL); ctx = isl_ctx_alloc_with_options(&barvinok_options_args, options); nbPol = nbVec = nbMat = 0; fgets(s, 128, stdin); while ((*s=='#') || ((sscanf(s, "D %d", &nbPol) < 1) && (sscanf(s, "V %d", &nbVec) < 1) && (sscanf(s, "M %d", &nbMat) < 1))) fgets(s, 128, stdin); for (i = 0; i < nbPol; ++i) { Matrix *M = Matrix_Read(); A = Constraints2Polyhedron(M, options->MaxRays); Matrix_Free(M); fgets(s, 128, stdin); while ((*s=='#') || (sscanf(s, "F %d", &func)<1)) fgets(s, 128, stdin); switch(func) { case 0: { Value cb, ck; value_init(cb); value_init(ck); fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; while ((*s=='#') || (value_read(ck, s) != 0)) { fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; } barvinok_count_with_options(A, &cb, options); if (value_ne(cb, ck)) return -1; value_clear(cb); value_clear(ck); break; } case 1: Polyhedron_Print(stdout, P_VALUE_FMT, A); B = Polyhedron_Polar(A, options->MaxRays); Polyhedron_Print(stdout, P_VALUE_FMT, B); C = Polyhedron_Polar(B, options->MaxRays); Polyhedron_Print(stdout, P_VALUE_FMT, C); Polyhedron_Free(C); Polyhedron_Free(B); break; case 2: Polyhedron_Print(stdout, P_VALUE_FMT, A); for (j = 0; j < A->NbRays; ++j) { B = supporting_cone(A, j); Polyhedron_Print(stdout, P_VALUE_FMT, B); Polyhedron_Free(B); } break; case 3: Polyhedron_Print(stdout, P_VALUE_FMT, A); C = B = NULL; barvinok_decompose(A,&B,&C); puts("Pos:"); Polyhedron_Print(stdout, P_VALUE_FMT, B); puts("Neg:"); Polyhedron_Print(stdout, P_VALUE_FMT, C); Domain_Free(B); Domain_Free(C); break; case 4: { Value cm, cb; struct tms tms_before, tms_between, tms_after; value_init(cm); value_init(cb); Polyhedron_Print(stdout, P_VALUE_FMT, A); times(&tms_before); manual_count(A, &cm); times(&tms_between); barvinok_count(A, &cb, 100); times(&tms_after); printf("manual: "); value_print(stdout, P_VALUE_FMT, cm); puts(""); time_diff(&tms_before, &tms_between); printf("Barvinok: "); value_print(stdout, P_VALUE_FMT, cb); puts(""); time_diff(&tms_between, &tms_after); value_clear(cm); value_clear(cb); break; } case 5: Polyhedron_Print(stdout, P_VALUE_FMT, A); B = triangulate_cone(A, 100); Polyhedron_Print(stdout, P_VALUE_FMT, B); check_triangulization(A, B); Domain_Free(B); break; case 6: Polyhedron_Print(stdout, P_VALUE_FMT, A); B = remove_equalities(A, options->MaxRays); Polyhedron_Print(stdout, P_VALUE_FMT, B); Polyhedron_Free(B); break; case 8: { evalue *EP; Matrix *M = Matrix_Read(); const char **param_name; C = Constraints2Polyhedron(M, options->MaxRays); Matrix_Free(M); Polyhedron_Print(stdout, P_VALUE_FMT, A); Polyhedron_Print(stdout, P_VALUE_FMT, C); EP = barvinok_enumerate_with_options(A, C, options); param_name = Read_ParamNames(stdin, C->Dimension); print_evalue(stdout, EP, (const char**)param_name); evalue_free(EP); Polyhedron_Free(C); } case 9: Polyhedron_Print(stdout, P_VALUE_FMT, A); Polyhedron_Polarize(A); C = B = NULL; barvinok_decompose(A,&B,&C); for (D = B; D; D = D->next) Polyhedron_Polarize(D); for (D = C; D; D = D->next) Polyhedron_Polarize(D); puts("Pos:"); Polyhedron_Print(stdout, P_VALUE_FMT, B); puts("Neg:"); Polyhedron_Print(stdout, P_VALUE_FMT, C); Domain_Free(B); Domain_Free(C); break; case 10: { evalue *EP; Value cb, ck; value_init(cb); value_init(ck); fgets(s, 128, stdin); sscanf(s, "%d", &n); for (j = 0; j < n; ++j) { Polyhedron *P; M = Matrix_Read(); P = Constraints2Polyhedron(M, options->MaxRays); Matrix_Free(M); A = DomainConcat(P, A); } fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; while ((*s=='#') || (value_read(ck, s) != 0)) { fgets(s, 128, stdin); /* workaround for apparent bug in older gmps */ *strchr(s, '\n') = '\0'; } C = Universe_Polyhedron(0); EP = barvinok_enumerate_union(A, C, options->MaxRays); value_set_double(cb, compute_evalue(EP, &ck)+.25); if (value_ne(cb, ck)) return -1; Domain_Free(C); value_clear(cb); value_clear(ck); evalue_free(EP); break; } case 11: { isl_space *dim; isl_basic_set *bset; isl_pw_qpolynomial *expected, *computed; unsigned nparam; expected = isl_pw_qpolynomial_read_from_file(ctx, stdin); nparam = isl_pw_qpolynomial_dim(expected, isl_dim_param); dim = isl_space_set_alloc(ctx, nparam, A->Dimension - nparam); bset = isl_basic_set_new_from_polylib(A, dim); computed = isl_basic_set_lattice_width(bset); computed = isl_pw_qpolynomial_sub(computed, expected); if (!isl_pw_qpolynomial_is_zero(computed)) return -1; isl_pw_qpolynomial_free(computed); break; } case 12: { Vector *sample; int has_sample; fgets(s, 128, stdin); sscanf(s, "%d", &has_sample); sample = Polyhedron_Sample(A, options); if (!sample && has_sample) return -1; if (sample && !has_sample) return -1; if (sample && !in_domain(A, sample->p)) return -1; Vector_Free(sample); } } Domain_Free(A); } for (i = 0; i < nbVec; ++i) { int ok; Vector *V = Vector_Read(); Matrix *M = Matrix_Alloc(V->Size, V->Size); Vector_Copy(V->p, M->p[0], V->Size); ok = unimodular_complete(M, 1); assert(ok); Matrix_Print(stdout, P_VALUE_FMT, M); Matrix_Free(M); Vector_Free(V); } for (i = 0; i < nbMat; ++i) { Matrix *U, *V, *S; Matrix *M = Matrix_Read(); Smith(M, &U, &V, &S); Matrix_Print(stdout, P_VALUE_FMT, U); Matrix_Print(stdout, P_VALUE_FMT, V); Matrix_Print(stdout, P_VALUE_FMT, S); Matrix_Free(M); Matrix_Free(U); Matrix_Free(V); Matrix_Free(S); } isl_ctx_free(ctx); return 0; }