new plotter

This commit is contained in:
Sergey Solovyev 2013-01-19 00:33:28 +04:00
parent bbdec030fe
commit ccfe8f752b
3 changed files with 34 additions and 21 deletions

View File

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

View File

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

View File

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