new plotter
This commit is contained in:
@@ -160,6 +160,8 @@ public enum CalculatorEventType {
|
||||
show_create_function_dialog,
|
||||
|
||||
plot_graph,
|
||||
|
||||
/** {@link org.solovyev.android.calculator.plot.PlotData} */
|
||||
plot_data_changed,
|
||||
|
||||
//String
|
||||
|
@@ -62,4 +62,6 @@ public interface CalculatorPlotter {
|
||||
void removeAllUnpinned();
|
||||
|
||||
void setPlotImag(boolean plotImag);
|
||||
|
||||
void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries);
|
||||
}
|
||||
|
@@ -35,6 +35,9 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
|
||||
private int arity = 0;
|
||||
|
||||
@NotNull
|
||||
private PlotBoundaries plotBoundaries = PlotBoundaries.newDefaultInstance();
|
||||
|
||||
public CalculatorPlotterImpl(@NotNull Calculator calculator) {
|
||||
this.calculator = calculator;
|
||||
}
|
||||
@@ -42,7 +45,7 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
@NotNull
|
||||
@Override
|
||||
public PlotData getPlotData() {
|
||||
return new PlotData(getVisibleFunctions(), plot3d);
|
||||
return new PlotData(getVisibleFunctions(), plot3d, plotBoundaries);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -298,6 +301,11 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
plot3d = false;
|
||||
}
|
||||
|
||||
if ( functions.isEmpty() ) {
|
||||
// no functions => new plot => default boundaries
|
||||
this.plotBoundaries = PlotBoundaries.newDefaultInstance();
|
||||
}
|
||||
|
||||
arity = maxArity;
|
||||
|
||||
firePlotDataChangedEvent();
|
||||
@@ -374,6 +382,14 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlotBoundaries(@NotNull PlotBoundaries plotBoundaries) {
|
||||
if ( !this.plotBoundaries.equals(plotBoundaries) ) {
|
||||
this.plotBoundaries = plotBoundaries;
|
||||
firePlotDataChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean toggleImagFunctions(boolean show) {
|
||||
boolean changed = false;
|
||||
|
||||
|
@@ -0,0 +1,103 @@
|
||||
package org.solovyev.android.calculator.plot;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/19/13
|
||||
* Time: 4:51 PM
|
||||
*/
|
||||
public final class PlotBoundaries implements Serializable {
|
||||
|
||||
private static final float DEFAULT_MIN_NUMBER = -10f;
|
||||
|
||||
private static final float DEFAULT_MAX_NUMBER = 10f;
|
||||
|
||||
|
||||
private float xMin;
|
||||
private float xMax;
|
||||
private float yMin;
|
||||
private float yMax;
|
||||
|
||||
public PlotBoundaries() {
|
||||
}
|
||||
|
||||
PlotBoundaries(float xMin, float xMax, float yMin, float yMax) {
|
||||
this.xMin = xMin;
|
||||
this.xMax = xMax;
|
||||
this.yMin = yMin;
|
||||
this.yMax = yMax;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotBoundaries newInstance(float xMin, float xMax, float yMin, float yMax) {
|
||||
return new PlotBoundaries(xMin, xMax, yMin, yMax);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotBoundaries newInstance(float xMin, float xMax) {
|
||||
return newInstance(xMin, xMax, DEFAULT_MIN_NUMBER, DEFAULT_MAX_NUMBER);
|
||||
}
|
||||
|
||||
public float getXMin() {
|
||||
return xMin;
|
||||
}
|
||||
|
||||
public float getXMax() {
|
||||
return xMax;
|
||||
}
|
||||
|
||||
public float getYMin() {
|
||||
return yMin;
|
||||
}
|
||||
|
||||
public float getYMax() {
|
||||
return yMax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PlotBoundaries{" +
|
||||
"yMax=" + yMax +
|
||||
", yMin=" + yMin +
|
||||
", xMax=" + xMax +
|
||||
", xMin=" + xMin +
|
||||
'}';
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PlotBoundaries newDefaultInstance() {
|
||||
PlotBoundaries plotBoundaries = new PlotBoundaries();
|
||||
plotBoundaries.xMin = DEFAULT_MIN_NUMBER;
|
||||
plotBoundaries.yMin = DEFAULT_MIN_NUMBER;
|
||||
plotBoundaries.xMax = DEFAULT_MAX_NUMBER;
|
||||
plotBoundaries.yMax = DEFAULT_MAX_NUMBER;
|
||||
return plotBoundaries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof PlotBoundaries)) return false;
|
||||
|
||||
PlotBoundaries that = (PlotBoundaries) o;
|
||||
|
||||
if (Float.compare(that.xMax, xMax) != 0) return false;
|
||||
if (Float.compare(that.xMin, xMin) != 0) return false;
|
||||
if (Float.compare(that.yMax, yMax) != 0) return false;
|
||||
if (Float.compare(that.yMin, yMin) != 0) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (xMin != +0.0f ? Float.floatToIntBits(xMin) : 0);
|
||||
result = 31 * result + (xMax != +0.0f ? Float.floatToIntBits(xMax) : 0);
|
||||
result = 31 * result + (yMin != +0.0f ? Float.floatToIntBits(yMin) : 0);
|
||||
result = 31 * result + (yMax != +0.0f ? Float.floatToIntBits(yMax) : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -16,9 +16,15 @@ public class PlotData {
|
||||
|
||||
private boolean plot3d;
|
||||
|
||||
public PlotData(@NotNull List<PlotFunction> functions, boolean plot3d) {
|
||||
@NotNull
|
||||
private PlotBoundaries boundaries;
|
||||
|
||||
public PlotData(@NotNull List<PlotFunction> functions,
|
||||
boolean plot3d,
|
||||
@NotNull PlotBoundaries boundaries) {
|
||||
this.functions = functions;
|
||||
this.plot3d = plot3d;
|
||||
this.boundaries = boundaries;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -29,4 +35,9 @@ public class PlotData {
|
||||
public boolean isPlot3d() {
|
||||
return plot3d;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PlotBoundaries getBoundaries() {
|
||||
return boundaries;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user