Skip to content

Commit bc627d8

Browse files
committed
Fixed control points clamp function to handle NaN value
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).
1 parent 744d825 commit bc627d8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Charts/Core/vtkControlPointsItem.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "vtkSmartPointer.h"
3232
#include "vtkTransform2D.h"
3333
#include "vtkVectorOperators.h"
34+
#include "vtkMath.h"
3435

3536
#include <algorithm>
3637
#include <cassert>
@@ -439,7 +440,7 @@ bool vtkControlPointsItem::ClampPos(double pos[2], double bounds[4])
439440
return false;
440441
}
441442
bool clamped = false;
442-
if (pos[0] < bounds[0])
443+
if (pos[0] < bounds[0] || vtkMath::IsNan(pos[0]))
443444
{
444445
pos[0] = bounds[0];
445446
clamped = true;
@@ -449,7 +450,7 @@ bool vtkControlPointsItem::ClampPos(double pos[2], double bounds[4])
449450
pos[0] = bounds[1];
450451
clamped = true;
451452
}
452-
if (pos[1] < 0.)
453+
if (pos[1] < 0. || vtkMath::IsNan(pos[0]))
453454
{
454455
pos[1] = 0.;
455456
clamped = true;

0 commit comments

Comments
 (0)