Plotter
This commit is contained in:
parent
a81ce84aff
commit
76db43efdd
@ -186,7 +186,7 @@ public final class ActivityLauncher {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final CustomFunction f = new CustomFunction.Builder().setName("").setParameterNames(parameters).setContent(content).create();
|
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);
|
plotter.get().add(ef);
|
||||||
showPlotter();
|
showPlotter();
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.solovyev.android.calculator.plot;
|
package org.solovyev.android.calculator.plot;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import jscl.math.Expression;
|
||||||
import jscl.math.Generic;
|
import jscl.math.Generic;
|
||||||
import jscl.math.JsclInteger;
|
import jscl.math.JsclInteger;
|
||||||
import jscl.math.NumericWrapper;
|
import jscl.math.NumericWrapper;
|
||||||
@ -15,21 +16,18 @@ import javax.annotation.Nonnull;
|
|||||||
public class ExpressionFunction extends Function {
|
public class ExpressionFunction extends Function {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public final jscl.math.function.Function function;
|
public final jscl.math.function.Function function;
|
||||||
public final boolean imaginary;
|
|
||||||
public final int arity;
|
public final int arity;
|
||||||
private final Generic[] parameters;
|
private final Generic[] parameters;
|
||||||
|
|
||||||
public ExpressionFunction(@Nonnull jscl.math.function.Function function,
|
public ExpressionFunction(@Nonnull jscl.math.function.Function function) {
|
||||||
boolean imaginary) {
|
super(makeFunctionName(function));
|
||||||
super(makeFunctionName(function, imaginary));
|
|
||||||
this.function = function;
|
this.function = function;
|
||||||
this.imaginary = imaginary;
|
|
||||||
this.arity = function.getMaxParameters();
|
this.arity = function.getMaxParameters();
|
||||||
this.parameters = new Generic[this.arity];
|
this.parameters = new Generic[this.arity];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@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();
|
String name = function.getName();
|
||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name)) {
|
||||||
if (function instanceof CustomFunction) {
|
if (function instanceof CustomFunction) {
|
||||||
@ -41,7 +39,7 @@ public class ExpressionFunction extends Function {
|
|||||||
name = name.substring(0, 10) + "…";
|
name = name.substring(0, 10) + "…";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return imaginary ? "Im(" + name + ")" : name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,7 +59,7 @@ public class ExpressionFunction extends Function {
|
|||||||
@Override
|
@Override
|
||||||
public float evaluate(float x) {
|
public float evaluate(float x) {
|
||||||
try {
|
try {
|
||||||
parameters[0] = new NumericWrapper(Real.valueOf(x));
|
parameters[0] = Expression.valueOf((double) x);
|
||||||
function.setParameters(parameters);
|
function.setParameters(parameters);
|
||||||
return unwrap(function.numeric());
|
return unwrap(function.numeric());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
@ -72,8 +70,8 @@ public class ExpressionFunction extends Function {
|
|||||||
@Override
|
@Override
|
||||||
public float evaluate(float x, float y) {
|
public float evaluate(float x, float y) {
|
||||||
try {
|
try {
|
||||||
parameters[0] = new NumericWrapper(Real.valueOf(x));
|
parameters[0] = Expression.valueOf((double) x);
|
||||||
parameters[1] = new NumericWrapper(Real.valueOf(y));
|
parameters[1] = Expression.valueOf((double) y);
|
||||||
function.setParameters(parameters);
|
function.setParameters(parameters);
|
||||||
return unwrap(function.numeric());
|
return unwrap(function.numeric());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
@ -96,7 +94,13 @@ public class ExpressionFunction extends Function {
|
|||||||
return (float) content.doubleValue();
|
return (float) content.doubleValue();
|
||||||
}
|
}
|
||||||
if (content instanceof Complex) {
|
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;
|
return Float.NaN;
|
||||||
}
|
}
|
||||||
|
@ -150,13 +150,15 @@ public class PlotEditFunctionFragment extends BaseFunctionFragment
|
|||||||
protected MeshSpec applyMeshSpec() {
|
protected MeshSpec applyMeshSpec() {
|
||||||
final Color color = Color.create(colorPicker.getColor());
|
final Color color = Color.create(colorPicker.getColor());
|
||||||
final int width = MeshSpec.MIN_WIDTH + lineWidthSeekBar.getProgress();
|
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) {
|
protected boolean applyData(@Nonnull CppFunction function) {
|
||||||
try {
|
try {
|
||||||
final ExpressionFunction expressionFunction =
|
final ExpressionFunction expressionFunction =
|
||||||
new ExpressionFunction(function.toJsclBuilder().create(), false);
|
new ExpressionFunction(function.toJsclBuilder().create());
|
||||||
final PlotFunction plotFunction = PlotFunction.create(expressionFunction,
|
final PlotFunction plotFunction = PlotFunction.create(expressionFunction,
|
||||||
applyMeshSpec());
|
applyMeshSpec());
|
||||||
final int id = function.getId();
|
final int id = function.getId();
|
||||||
|
@ -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, 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_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_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_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_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));
|
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;
|
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
|
@Nonnull
|
||||||
public static Intent makeIntent(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
|
public static Intent makeIntent(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
|
||||||
final Intent intent = new Intent(context, getClass(context));
|
final Intent intent = new Intent(context, getClass(context));
|
||||||
|
@ -41,9 +41,6 @@
|
|||||||
<Preference
|
<Preference
|
||||||
a:key="screen-appearance"
|
a:key="screen-appearance"
|
||||||
a:title="@string/c_prefs_appearance_category" />
|
a:title="@string/c_prefs_appearance_category" />
|
||||||
<Preference
|
|
||||||
a:key="screen-plot"
|
|
||||||
a:title="@string/prefs_graph_screen_title" />
|
|
||||||
<Preference
|
<Preference
|
||||||
a:key="screen-other"
|
a:key="screen-other"
|
||||||
a:title="@string/c_prefs_other_category" />
|
a:title="@string/c_prefs_other_category" />
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ Copyright 2013 serso aka se.solovyev
|
|
||||||
~
|
|
||||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
~ you may not use this file except in compliance with the License.
|
|
||||||
~ You may obtain a copy of the License at
|
|
||||||
~
|
|
||||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
~
|
|
||||||
~ Unless required by applicable law or agreed to in writing, software
|
|
||||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
~ See the License for the specific language governing permissions and
|
|
||||||
~ limitations under the License.
|
|
||||||
~
|
|
||||||
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
~ Contact details
|
|
||||||
~
|
|
||||||
~ Email: se.solovyev@gmail.com
|
|
||||||
~ Site: http://se.solovyev.org
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
|
||||||
a:key="graph_plot_imag"
|
|
||||||
a:summary="@string/cpp_prefs_graph_plot_imag_summary"
|
|
||||||
a:title="@string/cpp_prefs_graph_plot_imag_title" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
Loading…
Reference in New Issue
Block a user