diff --git a/perso/box.c b/perso/box.c index 43ef2363ee116a23281f5e155139e95622b4110c..848969dafa5466772d33816f6a467c92bcd3e565 100644 --- a/perso/box.c +++ b/perso/box.c @@ -8,7 +8,7 @@ * * * * * * * * * * * * * * * * * * */ -Box* new_box(double new_x0, double new_x1, double new_y0, double new_y1) { +Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1) { Box* temp_box = malloc(sizeof(Box)); if (new_x0 > new_x1) { @@ -32,27 +32,37 @@ Box* new_box(double new_x0, double new_x1, double new_y0, double new_y1) { } -Box* divide_in_four(Box box) { - Box* sub_boxes = malloc(sizeof(Box) * 4); - - // retourner quatre box +Box* divide_in_four(Box* box) { /* - x0 = 0 y0 = 0 + (x0 ; y0) ------------------- | | | | | | - ------------------- x1 = 5 y1 = 3 + ------------------- (x1 ; y1) - box0 (ul) : (0;0) (x1/2;y1/2) - box1 (ur) : (x1/2;0) (x1;y1/2) - box2 (ll) : (0;y1/2) (x1/2;y1) + box0 (ul) : (x0;y0) (x1/2;y1/2) + box1 (ur) : (x1/2;y0) (x1;y1/2) + box2 (ll) : (x0;y1/2) (x1/2;y1) box3 (lr) : (x1/2;y1/2) (x1;y1) - */ + Box* b0 = new_box(box -> x0, box -> y0, box -> x1/2, box -> y1/2); + Box* b1 = new_box(box -> x1/2, box -> y0, box -> x1, box -> y1/2); + Box* b2 = new_box(box -> x0, box -> y1/2, box -> x1/2, box -> y1); + Box* b3 = new_box(box -> x1/2, box -> y1/2, box -> x1, box -> y1); + + // pointeur ou pas? + Box* sub_boxes[] = malloc(4 * sizeof(Box*)); + sub_boxes[0] = b0; + sub_boxes[1] = b1; + sub_boxes[2] = b2; + sub_boxes[3] = b3; + + + return sub_boxes; @@ -95,8 +105,8 @@ void print_box(Box box) { void tests_box() { printf("TESTS BOX : \n"); - Box* b1 = new_box(0.0, 3.0, 0.0, 3.0); - Box* b2 = divide_in_four(*b1); + Box* b1 = new_box(0.0, 0.0, 3.0, 3.0); + Box* b2 = divide_in_four(b1); tests_box_new(b1); @@ -116,6 +126,7 @@ void tests_box_new(Box* b1) { void tests_box_divide(Box* b2) { // COMPLETER APRES AVOIR FINI DIVIDE() + printf("bla"); } void tests_box_include(Box* b1) { diff --git a/perso/box.h b/perso/box.h index 84d86b3320948baa69b4f1ad68a18df43e63e6b5..7fcd14d2ae6b51f107f569fe1adcc5f183ee167e 100644 --- a/perso/box.h +++ b/perso/box.h @@ -23,10 +23,10 @@ typedef struct __box { * * * * * * * * * * * * * * * * */ // crée une nouvelle box -Box* new_box(double new_x0, double new_x1, double new_y0, double new_y1); +Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1); // divise une box en quatre parties égales -Box* divide_in_four(Box box); +Box* divide_in_four(Box* box); // détérmine si une position est dans la box bool is_inside(Box box, Vector vector); diff --git a/perso/star.c b/perso/star.c index 95eac0d9cc7705dc7b3b178a3ea12b03078727aa..5fb350b7095414457807d292f28b6163a7d01eac 100644 --- a/perso/star.c +++ b/perso/star.c @@ -67,15 +67,26 @@ void print_star(const Star* const star) { } /* -il faut deja faire une liste de stars qui se trouvent dans une box -Star* super_star(Star* list_stars) { +// il faut deja faire une liste de stars qui se trouvent dans une box +Star* super_star(Star* list_stars, int size_list) { Star* super_star = malloc(sizeof(Star)) - for (int i = 0; i < list_stars.len() MARCHE PAS COMME CA; i++) { - super_star -> pos += list_stars[i] -> pos; + for (int i = 0; i < size_list; i++) { + // position + super_star -> pos -> x += list_stars[i] -> pos -> x; + super_star -> pos -> y += list_stars[i] -> pos -> y; + + // accélération + super_star -> acc -> x += list_stars[i] -> acc -> x; + super_star -> acc -> y += list_stars[i] -> acc -> y; + + // masse + super_star -> mass -> x += list_stars[i] -> pos -> masse; + } - super_star -> # /= list_stars.len() + // ne donne pas la même chose si on fait /= 2 pour chaque boucle for + super_star -> mass /= size_list; return super_star; }