Fix(parm.h): allow size to be correctly calculated

This commit is contained in:
PedroEdiaz
2025-05-11 17:28:30 -06:00
parent 8cc9587851
commit 605f4610ce
2 changed files with 18 additions and 16 deletions

View File

@@ -10,7 +10,7 @@
#define M_PI 3.14159265358979323846 #define M_PI 3.14159265358979323846
#endif #endif
unsigned char dim = 10; unsigned char dim = 17;
void cube(float *d_surface, int *coord, unsigned char *grid) void cube(float *d_surface, int *coord, unsigned char *grid)
{ {

View File

@@ -25,7 +25,7 @@ void klein_parametrize( struct klein * klein, struct parm parm );
#include <assert.h> #include <assert.h>
#endif #endif
static inline int __factorial(int n) static inline uint64_t __factorial(uint64_t n)
{ {
if (n == 1) if (n == 1)
return 1; return 1;
@@ -33,7 +33,7 @@ static inline int __factorial(int n)
return n * __factorial(n - 1); return n * __factorial(n - 1);
} }
static inline int __face(int n) static inline uint64_t __face(int n)
{ {
if (n == 2) if (n == 2)
return 1; return 1;
@@ -43,8 +43,8 @@ static inline int __face(int n)
void klein_parametrize( struct klein * klein, struct parm parm) void klein_parametrize( struct klein * klein, struct parm parm)
{ {
unsigned int i, j, k, o, p, n; unsigned long i, j, o, p, n;
unsigned long size, q = 0; uint64_t k, size, q = 0;
int *face; int *face;
#ifdef TEST #ifdef TEST
@@ -56,28 +56,30 @@ void klein_parametrize( struct klein * klein, struct parm parm)
klein->dim = parm.n; klein->dim = parm.n;
klein->vertex_size = 0; klein->vertex_size = 0;
{ {
unsigned char test = 0; uint64_t test = 0;
for (o = 0; o < parm.m; o++) for (o = 0; o < parm.m; o++)
{
for (p = 0; p < o; p++) for (p = 0; p < o; p++)
{
test += 1; test += 1;
klein->vertex_size += parm.grid[p] * parm.grid[o] * 6 * __face(parm.m);
}
} for (o = 0; o < parm.m; o++)
klein->vertex_size /= test; for (p = 0; p < o; p++)
klein->vertex_size += (uint64_t)parm.grid[p] * parm.grid[o] * 6 * __face(parm.m)/test;
} }
size = (klein->dim) * (klein->vertex_size); size = klein->vertex_size*klein->dim;
klein->vertex = malloc(size * sizeof(float)); klein->vertex = malloc(size * sizeof(float));
face = malloc(parm.m * sizeof(int)); face = malloc(parm.m * sizeof(int));
for (o = 0; o < parm.m; o++) for (o = 0; o < parm.m; o++)
{ {
for (p = 0; p < o; p++) for (p = 0; p < o; p++)
{ {
for (k = 0; k < (1 << (parm.m - 2)); k++) for (k = 0; k < ((uint64_t)1 << (parm.m - 2)); k++)
{ {
unsigned char skip = 0; unsigned char skip = 0;
for (n = 0; n < parm.m; n++) for (n = 0; n < parm.m; n++)
@@ -85,7 +87,7 @@ void klein_parametrize( struct klein * klein, struct parm parm)
if (n == o || n == p) if (n == o || n == p)
skip++; skip++;
face[n] = (k & (1 << (n - skip))) ? parm.grid[n] : 0; face[n] = (k & ((uint64_t)1 << (n - skip))) ? parm.grid[n] : 0;
} }
for (i = 0; i < parm.grid[p]; i++) for (i = 0; i < parm.grid[p]; i++)