SUCCESS IN PASSING A STRONG RANDOM GRAPHIC TEST

This commit is contained in:
Jean Sirmai 2023-10-02 10:38:27 +02:00 committed by Adrien 'neox' Bourmault
parent c3c2ca9f9a
commit f9722f51b1
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
2 changed files with 58 additions and 41 deletions

View File

@ -23,6 +23,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include <time.h>
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
#include "../../include/graphics.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 ? * TODO ?
* As, in this version only lines can be erased, * Should a function "graphics_erase_line (GLuint a, GLuint b)" be used ?
* similar functions for vertex and plans are not considered. But ?... * 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, 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); 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, buffer_lines_size_after_cubes,\
buffer_lines_size - buffer_lines_size_after_cubes, arrows_nb * 14, arrows_nb, arrows_nb); 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) * Init space and arrows (= initial state)
* and allows ulterior creations, suppressions or modifications of the arrows[] array * 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 // assert : no more than one arrow per address TODO NOT checked before init
// notify : weights are replaced, NOT added (could be !) TODO // 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 int pref_show_grids = 0; // 0, 1, 2, 3, 5, 6, 10, 15, 30, etc
// xyz, 0, x, y, z, xy, xz, yz, xyz // xyz, 0, x, y, z, xy, xz, yz, xyz
GLuint arrows[] = { GLuint arrows[arrows_nb * 5];
1, 0, 0, 0, 0,
1, 1, 1, 0, 0, if (arrows_nb > 0)
1, 0, 2, 0, 0, for (int i = 0; i < arrows_nb; i ++) {
1, 1, 3, 0, 0, arrows[i * 5 + 0] = 1 + rand() % arbitrary; // load / weight
// load, site, x, y, z 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; //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); show_user_choices(arrows, arrows_nb, space_X, space_Y, space_Z, pref_show_grids, 1);
/* GRID */ /* GRID */
grid_write_intersections (space_X, space_Y, space_Z); grid_write_intersections (space_X, space_Y, space_Z);
@ -782,22 +807,14 @@ void main_test_graphics (void)
/* ARROWS */ /* ARROWS */
/* NB The 12 vertices required to draw 6 arrows in each cube /* NB The 12 vertices required to draw 6 arrows in each cube
* are always defined (whether arrows are drawn or not). */ * 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, 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);
int weight = 0, site = 0, int weight = 0, site = 0,
stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0; stx = space_Z * space_Y, sty = space_Z, stz = 1, arrow_offset = 0;
if (arrows_nb > 0)
for (int i = 0; i < arrows_nb; i++) { for (int i = 0; i < arrows_nb; i++) {
weight = arrows[i * 5 + 0]; weight = arrows[i * 5 + 0];
site = arrows[i * 5 + 1]; site = arrows[i * 5 + 1];

View File

@ -231,7 +231,7 @@ static inline GtkWidget *create_axis_slider(int axis)
g_signal_connect(adj, "value-changed", g_signal_connect(adj, "value-changed",
G_CALLBACK(on_axis_value_change), G_CALLBACK(on_axis_value_change),
GINT_TO_POINTER(axis)); 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_box_append(GTK_BOX(box), slider);
gtk_widget_set_hexpand(slider, TRUE); gtk_widget_set_hexpand(slider, TRUE);
gtk_widget_show(slider); gtk_widget_show(slider);