Skip to content

Commit

Permalink
Fixed control points clamp function to handle NaN value
Browse files Browse the repository at this point in the history
If the user clicks in a plot that has an invalid (0,0) range, then in vtkContextScene::ProcessItem that is called after mouse events, the mapped mouse position becomes NaN, due to invalid matrix in the ContextScene's transform. This NaN position is then added to the function as a control point with an invalid NaN value. This fix makes sure this does not happen, by clamping the NaN values to minimum bounds on x axis, and 0 on y axis (any value comparison returns false if an operand is NaN, so need to check explicitly).
  • Loading branch information
cpinter committed Mar 14, 2018
1 parent 744d825 commit bc627d8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Charts/Core/vtkControlPointsItem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "vtkSmartPointer.h"
#include "vtkTransform2D.h"
#include "vtkVectorOperators.h"
#include "vtkMath.h"

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -439,7 +440,7 @@ bool vtkControlPointsItem::ClampPos(double pos[2], double bounds[4])
return false;
}
bool clamped = false;
if (pos[0] < bounds[0])
if (pos[0] < bounds[0] || vtkMath::IsNan(pos[0]))
{
pos[0] = bounds[0];
clamped = true;
Expand All @@ -449,7 +450,7 @@ bool vtkControlPointsItem::ClampPos(double pos[2], double bounds[4])
pos[0] = bounds[1];
clamped = true;
}
if (pos[1] < 0.)
if (pos[1] < 0. || vtkMath::IsNan(pos[0]))
{
pos[1] = 0.;
clamped = true;
Expand Down

0 comments on commit bc627d8

Please sign in to comment.