From f9722f51b1862263811c7152bc83e436bf9ec0ca Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 2 Oct 2023 10:38:27 +0200 Subject: [PATCH] SUCCESS IN PASSING A STRONG RANDOM GRAPHIC TEST --- src/graphics/graphics.c | 97 ++++++++++++++++++++++++----------------- src/ui/window.c | 2 +- 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index b327f5d..2311288 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -23,6 +23,8 @@ * along with this program. If not, see . */ +#include +#include #include "../../include/base.h" #include "../../include/ui.h" #include "../../include/graphics.h" @@ -109,9 +111,12 @@ static void graphics_debug_callback(GLenum source, GLenum type, GLuint id, /* -------------------------------------------------------------------------- */ /* - * void graphics_erase_line (GLuint a, GLuint b){} TODO and to use ? - * As, in this version only lines can be erased, - * similar functions for vertex and plans are not considered. But ?... + * TODO ? + * Should a function "graphics_erase_line (GLuint a, GLuint b)" be used ? + * symetric with graphics_write_line (GLuint a, GLuint b) + * + * NB in this version lines only can be erased, + * and similar functions for vertex and plans have not to be considered. */ /* @@ -634,9 +639,18 @@ static void show_buffers_states(int space_X, int space_Y, int space_Z, int arrow buffer_lines_size_after_cubes, ((space_X+1) * (space_Y+1) + (space_X+1) * (space_Z+1) + (space_Y+1) * (space_Z+1)) * 2, space_X+1, space_Y+1, space_X+1, space_Z+1, space_Y+1, space_Z+1); - printf("\n buffer_lines_offset after arrows = %6d\t%6d = %d + %d; <--> %d = (3 + 4) x 2 x %d (arrows_nb = %d)\n",\ + printf("\n buffer_lines_offset after arrows = %6d\t%6d = %d + %d; <--> %d = (3 + 4) x 2 x %d (arrows_nb = %d)",\ buffer_lines_size, buffer_lines_size, buffer_lines_size_after_cubes,\ buffer_lines_size - buffer_lines_size_after_cubes, arrows_nb * 14, arrows_nb, arrows_nb); + + if (arrows_nb < 0) // LOL ! This error no more exists ! + printf("\n ERR : %d - %d = %d %d = %d x %d\n",\ + arrows_nb * 14, buffer_lines_size - buffer_lines_size_after_cubes,\ + arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes),\ + arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes),\ + (arrows_nb * 14 - (buffer_lines_size - buffer_lines_size_after_cubes)) / arrows_nb, arrows_nb); + + printf("\n WARNING In this test, it may happens that two or several arrow basis are drawn superimposed (check the list).\n"); } @@ -744,7 +758,7 @@ static int set_arrow (GLuint *arrows, int arrows_nb, int requested_weight, int s } - +//#define RAND_MAX /* * Init space and arrows (= initial state) * and allows ulterior creations, suppressions or modifications of the arrows[] array @@ -758,17 +772,28 @@ void main_test_graphics (void) // assert : no more than one arrow per address TODO NOT checked before init // notify : weights are replaced, NOT added (could be !) TODO - int space_X = 4, space_Y = 1, space_Z = 1; + // Initialisation du générateur pseudo-aléatoire + srand(time(NULL)); + int rand(void); + void srand(unsigned int seed); // printf ("Valeur max : %d\n", RAND_MAX); min + rand() % (max+1 - min); + + int arbitrary = 11; + int space_X = 1 + rand() % arbitrary, space_Y = 1 + rand() % arbitrary, space_Z = 1 + rand() % arbitrary; + int density_max = space_X * space_Y * space_Z; + int arrows_nb = rand() % density_max / 3; int pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc // xyz, 0, x, y, z, xy, xz, yz, xyz - GLuint arrows[] = { - 1, 0, 0, 0, 0, - 1, 1, 1, 0, 0, - 1, 0, 2, 0, 0, - 1, 1, 3, 0, 0, - // load, site, x, y, z - }; - int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5; + GLuint arrows[arrows_nb * 5]; + + if (arrows_nb > 0) + for (int i = 0; i < arrows_nb; i ++) { + arrows[i * 5 + 0] = 1 + rand() % arbitrary; // load / weight + arrows[i * 5 + 1] = rand() % 6; // site + arrows[i * 5 + 2] = rand() % space_X; // x + arrows[i * 5 + 3] = rand() % space_Y; // y + arrows[i * 5 + 4] = rand() % space_Z; // z + }; + //int arrows_nb = sizeof(arrows) / sizeof(arrows[0]) / 5; forget, during the random tests show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1); /* GRID */ grid_write_intersections (space_X, space_Y, space_Z); @@ -782,41 +807,33 @@ void main_test_graphics (void) /* ARROWS */ /* NB The 12 vertices required to draw 6 arrows in each cube * are always defined (whether arrows are drawn or not). */ - arrows_write_terminations (space_X, space_Y, space_Z); + if (arrows_nb > 0) arrows_write_terminations (space_X, space_Y, space_Z); - arrows_nb = set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 0, 0, 2, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 1, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 3, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 1, 0, 1, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 1, 1, 2, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 8, 1, 3, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 8, 1, 3, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 3, 0, 0); - arrows_nb = set_arrow (arrows, arrows_nb, 0, 1, 1, 0, 0); +// arrows_nb = set_arrow (arrows, arrows_nb, 0, 0, 0, 0, 0); int weight = 0, site = 0, stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0; - for (int i = 0; i < arrows_nb; i++) { - weight = arrows[i * 5 + 0]; - site = arrows[i * 5 + 1]; - x = arrows[i * 5 + 2]; - y = arrows[i * 5 + 3]; - z = arrows[i * 5 + 4]; + if (arrows_nb > 0) + for (int i = 0; i < arrows_nb; i++) { + weight = arrows[i * 5 + 0]; + site = arrows[i * 5 + 1]; + x = arrows[i * 5 + 2]; + y = arrows[i * 5 + 3]; + z = arrows[i * 5 + 4]; - offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z); - arrow_offset = offset_after_grids + offset_up_to_this_cube_coords; + offset_up_to_this_cube_coords = 12 * (stx * x + sty * y + stz * z); + arrow_offset = offset_after_grids + offset_up_to_this_cube_coords; - arrows_write_basis (arrow_offset); + arrows_write_basis (arrow_offset); - switch(site){ - case EAST: case WEST: write_arrow_lines_east_west (arrow_offset, weight, site); break; - case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (arrow_offset, weight, site); break; - case SOUTH: case NORTH: write_arrow_lines_south_north (arrow_offset, weight, site); break; - default: break; + switch(site){ + case EAST: case WEST: write_arrow_lines_east_west (arrow_offset, weight, site); break; + case ZENITH: case NADIR: write_arrow_lines_zenith_nadir (arrow_offset, weight, site); break; + case SOUTH: case NORTH: write_arrow_lines_south_north (arrow_offset, weight, site); break; + default: break; + } } - } show_buffers_states(space_X, space_Y, space_Z, arrows_nb, offset_after_grids, buffer_vertex_size, diff --git a/src/ui/window.c b/src/ui/window.c index d3f18a0..8463a32 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -231,7 +231,7 @@ static inline GtkWidget *create_axis_slider(int axis) g_signal_connect(adj, "value-changed", G_CALLBACK(on_axis_value_change), GINT_TO_POINTER(axis)); - slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj); + slider = gtk_scale_new(GTK_ORIENTATION_VERTICAL, adj); gtk_box_append(GTK_BOX(box), slider); gtk_widget_set_hexpand(slider, TRUE); gtk_widget_show(slider);