From ccfe8f752b936d0bb423aca49bc2c298da686eab Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sat, 19 Jan 2013 00:33:28 +0400 Subject: [PATCH] new plotter --- .../plot/AbstractGraphCalculator.java | 7 ++- .../plot/CalculatorGraph2dView.java | 3 ++ .../android/calculator/plot/GraphData.java | 45 ++++++++++--------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractGraphCalculator.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractGraphCalculator.java index 3f4b7893..e6eada46 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractGraphCalculator.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/AbstractGraphCalculator.java @@ -19,7 +19,12 @@ public abstract class AbstractGraphCalculator implements GraphCalculator { private final GraphData startGraph = GraphData.newEmptyInstance(); @Override - public final void computeGraph(@NotNull XyFunction f, float xMin, float xMax, @NotNull GraphData graph, @NotNull GraphsData graphsData, @NotNull Graph2dDimensions dimensions) { + public final void computeGraph(@NotNull XyFunction f, + float xMin, + float xMax, + @NotNull GraphData graph, + @NotNull GraphsData graphsData, + @NotNull Graph2dDimensions dimensions) { if (f.getArity() == 0) { final float v = (float) f.eval(); graph.clear(); diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph2dView.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph2dView.java index a7bf5bbf..6c707cd4 100644 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph2dView.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/CalculatorGraph2dView.java @@ -14,6 +14,8 @@ import org.solovyev.common.math.Point2d; import java.text.DecimalFormat; import java.util.Collections; import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; public class CalculatorGraph2dView extends View implements GraphView { @@ -82,6 +84,7 @@ public class CalculatorGraph2dView extends View implements GraphView { @NotNull private final Graph2dDimensions dimensions = new Graph2dDimensions(this); + @NotNull private final GraphCalculator graphCalculator = new GraphCalculatorImpl(); private boolean mDrawn = false; diff --git a/android-app/src/main/java/org/solovyev/android/calculator/plot/GraphData.java b/android-app/src/main/java/org/solovyev/android/calculator/plot/GraphData.java index cbbb6018..e7787caa 100755 --- a/android-app/src/main/java/org/solovyev/android/calculator/plot/GraphData.java +++ b/android-app/src/main/java/org/solovyev/android/calculator/plot/GraphData.java @@ -91,42 +91,47 @@ class GraphData { } void eraseBefore(float x) { - int pos = 0; - while (pos < size && xs[pos] < x) { - ++pos; + int i = 0; + while (i < size && xs[i] < x) { + ++i; } - --pos; - if (pos > 0) { - size -= pos; - System.arraycopy(xs, pos, xs, 0, size); - System.arraycopy(ys, pos, ys, 0, size); + // step back as xs[i] >= x and xs[i-1] < x + --i; + + if (i > 0) { + size -= i; + System.arraycopy(xs, i, xs, 0, size); + System.arraycopy(ys, i, ys, 0, size); } } void eraseAfter(float x) { - int pos = size - 1; - while (pos >= 0 && x < xs[pos]) { - --pos; + int i = size - 1; + while (i >= 0 && x < xs[i]) { + --i; } - ++pos; - if (pos < size - 1) { - size = pos + 1; + + // step next as xs[i] > x and xs[i+1] <= x + ++i; + + if (i < size - 1) { + size = i + 1; } } int findPositionAfter(float x, float y) { - int position = 0; - while (position < size && xs[position] <= x) { - ++position; + int i = 0; + while (i < size && xs[i] <= x) { + ++i; } if (Float.isNaN(y)) { - while (position < size && Float.isNaN(ys[position])) { - ++position; + while (i < size && Float.isNaN(ys[i])) { + ++i; } } - return position; + return i; } void append(GraphData that) {