Skip to content
Snippets Groups Projects
Commit 7acbc444 authored by arnaud.devevey's avatar arnaud.devevey
Browse files

debut aprem

parent 94362057
No related branches found
No related tags found
No related merge requests found
Pipeline #6069 failed
...@@ -8,23 +8,23 @@ ...@@ -8,23 +8,23 @@
* * * *
* * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * */
Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1) { Box new_box(double new_x0, double new_y0, double new_x1, double new_y1) {
Box* temp_box = malloc(sizeof(Box)); Box temp_box;
if (new_x0 > new_x1) { if (new_x0 > new_x1) {
temp_box -> x0 = new_x1; temp_box.x0 = new_x1;
temp_box -> x1 = new_x0; temp_box.x1 = new_x0;
} else { } else {
temp_box -> x0 = new_x0; temp_box.x0 = new_x0;
temp_box -> x1 = new_x1; temp_box.x1 = new_x1;
} }
if (new_y0 > new_y1) { if (new_y0 > new_y1) {
temp_box -> y0 = new_y1; temp_box.y0 = new_y1;
temp_box -> y1 = new_y0; temp_box.y1 = new_y0;
} else { } else {
temp_box -> y0 = new_y0; temp_box.y0 = new_y0;
temp_box -> y1 = new_y1; temp_box.y1 = new_y1;
} }
...@@ -32,7 +32,7 @@ Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1) { ...@@ -32,7 +32,7 @@ Box* new_box(double new_x0, double new_y0, double new_x1, double new_y1) {
} }
Box* divide_in_four(Box* box) { Box* divide_in_four(Box box) {
/* /*
(x0 ; y0) (x0 ; y0)
...@@ -49,13 +49,13 @@ Box* divide_in_four(Box* box) { ...@@ -49,13 +49,13 @@ Box* divide_in_four(Box* box) {
*/ */
Box* b0 = new_box(box -> x0, box -> y0, box -> x1/2, box -> y1/2); Box b0 = new_box(box.x0, box.y0, box.x1/2.0, box.y1/2.0);
Box* b1 = new_box(box -> x1/2, box -> y0, box -> x1, box -> y1/2); Box b1 = new_box(box.x1/2.0, box.y0, box.x1, box.y1/2.0);
Box* b2 = new_box(box -> x0, box -> y1/2, box -> x1/2, box -> y1); Box b2 = new_box(box.x0, box.y1/2.0, box.x1/2.0, box.y1);
Box* b3 = new_box(box -> x1/2, box -> y1/2, box -> x1, box -> y1); Box b3 = new_box(box.x1/2.0, box.y1/2.0, box.x1, box.y1);
// pointeur ou pas? // pointeur ou pas?
Box* sub_boxes[] = malloc(4 * sizeof(Box*)); Box* sub_boxes = malloc(4 * sizeof(Box));
sub_boxes[0] = b0; sub_boxes[0] = b0;
sub_boxes[1] = b1; sub_boxes[1] = b1;
sub_boxes[2] = b2; sub_boxes[2] = b2;
...@@ -105,33 +105,26 @@ void print_box(Box box) { ...@@ -105,33 +105,26 @@ void print_box(Box box) {
void tests_box() { void tests_box() {
printf("TESTS BOX : \n"); printf("TESTS BOX : \n");
Box* b1 = new_box(0.0, 0.0, 3.0, 3.0); Box b1 = new_box(0.0, 0.0, 3.0, 3.0);
Box* b2 = divide_in_four(b1); Box* b2 = divide_in_four(b1);
tests_box_new(b1);
tests_box_divide(b2); tests_box_divide(b2);
tests_box_include(b1); tests_box_include(b1);
free(b1);
free(b2); free(b2);
printf("\n"); printf("\n");
} }
void tests_box_new(Box* b1) { void tests_box_divide(Box* b) {
TEST(b1 != NULL); Box box_test = new_box(1.5, 0.0, 3.0, 1.5);
} TEST(box_test.x0 == b[1].x0 && box_test.x1 == b[1].x1 && box_test.y0 == b[1].y0 && box_test.y1 == b[1].y1);
void tests_box_divide(Box* b2) {
// COMPLETER APRES AVOIR FINI DIVIDE()
printf("bla");
} }
void tests_box_include(Box* b1) { void tests_box_include(Box b1) {
Vector* vector = new_vec(1.0, 2.0); Vector* vector = new_vec(1.0, 2.0);
TEST(is_inside(*b1, *vector)); TEST(is_inside(b1, *vector));
free(vector); free(vector);
} }
\ No newline at end of file
...@@ -23,10 +23,10 @@ typedef struct __box { ...@@ -23,10 +23,10 @@ typedef struct __box {
* * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * */
// crée une nouvelle box // crée une nouvelle box
Box* new_box(double new_x0, double new_y0, double new_x1, 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 // 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 // détérmine si une position est dans la box
bool is_inside(Box box, Vector vector); bool is_inside(Box box, Vector vector);
...@@ -39,8 +39,8 @@ void print_box(Box box); ...@@ -39,8 +39,8 @@ void print_box(Box box);
void tests_box(); void tests_box();
void tests_box_new(Box* b1); // void tests_box_new(Box b);
void tests_box_divide(Box* b2); void tests_box_divide(Box* b);
void tests_box_include(Box* b1); void tests_box_include(Box b);
#endif #endif
\ No newline at end of file
#ifndef __TESTS_H__
#define __TESTS_H__
#define TEST(x) \
if (x) \
PRT_OK else PRT_NOK
// OK print en vert, error en rouge
#define PRT_OK printf("\t%s() : %sok%s\n", __func__, "\t[\x1B[32m", "\x1B[0m]");
#define PRT_NOK printf("\t%s() : %serror%s\n", __func__, "\t[\x1B[31m", "\x1B[0m]");
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment