new plotter
This commit is contained in:
parent
bbdec030fe
commit
ccfe8f752b
@ -19,7 +19,12 @@ public abstract class AbstractGraphCalculator implements GraphCalculator {
|
|||||||
private final GraphData startGraph = GraphData.newEmptyInstance();
|
private final GraphData startGraph = GraphData.newEmptyInstance();
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (f.getArity() == 0) {
|
||||||
final float v = (float) f.eval();
|
final float v = (float) f.eval();
|
||||||
graph.clear();
|
graph.clear();
|
||||||
|
@ -14,6 +14,8 @@ import org.solovyev.common.math.Point2d;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class CalculatorGraph2dView extends View implements GraphView {
|
public class CalculatorGraph2dView extends View implements GraphView {
|
||||||
|
|
||||||
@ -82,6 +84,7 @@ public class CalculatorGraph2dView extends View implements GraphView {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final Graph2dDimensions dimensions = new Graph2dDimensions(this);
|
private final Graph2dDimensions dimensions = new Graph2dDimensions(this);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private final GraphCalculator graphCalculator = new GraphCalculatorImpl();
|
private final GraphCalculator graphCalculator = new GraphCalculatorImpl();
|
||||||
|
|
||||||
private boolean mDrawn = false;
|
private boolean mDrawn = false;
|
||||||
|
@ -91,42 +91,47 @@ class GraphData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void eraseBefore(float x) {
|
void eraseBefore(float x) {
|
||||||
int pos = 0;
|
int i = 0;
|
||||||
while (pos < size && xs[pos] < x) {
|
while (i < size && xs[i] < x) {
|
||||||
++pos;
|
++i;
|
||||||
}
|
}
|
||||||
--pos;
|
// step back as xs[i] >= x and xs[i-1] < x
|
||||||
if (pos > 0) {
|
--i;
|
||||||
size -= pos;
|
|
||||||
System.arraycopy(xs, pos, xs, 0, size);
|
if (i > 0) {
|
||||||
System.arraycopy(ys, pos, ys, 0, size);
|
size -= i;
|
||||||
|
System.arraycopy(xs, i, xs, 0, size);
|
||||||
|
System.arraycopy(ys, i, ys, 0, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eraseAfter(float x) {
|
void eraseAfter(float x) {
|
||||||
int pos = size - 1;
|
int i = size - 1;
|
||||||
while (pos >= 0 && x < xs[pos]) {
|
while (i >= 0 && x < xs[i]) {
|
||||||
--pos;
|
--i;
|
||||||
}
|
}
|
||||||
++pos;
|
|
||||||
if (pos < size - 1) {
|
// step next as xs[i] > x and xs[i+1] <= x
|
||||||
size = pos + 1;
|
++i;
|
||||||
|
|
||||||
|
if (i < size - 1) {
|
||||||
|
size = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int findPositionAfter(float x, float y) {
|
int findPositionAfter(float x, float y) {
|
||||||
int position = 0;
|
int i = 0;
|
||||||
while (position < size && xs[position] <= x) {
|
while (i < size && xs[i] <= x) {
|
||||||
++position;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Float.isNaN(y)) {
|
if (Float.isNaN(y)) {
|
||||||
while (position < size && Float.isNaN(ys[position])) {
|
while (i < size && Float.isNaN(ys[i])) {
|
||||||
++position;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return position;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(GraphData that) {
|
void append(GraphData that) {
|
||||||
|
Loading…
Reference in New Issue
Block a user