Wave function collapse: Difference between revisions

C: more consistent use of indexing macros (extremely slight deoptimization -- but should be easier to read now)
(C: use macros for 2- and 3- dimensional index calculations)
(C: more consistent use of indexing macros (extremely slight deoptimization -- but should be easier to read now))
Line 39:
}
};
 
/* avoid problems with slightly egative numbers and C's X%Y */
#define MOD(X,Y) ((Y)+(X))%(Y)
 
char *wfc(char *blocks, int *bdim /* 5,3,3 */, int *tdim /* 8,8 */) {
Line 47 ⟶ 50:
int k= j+td1*i;
int m= 4*k;
adj[m XY(k,0,4)]= XY(MOD(i-1, td0), MOD(j, +td1), td1*((td0+i-1)%td0); /* above (1) */
adj[m+XY(k,1,4)]= XY(MOD(i, td0), MOD(td1+j-1)%, td1 +), td1* i); /* left (3) */
adj[m+XY(k,2,4)]= XY(MOD(i, td0), MOD(j+1)%, td1 +), td1* i); /* right (5) */
adj[m+XY(k,3,4)]= XY(MOD(i+1, td0), MOD(j, +td1), td1*(( i+1)%td0); /* below (7) */
}
}
6,962

edits