summaryrefslogtreecommitdiffstats
path: root/balls.h
blob: c19b94800ab9e95c8e5b8296c760cb4db218e996 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
typedef float float2 __attribute__ ((vector_size (2*sizeof(float))));

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);
void printPartition(Partition part);

int isCollision(float2 p1, float r1, float2 p2, float r2);
Rectangle insetRect(Rectangle r, float n);

float randFloat(float lo, float hi);
float2 randPtInRect(Rectangle r);
float2 randVec(float xmin, float xmax, float ymin, float ymax);