------------------------------------------------------------------------------
| 588 | |
| 589 | //------------------------------------------------------------------------------ |
| 590 | vtkTypeBool vtkBox::IntersectWithPlane(double bounds[6], double origin[3], double normal[3]) |
| 591 | { |
| 592 | // Evaluate the eight points. If there is a sign change, then there is an |
| 593 | // intersection. |
| 594 | double p[3], d; |
| 595 | int x, y, z, sign = 1, firstOne = 1; |
| 596 | |
| 597 | for (z = 4; z <= 5; ++z) |
| 598 | { |
| 599 | p[2] = bounds[z]; |
| 600 | for (y = 2; y <= 3; ++y) |
| 601 | { |
| 602 | p[1] = bounds[y]; |
| 603 | for (x = 0; x <= 1; ++x) |
| 604 | { |
| 605 | p[0] = bounds[x]; |
| 606 | d = vtkPlane::Evaluate(normal, origin, p); |
| 607 | if (firstOne) |
| 608 | { |
| 609 | sign = (d >= 0 ? 1 : -1); |
| 610 | firstOne = 0; |
| 611 | } |
| 612 | if (d == 0.0 || (sign > 0 && d < 0.0) || (sign < 0 && d > 0.0)) |
| 613 | { |
| 614 | return 1; |
| 615 | } |
| 616 | } // x |
| 617 | } // y |
| 618 | } // z |
| 619 | |
| 620 | return 0; // no intersection |
| 621 | } |
| 622 | |
| 623 | //------------------------------------------------------------------------------ |
| 624 | // Support for IntersectWithPlane |
no test coverage detected