summaryrefslogtreecommitdiffstats
path: root/balls.h
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-29 20:16:06 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-29 20:16:06 -0400
commit73a4a9569041c984416466aacb42be2d8868dad3 (patch)
treeb6795d59ac698181db901e636033749f3cdb5e95 /balls.h
parent9b718d4dc1bd21687a6a036cf0168fd7a73f8197 (diff)
downloadballs-73a4a9569041c984416466aacb42be2d8868dad3.zip
ball-ball collisions (untested)
Diffstat (limited to 'balls.h')
-rw-r--r--balls.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/balls.h b/balls.h
index 051c185..a767db0 100644
--- a/balls.h
+++ b/balls.h
@@ -4,6 +4,22 @@ typedef struct {
float2 min, max;
} Rectangle;
+/*
+ * A partition of the set of all possible collisions between pairs of balls.
+ * Collisions within a cell of the partition can run concurrently. Cells must
+ * run sequentially.
+*/
+typedef struct {
+ struct cell {
+ size_t (*ballIndices)[2]; /* Array of pairs of ball indices. */
+ size_t size; /* Length of ballIndices. */
+ } *cells; /* Array of cells. */
+ size_t size; /* Length of cell array. */
+} Partition;
+
+Partition partitionCollisions(size_t nBalls);
+void freePartition(Partition part);
+
int isCollision(float2 p1, float r1, float2 p2, float r2);
Rectangle insetRect(Rectangle r, float n);