Skip to content

Commit

Permalink
Fix infinite loop in LineAnnotation oxyplot#1029
Browse files Browse the repository at this point in the history
  • Loading branch information
objorke committed Jun 18, 2017
1 parent c1a83a8 commit 33b7ab0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -35,6 +35,7 @@ All notable changes to this project will be documented in this file.
- When Color Property of LineSeries is set Markers are not shown (#937)
- Change from linear to logarithmic axis does not work (#1067)
- OxyPalette.Interpolate() throws exception when paletteSize = 1 (#1068)
- Infinite loop in LineAnnotation (#1029)

## [1.0.0] - 2016-09-11
### Added
Expand Down
60 changes: 22 additions & 38 deletions Source/OxyPlot/Annotations/LineAnnotation.cs
Expand Up @@ -92,62 +92,46 @@ protected override IList<ScreenPoint> GetScreenPoints()

if (!isCurvedLine)
{
if (this.ActualMinimumX != this.ActualMaximumX)
// we only need to calculate two points if it is a straight line
if (fx != null)
{
// we only need to calculate two points if it is a straight line
if (fx != null)
{
points.Add(new DataPoint(this.ActualMinimumX, fx(this.ActualMinimumX)));
points.Add(new DataPoint(this.ActualMaximumX, fx(this.ActualMaximumX)));
}
else
{
points.Add(new DataPoint(fy(this.ActualMinimumY), this.ActualMinimumY));
points.Add(new DataPoint(fy(this.ActualMaximumY), this.ActualMaximumY));
}
points.Add(new DataPoint(this.ActualMinimumX, fx(this.ActualMinimumX)));
points.Add(new DataPoint(this.ActualMaximumX, fx(this.ActualMaximumX)));
}
else
{
points.Add(new DataPoint(fy(this.ActualMinimumY), this.ActualMinimumY));
points.Add(new DataPoint(fy(this.ActualMaximumY), this.ActualMaximumY));
}

if (this.Type == LineAnnotationType.Horizontal || this.Type == LineAnnotationType.Vertical)
{
// use aliased line drawing for horizontal and vertical lines
this.Aliased = true;
}
if (this.Type == LineAnnotationType.Horizontal || this.Type == LineAnnotationType.Vertical)
{
// use aliased line drawing for horizontal and vertical lines
this.Aliased = true;
}

}
else
{
if (fx != null)
{
double x = this.ActualMinimumX;

// todo: the step size should be adaptive
double dx = (this.ActualMaximumX - this.ActualMinimumX) / 100;
while (true)
var n = 100;
var dx = (this.ActualMaximumX - this.ActualMinimumX) / 100;
for (int i = 0; i <= n; i++)
{
var x = this.ActualMinimumX + i * dx;
points.Add(new DataPoint(x, fx(x)));
if (x > this.ActualMaximumX)
{
break;
}

x += dx;
}
}
else
{
double y = this.ActualMinimumY;

// todo: the step size should be adaptive
double dy = (this.ActualMaximumY - this.ActualMinimumY) / 100;
while (true)
var n = 100;
var dy = (this.ActualMaximumY - this.ActualMinimumY) / n;
for (int i = 0; i <= n; i++)
{
var y = this.ActualMinimumY + i * dy;
points.Add(new DataPoint(fy(y), y));
if (y > this.ActualMaximumY)
{
break;
}

y += dy;
}
}
}
Expand Down

0 comments on commit 33b7ab0

Please sign in to comment.