Skip to content

Commit a8396ca

Browse files
Fix plot scale for (near) constant plots
For plot signals whose data Y-range is small enough to be effectively constant (depends on plot view port size, but roughly less than 1e-300), the computed scale for the Y axis was overflowing to +infinity. An infinite scale then results in the plot not being rendered, so this adds checks to set the X/Y scales to 1.0 if they are infinite.
1 parent ba5f109 commit a8396ca

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cisstVector/code/vctPlot2DBase.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ void vctPlot2DBase::Scale::FitX(double min, double max, double padding)
7373
{
7474
this->ViewingRangeX.Assign(min, max);
7575
this->ScaleValue.X() = this->Viewport.X() / ((max - min) * (1.0 + padding));
76+
if (!cmnTypeTraits<double>::IsFinite(ScaleValue.X())) { ScaleValue.X() = 1.0; }
77+
7678
this->Translation.X() =
7779
- min * this->ScaleValue.X()
7880
+ 0.5 * padding * this->Viewport.X();
@@ -102,6 +104,8 @@ void vctPlot2DBase::Scale::FitY(double min, double max, double padding)
102104
{
103105
this->ViewingRangeY.Assign(min, max);
104106
this->ScaleValue.Y() = this->Viewport.Y() / ((max - min) * (1.0 + padding));
107+
if (!cmnTypeTraits<double>::IsFinite(ScaleValue.Y())) { ScaleValue.Y() = 1.0; }
108+
105109
this->Translation.Y() =
106110
- min * this->ScaleValue.Y()
107111
+ 0.5 * padding * this->Viewport.Y();
@@ -122,6 +126,9 @@ void vctPlot2DBase::Scale::FitXY(vctDouble2 min, vctDouble2 max, const vctDouble
122126
vctDouble2 dataDiff;
123127
dataDiff.DifferenceOf(max, min);
124128
this->ScaleValue.ElementwiseRatioOf(this->Viewport, dataDiff);
129+
if (!cmnTypeTraits<double>::IsFinite(ScaleValue.X())) { ScaleValue.X() = 1.0; }
130+
if (!cmnTypeTraits<double>::IsFinite(ScaleValue.Y())) { ScaleValue.Y() = 1.0; }
131+
125132
vctDouble2 pad(padding);
126133
pad.Add(1.0);
127134
this->ScaleValue.ElementwiseDivide(pad);

0 commit comments

Comments
 (0)