Fix for plotting

This commit is contained in:
Sergey Solovyev 2012-11-19 22:41:40 +04:00
parent 3467ba828f
commit 7c546a0ea9
2 changed files with 14 additions and 8 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="108" android:versionName="1.5.1-b2" package="org.solovyev.android.calculator"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="109" android:versionName="1.5.1-b3-SNAPSHOT" package="org.solovyev.android.calculator">
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>

View File

@ -39,7 +39,7 @@ import java.util.Arrays;
*/ */
public final class PlotUtils { 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; private static final double MAX_X_DIFF = 1;
static final int DEFAULT_NUMBER_OF_STEPS = 100; static final int DEFAULT_NUMBER_OF_STEPS = 100;
@ -55,7 +55,7 @@ public final class PlotUtils {
@NotNull MyXYSeries realSeries, @NotNull MyXYSeries realSeries,
@Nullable MyXYSeries imagSeries, @Nullable MyXYSeries imagSeries,
boolean addExtra, boolean addExtra,
int numberOfSteps) throws ArithmeticException { int numberOfSteps) {
boolean imagExists = false; boolean imagExists = false;
@ -145,7 +145,7 @@ public final class PlotUtils {
int bgColor, int bgColor,
boolean interpolate, boolean interpolate,
int realLineColor, int realLineColor,
int imagLineColor) throws ArithmeticException{ int imagLineColor) {
final MyXYSeries realSeries = new MyXYSeries(getRealFunctionName(expression, variable), DEFAULT_NUMBER_OF_STEPS * 2); 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); final MyXYSeries imagSeries = new MyXYSeries(getImagFunctionName(variable), DEFAULT_NUMBER_OF_STEPS * 2);
@ -372,8 +372,12 @@ public final class PlotUtils {
@NotNull @NotNull
public static Complex calculatorExpression(@NotNull Generic expression, @NotNull Constant variable, double x) { 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, public static void addSingularityPoint(@NotNull MyXYSeries series,
@NotNull Point point) { @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) { public static Complex unwrap(@Nullable Generic numeric) {
if (numeric instanceof JsclInteger) { if (numeric instanceof JsclInteger) {
return Complex.valueOf(((JsclInteger) numeric).intValue(), 0d); return Complex.valueOf(((JsclInteger) numeric).intValue(), 0d);
} else if (numeric instanceof NumericWrapper) { } else if (numeric instanceof NumericWrapper) {
return unwrap(((NumericWrapper) numeric).content()); return unwrap(((NumericWrapper) numeric).content());
} else { } else {
throw new ArithmeticException(); return NaN;
} }
} }