Commit ca83ef71 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

vtkBoundingBox::AddBounds() was working incorrectly for invalid bounds.

If either the current value of the vtkBoundingBox instance was invalid or if the
added bounds were invalid, AddBounds() was totally messing itself up. Fixed the
logic to handle invalid bounds.
parent 3fad2fad
......@@ -47,23 +47,28 @@ void vtkBoundingBox::AddPoint(double p[3])
// ---------------------------------------------------------------------------
void vtkBoundingBox::AddBox(const vtkBoundingBox &bbox)
{
int i;
for (i = 0; i < 3; i++)
{
if (bbox.MinPnt[i] < this->MinPnt[i])
{
this->MinPnt[i] = bbox.MinPnt[i];
}
if (bbox.MaxPnt[i] > this->MaxPnt[i])
{
this->MaxPnt[i] = bbox.MaxPnt[i];
}
}
double bds[6];
bbox.GetBounds(bds);
this->AddBounds(bds);
}
// ---------------------------------------------------------------------------
void vtkBoundingBox::AddBounds(double bounds[6])
{
bool this_valid = (this->IsValid() != 0);
bool other_valid = (vtkBoundingBox::IsValid(bounds) != 0);
if (!other_valid)
{
return;
}
if (other_valid && !this_valid)
{
this->SetBounds(bounds);
return;
}
if (bounds[0] < this->MinPnt[0])
{
this->MinPnt[0] = bounds[0];
......
......@@ -156,6 +156,7 @@ public:
// Returns 1 if the bounds have been set and 0 if the box is in its
// initialized state which is an inverted state
int IsValid() const;
static int IsValid(double bounds[6]);
// Description:
// Returns the box to its initialized state
......@@ -218,6 +219,13 @@ inline int vtkBoundingBox::IsValid() const
(this->MinPnt[2] <= this->MaxPnt[2]));
}
inline int vtkBoundingBox::IsValid(double bounds[6])
{
return (bounds[0] <= bounds[1] &&
bounds[2] <= bounds[3] &&
bounds[4] <= bounds[5]);
}
inline double vtkBoundingBox::GetLength(int i) const
{
return this->MaxPnt[i] - this->MinPnt[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment