| 410 | } |
| 411 | |
| 412 | void |
| 413 | testRayBoxIntersection (const Box3f& box) |
| 414 | { |
| 415 | Rand48 random (2007); |
| 416 | |
| 417 | float e = 50 * std::numeric_limits<float>::epsilon (); |
| 418 | |
| 419 | if (box.isEmpty ()) |
| 420 | { |
| 421 | cout << " empty box, no rays intersect" << endl; |
| 422 | |
| 423 | for (int i = 0; i < 100000; ++i) |
| 424 | { |
| 425 | V3f p1 ( |
| 426 | float(random.nextf (box.max.x, box.min.x)), |
| 427 | float(random.nextf (box.max.y, box.min.y)), |
| 428 | float(random.nextf (box.max.z, box.min.z))); |
| 429 | |
| 430 | V3f p2 (p1 + hollowSphereRand<V3f> (random)); |
| 431 | |
| 432 | V3f ip; |
| 433 | assert (!intersects (box, Line3f (p1, p2), ip)); |
| 434 | } |
| 435 | |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | cout << " box = (" << box.min << " " << box.max << ")" << endl; |
| 440 | |
| 441 | if (box.max == box.min) |
| 442 | { |
| 443 | cout << " single-point box, ray intersects" << endl; |
| 444 | |
| 445 | static const float off[6][3] = { |
| 446 | {-1, 0, 0}, |
| 447 | {1, 0, 0}, |
| 448 | {0, -1, 0}, |
| 449 | {0, 1, 0}, |
| 450 | {0, 0, -1}, |
| 451 | {0, 0, 1}}; |
| 452 | |
| 453 | for (int i = 0; i < 6; ++i) |
| 454 | { |
| 455 | V3f p1 ( |
| 456 | box.min.x + off[i][0], |
| 457 | box.min.y + off[i][1], |
| 458 | box.min.z + off[i][2]); |
| 459 | |
| 460 | V3f ip; |
| 461 | assert (intersects (box, Line3f (p1, box.min), ip)); |
| 462 | assert (ip == box.min); |
| 463 | } |
| 464 | |
| 465 | cout << " single-point box, ray does not intersect" << endl; |
| 466 | |
| 467 | for (int i = 0; i < 100000; ++i) |
| 468 | { |
| 469 | // |
no test coverage detected