Skip to content

Commit

Permalink
Fix #260 - UI is crashed for 'sqrt(x)' graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed May 6, 2020
1 parent 16d0867 commit 70318aa
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions xFunc/Views/PlottingGraph.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private void this_MouseMove(object o, MouseEventArgs args)

private void this_MouseWheel(object o, MouseWheelEventArgs args)
{
if (slider.Value != slider.Maximum)
slider.Value -= (slider.Value > 1 ? 0.5 : 0.1) * Math.Sign(args.Delta);
slider.Value -= (slider.Value > 1 ? 0.5 : 0.1) * Math.Sign(args.Delta);
}

private void slider_ValueChanged(object o, RoutedPropertyChangedEventArgs<double> args)
Expand Down Expand Up @@ -320,27 +319,27 @@ private void DrawFunc(GraphItemViewModel graph)
using (var context = geometry.Open())
{
bool startFlag = true;
double y;
double tempY;
for (double x = -centerX / cm; x <= (currentWidth - centerX) / cm; x += 0.03 * slider.Value)
{
parameters.Variables["x"] = x;
y = (double)exp.Execute(parameters);

tempY = centerY - (y * cm);
if (double.IsNaN(y) || tempY < 0 || tempY > currentHeight)
{
startFlag = true;
}
else
if (exp.Execute(parameters) is double y)
{
if (startFlag)
tempY = centerY - (y * cm);
if (double.IsNaN(y) || tempY < 0 || tempY > currentHeight)
{
context.BeginFigure(new Point(centerX + (x * cm), tempY), false, false);
startFlag = false;
startFlag = true;
}
else
{
if (startFlag)
{
context.BeginFigure(new Point(centerX + (x * cm), tempY), false, false);
startFlag = false;
}

context.LineTo(new Point(centerX + (x * cm), tempY), true, false);
context.LineTo(new Point(centerX + (x * cm), tempY), true, false);
}
}
}
}
Expand Down

0 comments on commit 70318aa

Please sign in to comment.