diff --git a/perso/galaxy.c b/perso/galaxy.c index 6ad649c31e199b711e3305989eb55f82d43a569e..099bba2c6b60424f60e66acf38e0389eee306968 100644 --- a/perso/galaxy.c +++ b/perso/galaxy.c @@ -40,9 +40,11 @@ int main(int argc, char **argv) { printf("\n\n"); tests(); + + double zone = 1e10; Box box_initial = new_box(-zone, zone, zone, -zone); - // Galaxy* galaxy = create_and_init_galaxy(nb_stars, box_initial, DELTA_T); + Galaxy* galaxy = create_and_init_galaxy(nb_stars, box_initial, DELTA_T); @@ -61,7 +63,7 @@ int main(int argc, char **argv) { destruction_galaxie(); */ - + free_galaxy(galaxy); } else { printf("\nNombre d'arguments non valide \n\n"); @@ -80,7 +82,7 @@ int main(int argc, char **argv) { * * * * * * * * * * * * * * * * */ Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) { - Star* list_stars = malloc(sizeof(Star) * nb_bodies); + Star** list_stars = malloc(sizeof(Star*) * nb_bodies); Vector* v_null = new_vec(0, 0); Star* temp; @@ -92,17 +94,20 @@ Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) { } else { double m_i = random_mass(); - Vector r_i = random_position(); - // si pos est dans box Vector v_i = random_speed(r_i, m_i); + Vector r_i; + do { + r_i = random_position(); + } while (!is_inside(box, r_i)); + temp = new_star_vel(r_i, v_i, *v_null, m_i, 0.0); } - list_stars[i] = *temp; + list_stars[i] = temp; // on regarde comment cette étoile se fait attirer par le "soleil" - // update_acc(list_stars[i], list_stars[0]); + update_acc(list_stars[i], list_stars[0]); } @@ -110,6 +115,7 @@ Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) { galaxy -> nb_bodies = nb_bodies; galaxy -> stars = list_stars; galaxy -> box = box; + return galaxy; } @@ -120,9 +126,6 @@ void reset_acc_galaxy(Galaxy* galaxy) { for (int i = 0; i < galaxy -> nb_bodies; i++) { galaxy -> stars[i].acc = *v_null; - - /*if (galaxy -> stars[i] != NULL) { - }*/ } free(v_null); @@ -137,11 +140,13 @@ void update_pos_galaxy(Galaxy* galaxy, double delta_t) { void free_galaxy(Galaxy* galaxy) { - /* for (int i = 0; i < galaxy -> nb_bodies; i++) { - free(galaxy -> stars[i]); + if (!is_inside(galaxy -> box, galaxy -> stars[i].pos)) { + free(&(galaxy -> stars[i])); + galaxy -> nb_bodies--; + } } - */ + } @@ -160,6 +165,24 @@ void tests() { tests_vector(); tests_box(); tests_star(); + tests_galaxy(); // tests_quadtree(); - // tests_galaxy(); +} + + + + + +/* * * * * * * * * * * * * * * * * +* * +* --- TESTS --- * +* * +* * * * * * * * * * * * * * * * */ + +void tests_galaxy() { + printf("TESTS GALAXY : \n"); + + + + printf("\n"); } \ No newline at end of file diff --git a/perso/star.c b/perso/star.c index 50715aa9a7531bc7df21949c9339d34191eeb004..3159364d6432509ac23013d2c6debb95ba1288b4 100644 --- a/perso/star.c +++ b/perso/star.c @@ -142,20 +142,21 @@ Vector* resultante(Vector* list_stars, int size_list) { int G_mi_mj = FORCE_GRAVITATION * list_stars[i] -> mass * list_stars[j] -> mass; Vector* temp = mul_vec(rj_ri, G_mi_mj); - Fi = add_vec(Fi, temp) + Fi = add_vec(Fi, temp); */ } } } - - Fi -> x /= size_list; - Fi -> y /= size_list; return Fi; } void new_position(Star* star, Vector resultante) { - star -> acc = *(add_vec(&(star -> acc), &resultante)); + Vector* acc_tmp = add_vec(&(star -> acc), &resultante); + star -> acc = *acc_tmp; + + free(acc_tmp); + acc_tmp = NULL; } @@ -187,9 +188,10 @@ void tests_star() { Vector* acceleration = new_vec(4.0, 5.0); Star* s1 = new_star_vel(*position, *speed, *acceleration, MASSE_MIN, DELTA_T); - // print_star(s1); tests_star_new(s1); + // tests_star_acc(s1); LEAK + // tests_stars_res(s1); ERREUR free(s1); @@ -198,19 +200,38 @@ void tests_star() { free(acceleration); + printf("\n"); } void tests_star_new(Star* s) { - Star star_test; double x = 4.0; double y = 5.0; - //star_test.previous_pos = ; - //star_test.acc = ; - //star_test.mass = ; TEST( s -> pos.x == x && s -> pos.y == y && \ - s -> previous_pos.x == x && s -> previous_pos.y == y && \ + s -> previous_pos.x == (4e10 - x) && s -> previous_pos.y == (5e10 - y) && \ s -> acc.x == x && s -> acc.y == y && \ s -> mass == 1e20); -} \ No newline at end of file +} + +void tests_star_acc(Star* s) { + Vector* v_test = new_vec(1.0, 1.0); + Star star_test; + star_test.pos = *v_test; + star_test.mass = 1e20; + update_acc(s, &star_test); + + free(v_test); +} + +void tests_star_pos() { + +} + +void tests_stars_res(Star* star) { + Vector* v_test = new_vec(-5.0, 4.0); + new_position(star, *v_test); + + TEST(star -> pos.x == -1.0 && star -> pos.y == 9.0); + free(v_test); +} \ No newline at end of file diff --git a/perso/star.h b/perso/star.h index 52d40ea3d693a56a09d31b0241fa991a4a4b9b8f..501713c24f0ab28175cfd70e87a9f4f7bba76a9d 100644 --- a/perso/star.h +++ b/perso/star.h @@ -80,5 +80,9 @@ double random_1(); void tests_star(); +void tests_star_new(Star* s); + +void tests_stars_res(Star* star); + #endif \ No newline at end of file