summaryrefslogtreecommitdiffstats
path: root/balls.cl
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-10-30 10:51:15 -0400
committerSam Anthony <sam@samanthony.xyz>2024-10-30 10:51:15 -0400
commitad76ceb696bc8d54c2bd6e0f288161bea1b1117c (patch)
treea60a28acad777962bbfc9d706d475db9a06d7c07 /balls.cl
parent58881645eb1074ca457e325fcbe069b3f773fab6 (diff)
downloadballs-ad76ceb696bc8d54c2bd6e0f288161bea1b1117c.zip
replace EPSILON with FLT_EPSILON
Diffstat (limited to 'balls.cl')
-rw-r--r--balls.cl15
1 files changed, 7 insertions, 8 deletions
diff --git a/balls.cl b/balls.cl
index 6cf4a57..22c3606 100644
--- a/balls.cl
+++ b/balls.cl
@@ -1,7 +1,6 @@
#define G_FACTOR 3600.0
#define G (9.81 / G_FACTOR)
#define DENSITY 1500.0
-#define EPSILON 1e-8 /* Account for FP rounding error. */
float mass(float radius);
int isCollision(float2 p1, float r1, float2 p2, float r2);
@@ -34,10 +33,10 @@ collideWalls(__global float2 *positions, __global float2 *velocities, __global f
r = radii[id];
/* Set bounds. */
- min.x = -1.0 + r + EPSILON;
- min.y = -1.0 + r + EPSILON;
- max.x = 1.0 - r - EPSILON;
- max.y = 1.0 - r - EPSILON;
+ min.x = -1.0 + r + FLT_EPSILON;
+ min.y = -1.0 + r + FLT_EPSILON;
+ max.x = 1.0 - r - FLT_EPSILON;
+ max.y = 1.0 - r - FLT_EPSILON;
/* Check for collision with bounds. */
if (p.x <= min.x || p.x >= max.x) {
@@ -123,7 +122,7 @@ isCollision(float2 p1, float r1, float2 p2, float r2) {
float rhs;
dist = p1 - p2;
- rhs = r1 + r2 + EPSILON;
+ rhs = r1 + r2 + FLT_EPSILON;
return (dist.x*dist.x + dist.y*dist.y) <= rhs*rhs;
}
@@ -134,8 +133,8 @@ setPosition(float2 *p1, float r1, float2 *p2, float r2) {
mid = (*p1 + *p2) / 2.0f;
n = unitNorm(*p2 - *p1);
- *p1 = mid - (n*r1 + EPSILON);
- *p2 = mid + (n*r2 + EPSILON);
+ *p1 = mid - (n*r1 + FLT_EPSILON);
+ *p2 = mid + (n*r2 + FLT_EPSILON);
}
/* Return the velocity of ball 1 after colliding with ball 2. */