From 7c546a0ea932d9ce1cc8f462420b0f6b879d885b Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Mon, 19 Nov 2012 22:41:40 +0400 Subject: [PATCH] Fix for plotting --- calculatorpp/AndroidManifest.xml | 2 +- .../android/calculator/plot/PlotUtils.java | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/calculatorpp/AndroidManifest.xml b/calculatorpp/AndroidManifest.xml index 63381725..3b4ac322 100644 --- a/calculatorpp/AndroidManifest.xml +++ b/calculatorpp/AndroidManifest.xml @@ -1,5 +1,5 @@ - + diff --git a/calculatorpp/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java b/calculatorpp/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java index d009a738..e719d343 100644 --- a/calculatorpp/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java +++ b/calculatorpp/src/main/java/org/solovyev/android/calculator/plot/PlotUtils.java @@ -39,7 +39,7 @@ import java.util.Arrays; */ public final class PlotUtils { - private static final double MAX_Y_DIFF = 1; + private static final double MAX_Y_DIFF = 1; private static final double MAX_X_DIFF = 1; static final int DEFAULT_NUMBER_OF_STEPS = 100; @@ -55,7 +55,7 @@ public final class PlotUtils { @NotNull MyXYSeries realSeries, @Nullable MyXYSeries imagSeries, boolean addExtra, - int numberOfSteps) throws ArithmeticException { + int numberOfSteps) { boolean imagExists = false; @@ -145,7 +145,7 @@ public final class PlotUtils { int bgColor, boolean interpolate, int realLineColor, - int imagLineColor) throws ArithmeticException{ + int imagLineColor) { final MyXYSeries realSeries = new MyXYSeries(getRealFunctionName(expression, variable), DEFAULT_NUMBER_OF_STEPS * 2); final MyXYSeries imagSeries = new MyXYSeries(getImagFunctionName(variable), DEFAULT_NUMBER_OF_STEPS * 2); @@ -372,8 +372,12 @@ public final class PlotUtils { @NotNull public static Complex calculatorExpression(@NotNull Generic expression, @NotNull Constant variable, double x) { - return unwrap(expression.substitute(variable, Expression.valueOf(x)).numeric()); - } + try { + return unwrap(expression.substitute(variable, Expression.valueOf(x)).numeric()); + } catch (RuntimeException e) { + return NaN; + } + } public static void addSingularityPoint(@NotNull MyXYSeries series, @NotNull Point point) { @@ -410,14 +414,16 @@ public final class PlotUtils { } } - @NotNull + private static final Complex NaN = Complex.valueOf(Double.NaN, 0d); + + @NotNull public static Complex unwrap(@Nullable Generic numeric) { if (numeric instanceof JsclInteger) { return Complex.valueOf(((JsclInteger) numeric).intValue(), 0d); } else if (numeric instanceof NumericWrapper) { return unwrap(((NumericWrapper) numeric).content()); } else { - throw new ArithmeticException(); + return NaN; } }