From 76db43efdd238e25bdaf6ff3894b391ca7b45c83 Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 5 Mar 2016 13:07:38 +0100 Subject: [PATCH] Plotter --- .../android/calculator/ActivityLauncher.java | 2 +- .../calculator/plot/ExpressionFunction.java | 26 ++++++++------- .../plot/PlotEditFunctionFragment.java | 6 ++-- .../preferences/PreferencesActivity.java | 10 ------ app/src/main/res/xml/preferences.xml | 3 -- app/src/main/res/xml/preferences_plot.xml | 32 ------------------- 6 files changed, 20 insertions(+), 59 deletions(-) delete mode 100644 app/src/main/res/xml/preferences_plot.xml diff --git a/app/src/main/java/org/solovyev/android/calculator/ActivityLauncher.java b/app/src/main/java/org/solovyev/android/calculator/ActivityLauncher.java index e66864be..1ac41f5f 100644 --- a/app/src/main/java/org/solovyev/android/calculator/ActivityLauncher.java +++ b/app/src/main/java/org/solovyev/android/calculator/ActivityLauncher.java @@ -186,7 +186,7 @@ public final class ActivityLauncher { try { final CustomFunction f = new CustomFunction.Builder().setName("").setParameterNames(parameters).setContent(content).create(); - final ExpressionFunction ef = new ExpressionFunction(f, false); + final ExpressionFunction ef = new ExpressionFunction(f); plotter.get().add(ef); showPlotter(); } catch (RuntimeException e) { diff --git a/app/src/main/java/org/solovyev/android/calculator/plot/ExpressionFunction.java b/app/src/main/java/org/solovyev/android/calculator/plot/ExpressionFunction.java index 15b693e7..50cf585c 100644 --- a/app/src/main/java/org/solovyev/android/calculator/plot/ExpressionFunction.java +++ b/app/src/main/java/org/solovyev/android/calculator/plot/ExpressionFunction.java @@ -1,6 +1,7 @@ package org.solovyev.android.calculator.plot; import android.text.TextUtils; +import jscl.math.Expression; import jscl.math.Generic; import jscl.math.JsclInteger; import jscl.math.NumericWrapper; @@ -15,21 +16,18 @@ import javax.annotation.Nonnull; public class ExpressionFunction extends Function { @Nonnull public final jscl.math.function.Function function; - public final boolean imaginary; public final int arity; private final Generic[] parameters; - public ExpressionFunction(@Nonnull jscl.math.function.Function function, - boolean imaginary) { - super(makeFunctionName(function, imaginary)); + public ExpressionFunction(@Nonnull jscl.math.function.Function function) { + super(makeFunctionName(function)); this.function = function; - this.imaginary = imaginary; this.arity = function.getMaxParameters(); this.parameters = new Generic[this.arity]; } @Nonnull - private static String makeFunctionName(@Nonnull jscl.math.function.Function function, boolean imaginary) { + private static String makeFunctionName(@Nonnull jscl.math.function.Function function) { String name = function.getName(); if (TextUtils.isEmpty(name)) { if (function instanceof CustomFunction) { @@ -41,7 +39,7 @@ public class ExpressionFunction extends Function { name = name.substring(0, 10) + "…"; } } - return imaginary ? "Im(" + name + ")" : name; + return name; } @Override @@ -61,7 +59,7 @@ public class ExpressionFunction extends Function { @Override public float evaluate(float x) { try { - parameters[0] = new NumericWrapper(Real.valueOf(x)); + parameters[0] = Expression.valueOf((double) x); function.setParameters(parameters); return unwrap(function.numeric()); } catch (RuntimeException e) { @@ -72,8 +70,8 @@ public class ExpressionFunction extends Function { @Override public float evaluate(float x, float y) { try { - parameters[0] = new NumericWrapper(Real.valueOf(x)); - parameters[1] = new NumericWrapper(Real.valueOf(y)); + parameters[0] = Expression.valueOf((double) x); + parameters[1] = Expression.valueOf((double) y); function.setParameters(parameters); return unwrap(function.numeric()); } catch (RuntimeException e) { @@ -96,7 +94,13 @@ public class ExpressionFunction extends Function { return (float) content.doubleValue(); } if (content instanceof Complex) { - return (float) (imaginary ? ((Complex) content).imaginaryPart() : ((Complex) content).realPart()); + final Complex complex = (Complex) content; + final double imag = complex.imaginaryPart(); + final double real = complex.realPart(); + if (real == 0f && imag != 0f) { + return Float.NaN; + } + return (float) real; } return Float.NaN; } diff --git a/app/src/main/java/org/solovyev/android/calculator/plot/PlotEditFunctionFragment.java b/app/src/main/java/org/solovyev/android/calculator/plot/PlotEditFunctionFragment.java index c1b522cd..0a12357e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/plot/PlotEditFunctionFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/plot/PlotEditFunctionFragment.java @@ -150,13 +150,15 @@ public class PlotEditFunctionFragment extends BaseFunctionFragment protected MeshSpec applyMeshSpec() { final Color color = Color.create(colorPicker.getColor()); final int width = MeshSpec.MIN_WIDTH + lineWidthSeekBar.getProgress(); - return MeshSpec.create(color, width); + final MeshSpec meshSpec = MeshSpec.create(color, width); + meshSpec.pointsCount = 100; + return meshSpec; } protected boolean applyData(@Nonnull CppFunction function) { try { final ExpressionFunction expressionFunction = - new ExpressionFunction(function.toJsclBuilder().create(), false); + new ExpressionFunction(function.toJsclBuilder().create()); final PlotFunction plotFunction = PlotFunction.create(expressionFunction, applyMeshSpec()); final int id = function.getId(); diff --git a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java index 78f85c4b..aaff957b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/preferences/PreferencesActivity.java @@ -39,7 +39,6 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc preferenceDefs.append(R.xml.preferences, new PrefDef("screen-main", R.string.cpp_settings)); preferenceDefs.append(R.xml.preferences_calculations, new PrefDef("screen-calculations", R.string.c_prefs_calculations_category)); preferenceDefs.append(R.xml.preferences_appearance, new PrefDef("screen-appearance", R.string.c_prefs_appearance_category)); - preferenceDefs.append(R.xml.preferences_plot, new PrefDef("screen-plot", R.string.prefs_graph_screen_title)); preferenceDefs.append(R.xml.preferences_other, new PrefDef("screen-other", R.string.c_prefs_other_category)); preferenceDefs.append(R.xml.preferences_onscreen, new PrefDef("screen-onscreen", R.string.prefs_onscreen_title)); preferenceDefs.append(R.xml.preferences_widget, new PrefDef("screen-widget", R.string.prefs_widget_title)); @@ -66,15 +65,6 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc return preferenceDefs; } - public static void showPlotPreferences(@Nonnull Context context) { - start(context, R.xml.preferences_plot, R.string.prefs_graph_screen_title); - } - - private static void start(@Nonnull Context context, @XmlRes int preference, @StringRes int title) { - final Intent intent = makeIntent(context, preference, title); - context.startActivity(intent); - } - @Nonnull public static Intent makeIntent(@Nonnull Context context, @XmlRes int preference, @StringRes int title) { final Intent intent = new Intent(context, getClass(context)); diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 1a0365e3..0ffdadcc 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -41,9 +41,6 @@ - diff --git a/app/src/main/res/xml/preferences_plot.xml b/app/src/main/res/xml/preferences_plot.xml deleted file mode 100644 index 1509387e..00000000 --- a/app/src/main/res/xml/preferences_plot.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - \ No newline at end of file