-
Notifications
You must be signed in to change notification settings - Fork 0
/
circleBoxTest.cu_inl
43 lines (34 loc) · 1.15 KB
/
circleBoxTest.cu_inl
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
30
31
32
33
34
35
36
37
38
39
40
41
42
__device__ __inline__ int
circleInBoxConservative(
float circleX, float circleY, float circleRadius,
float boxL, float boxR, float boxT, float boxB)
{
// expand box by circle radius. Test if circle center is in the
// expanded box.
if ( circleX >= (boxL - circleRadius) &&
circleX <= (boxR + circleRadius) &&
circleY >= (boxB - circleRadius) &&
circleY <= (boxT + circleRadius) ) {
return 1;
} else {
return 0;
}
}
__device__ __inline__ int
circleInBox(
float circleX, float circleY, float circleRadius,
float boxL, float boxR, float boxT, float boxB)
{
// clamp circle center to box (finds the closest point on the box)
float closestX = (circleX > boxL) ? ((circleX < boxR) ? circleX : boxR) : boxL;
float closestY = (circleY > boxB) ? ((circleY < boxT) ? circleY : boxT) : boxB;
// is circle radius less than the distance to the closest point on
// the box?
float distX = closestX - circleX;
float distY = closestY - circleY;
if ( ((distX*distX) + (distY*distY)) <= (circleRadius*circleRadius) ) {
return 1;
} else {
return 0;
}
}