summaryrefslogtreecommitdiffstats
path: root/balls.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-31 19:56:31 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-31 19:56:31 -0400
commitaedd626997abe949126b92db7d4536933319c461 (patch)
treeeadeef543f7af02c7351afe96fe6423c465c7cd1 /balls.c
parent111013b9ecb8b4208bfb1109e0f8ce8291fc90df (diff)
downloadballs-aedd626997abe949126b92db7d4536933319c461.zip
move noOverlapPositions to geo
Diffstat (limited to 'balls.c')
-rw-r--r--balls.c31
1 files changed, 1 insertions, 30 deletions
diff --git a/balls.c b/balls.c
index c342b40..20d4ff2 100644
--- a/balls.c
+++ b/balls.c
@@ -59,7 +59,6 @@ void freeGL(void);
void initShaders(void);
char *readFile(const char *filename, size_t *size);
void compileShader(GLint shader);
-Vector *noOverlapPositions(int n);
void frameCount(void);
void drawString(const char *str);
@@ -219,7 +218,7 @@ setPositions(void) {
int err;
/* Generate initial ball positions. */
- hostPositions = noOverlapPositions(nBalls);
+ hostPositions = noOverlapPositions(nBalls, bounds, RMAX);
hostPositionBuf = flatten(hostPositions);
free(hostPositions);
@@ -590,34 +589,6 @@ compileShader(GLint shader) {
}
}
-/*
- * Generate n circle coordinates such that none overlap even if all circles
- * have the maximum radius.
- */
-Vector *
-noOverlapPositions(int n) {
- Vector *ps;
- Rectangle r;
- int i, j;
-
- if ((ps = malloc(n*sizeof(Vector))) == NULL)
- sysfatal("Failed to allocate position array.\n");
-
- r = insetRect(bounds, RMAX);
- for (i = 0; i < n; i++) {
- ps[i] = randPtInRect(r);
- for (j = 0; j < i; j++)
- if (isCollision(ps[j], RMAX, ps[i], RMAX))
- break;
- if (j < i) { /* Overlapping. */
- i--;
- continue;
- }
- }
-
- return ps;
-}
-
void
frameCount(void) {
static int fps = 0;