space dimension

This commit is contained in:
Adrien Bourmault 2021-06-16 13:06:23 +02:00
parent bff453bb33
commit de284948d7
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
3 changed files with 29 additions and 16 deletions

View File

@ -30,6 +30,11 @@
#define BASE_H #define BASE_H
struct {
size_t size;
int *space;
} typedef IntArray_t;
struct { struct {
int x; int x;
int y; int y;
@ -60,11 +65,6 @@ struct {
SpaceUnit_t *space; SpaceUnit_t *space;
} typedef Space_t; } typedef Space_t;
struct {
size_t size;
int *space;
} typedef IntArray_t;
#define LOGMSG "[%s]" #define LOGMSG "[%s]"
#define printLog(FORMAT, ...) printf(LOGMSG " " FORMAT, __func__, ##__VA_ARGS__) #define printLog(FORMAT, ...) printf(LOGMSG " " FORMAT, __func__, ##__VA_ARGS__)

View File

@ -26,8 +26,11 @@
#define ARROW_NUMBER 150 #define ARROW_NUMBER 150
#define MAX_CYCLES 15 #define MAX_CYCLES 15
#define SPACE_SIZE 10000
#define MAX_THREAD 0 #define MAX_THREAD 0
#define XMAX 1000
#define YMAX 1000
#define ZMAX 0
#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -53,6 +56,9 @@ int main(int argc, char **argv)
scheduler0->globalDrawingSpace->space = scheduler0->globalDrawingSpace->space =
(SpaceUnit_t*) calloc(SPACE_SIZE, sizeof(SpaceUnit_t)); (SpaceUnit_t*) calloc(SPACE_SIZE, sizeof(SpaceUnit_t));
scheduler0->globalDrawingSpace->size = SPACE_SIZE; scheduler0->globalDrawingSpace->size = SPACE_SIZE;
scheduler0->globalDrawingSpace->xmax = SPACE_SIZE;
scheduler0->globalDrawingSpace->ymax = SPACE_SIZE;
scheduler0->globalDrawingSpace->zmax = SPACE_SIZE;
scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t)); scheduler0->arrowList = (ArrowArray_t*) calloc(1, sizeof(ArrowArray_t));
scheduler0->arrowList->array = scheduler0->arrowList->array =
@ -61,12 +67,18 @@ int main(int argc, char **argv)
printLog("Populating a random arrow list...\n"); printLog("Populating a random arrow list...\n");
for (int i = 0; i < ARROW_NUMBER; i++) { for (int i = 0; i < ARROW_NUMBER; i++) {
scheduler0->arrowList->array[i].x =
rand() % scheduler0->globalDrawingSpace->xmax; if (scheduler0->globalDrawingSpace->xmax)
scheduler0->arrowList->array[i].y = scheduler0->arrowList->array[i].x =
rand() % scheduler0->globalDrawingSpace->ymax; rand() % (scheduler0->globalDrawingSpace->xmax + 1);
scheduler0->arrowList->array[i].z =
rand() % scheduler0->globalDrawingSpace->zmax; if (scheduler0->globalDrawingSpace->ymax)
scheduler0->arrowList->array[i].y =
rand() % (scheduler0->globalDrawingSpace->ymax + 1);
if (scheduler0->globalDrawingSpace->zmax)
scheduler0->arrowList->array[i].z =
rand() % (scheduler0->globalDrawingSpace->zmax + 1);
} }
scheduler0->nmaxThread = MAX_THREAD; scheduler0->nmaxThread = MAX_THREAD;

View File

@ -49,15 +49,16 @@ static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
{ {
register Center_t *currentCenter, *newCenter; register Center_t *currentCenter, *newCenter;
currentCenter = centersList; currentCenter = centersList->next;
newCenter = (Center_t*) malloc(sizeof(Center_t)); newCenter = (Center_t*) malloc(sizeof(Center_t));
while (currentCenter){ while (currentCenter){
if ( abs(electedArrow->x - currentCenter->x) <= ruleRadius if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius))
|| abs(electedArrow->y - currentCenter->y) <= ruleRadius || (ymax && (abs(electedArrow->y - currentCenter->y) <= ruleRadius))
|| abs(electedArrow->z - currentCenter->z) <= ruleRadius || (zmax && (abs(electedArrow->z - currentCenter->z) <= ruleRadius))
){ ){
free(newCenter); free(newCenter);
//printLog("Can't find a free area\n");
return NULL; return NULL;
} }
currentCenter = currentCenter->next; currentCenter = currentCenter->next;