This commit is contained in:
serso 2016-03-05 13:07:38 +01:00
parent a81ce84aff
commit 76db43efdd
6 changed files with 20 additions and 59 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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();

View File

@ -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));

View File

@ -41,9 +41,6 @@
<Preference
a:key="screen-appearance"
a:title="@string/c_prefs_appearance_category" />
<Preference
a:key="screen-plot"
a:title="@string/prefs_graph_screen_title" />
<Preference
a:key="screen-other"
a:title="@string/c_prefs_other_category" />

View File

@ -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>