---------------------------------------------------------------------------
| 670 | |
| 671 | // --------------------------------------------------------------------------- |
| 672 | bool vtkBoundingBox::IntersectsLine(const double p1[3], const double p2[3]) const |
| 673 | { |
| 674 | if (this->ContainsPoint(p1) || this->ContainsPoint(p2)) |
| 675 | { |
| 676 | return true; |
| 677 | } |
| 678 | |
| 679 | if (vtkMathUtilities::NearlyEqual(p1[0], p2[0]) && vtkMathUtilities::NearlyEqual(p1[1], p2[1]) && |
| 680 | vtkMathUtilities::NearlyEqual(p1[2], p2[2])) |
| 681 | { |
| 682 | return false; |
| 683 | } |
| 684 | |
| 685 | double line[3]; |
| 686 | vtkMath::Subtract(p2, p1, line); |
| 687 | vtkMath::Normalize(line); |
| 688 | |
| 689 | const double* points[2] = { p1, p2 }; |
| 690 | const double* bbPoints[2] = { this->MinPnt, this->MaxPnt }; |
| 691 | |
| 692 | for (int dim = 0; dim < 3; ++dim) |
| 693 | { |
| 694 | if (std::abs(line[dim]) > VTK_DBL_EPSILON) |
| 695 | { |
| 696 | for (int pointId = 0; pointId < 2; ++pointId) |
| 697 | { |
| 698 | const double* p = points[pointId]; |
| 699 | const double* bbp = bbPoints[pointId]; |
| 700 | double t = (bbp[dim] - p[dim]) / line[dim]; |
| 701 | int orthdimx = (dim + 1) % 3; |
| 702 | int orthdimy = (dim + 2) % 3; |
| 703 | double x = p[orthdimx] + t * line[orthdimx]; |
| 704 | double y = p[orthdimy] + t * line[orthdimy]; |
| 705 | if (x - this->MinPnt[orthdimx] >= |
| 706 | -VTK_DBL_EPSILON * std::max(std::abs(x), std::abs(this->MinPnt[orthdimx])) && |
| 707 | x - this->MaxPnt[orthdimx] <= |
| 708 | VTK_DBL_EPSILON * std::max(std::abs(x), std::abs(this->MaxPnt[orthdimx])) && |
| 709 | y - this->MinPnt[orthdimy] >= |
| 710 | -VTK_DBL_EPSILON * std::max(std::abs(x), std::abs(this->MinPnt[orthdimy])) && |
| 711 | y - this->MaxPnt[orthdimy] <= |
| 712 | VTK_DBL_EPSILON * std::max(std::abs(x), std::abs(this->MaxPnt[orthdimy]))) |
| 713 | { |
| 714 | return true; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | return false; |
| 720 | } |
| 721 | |
| 722 | // --------------------------------------------------------------------------- |
| 723 | void vtkBoundingBox::GetDistance(double point[3], double distance[3]) |
nothing calls this directly
no test coverage detected