plot changes
This commit is contained in:
parent
1a861b6403
commit
62eb80c89d
@ -169,4 +169,9 @@ public class AndroidCalculatorPlotter implements CalculatorPlotter, SharedPrefer
|
|||||||
setPlotImag(CalculatorPreferences.Graph.plotImag.getPreference(preferences));
|
setPlotImag(CalculatorPreferences.Graph.plotImag.getPreference(preferences));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries) {
|
||||||
|
plotter.setPlotData(plot3d, plotBoundaries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,13 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
Locator.getInstance().getPlotter().setPlot3d(true);
|
final PlotBoundaries plotBoundaries = getPlotBoundaries();
|
||||||
|
|
||||||
|
if (plotBoundaries != null) {
|
||||||
|
Locator.getInstance().getPlotter().setPlotData(true, plotBoundaries);
|
||||||
|
} else {
|
||||||
|
Locator.getInstance().getPlotter().setPlot3d(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
menuItems.add(plot3dMenuItem);
|
menuItems.add(plot3dMenuItem);
|
||||||
@ -231,7 +237,13 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
public void onClick(@NotNull MenuItem data, @NotNull Context context) {
|
||||||
Locator.getInstance().getPlotter().setPlot3d(false);
|
final PlotBoundaries plotBoundaries = getPlotBoundaries();
|
||||||
|
|
||||||
|
if (plotBoundaries != null) {
|
||||||
|
Locator.getInstance().getPlotter().setPlotData(false, plotBoundaries);
|
||||||
|
} else {
|
||||||
|
Locator.getInstance().getPlotter().setPlot3d(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
menuItems.add(plot2dMenuItem);
|
menuItems.add(plot2dMenuItem);
|
||||||
|
@ -598,6 +598,8 @@ public class CalculatorGraph2dView extends View implements GraphView {
|
|||||||
|
|
||||||
public void onTouchZoomDown(float x1, float y1, float x2, float y2) {
|
public void onTouchZoomDown(float x1, float y1, float x2, float y2) {
|
||||||
zoomTracker.start(dimensions.getGWidth(), dimensions.getGHeight(), x1, y1, x2, y2);
|
zoomTracker.start(dimensions.getGWidth(), dimensions.getGHeight(), x1, y1, x2, y2);
|
||||||
|
lastTouchXPxs = NO_TOUCH;
|
||||||
|
lastTouchYPxs = NO_TOUCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTouchZoomMove(float x1, float y1, float x2, float y2) {
|
public void onTouchZoomMove(float x1, float y1, float x2, float y2) {
|
||||||
@ -612,16 +614,11 @@ public class CalculatorGraph2dView extends View implements GraphView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void scroll(float deltaX, float deltaY) {
|
private void scroll(float deltaX, float deltaY) {
|
||||||
final float scale = dimensions.getGWidth() / dimensions.getVWidthPxs();
|
final float xScale = dimensions.getXGraphToViewScale();
|
||||||
float dx = deltaX * scale;
|
final float yScale = dimensions.getYGraphToViewScale();
|
||||||
float dy = deltaY * scale;
|
|
||||||
final float adx = Math.abs(dx);
|
float dx = deltaX * xScale;
|
||||||
final float ady = Math.abs(dy);
|
float dy = deltaY * yScale;
|
||||||
if (adx < ady / 3) {
|
|
||||||
dx = 0;
|
|
||||||
} else if (ady < adx / 3) {
|
|
||||||
dy = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
dimensions.increaseXY(dx, dy);
|
dimensions.increaseXY(dx, dy);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public class CalculatorGraph3dView extends GLView implements GraphView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setXRange(float xMin, float xMax) {
|
public void setXRange(float xMin, float xMax) {
|
||||||
dimensions.setXRange(PlotBoundaries.DEFAULT_MIN_NUMBER, PlotBoundaries.DEFAULT_MAX_NUMBER);
|
dimensions.setRanges(1, 1, 1, 1);
|
||||||
|
|
||||||
zoomLevel = 1;
|
zoomLevel = 1;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -165,15 +165,30 @@ public class Graph2dDimensions {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public void setXRange(float xMin, float xMax) {
|
public void setXRange(float xMin, float xMax) {
|
||||||
this.gWidth = xMax - xMin;
|
setXRange0(xMin, xMax);
|
||||||
this.x0 = xMin + gWidth / 2;
|
|
||||||
|
|
||||||
this.graphView.invalidateGraphs();
|
this.graphView.invalidateGraphs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setXRange0(float xMin, float xMax) {
|
||||||
|
this.gWidth = xMax - xMin;
|
||||||
|
this.x0 = xMin + gWidth / 2;
|
||||||
|
}
|
||||||
|
|
||||||
public void setYRange(float yMin, float yMax) {
|
public void setYRange(float yMin, float yMax) {
|
||||||
|
setYRange0(yMin, yMax);
|
||||||
|
|
||||||
|
this.graphView.invalidateGraphs();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setYRange0(float yMin, float yMax) {
|
||||||
this.gHeight = yMax - yMin;
|
this.gHeight = yMax - yMin;
|
||||||
this.y0 = yMin + gHeight / 2;
|
this.y0 = yMin + gHeight / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRanges(float xMin, float xMax, float yMin, float yMax) {
|
||||||
|
setXRange0(xMin, xMax);
|
||||||
|
setYRange0(yMin, yMax);
|
||||||
|
|
||||||
this.graphView.invalidateGraphs();
|
this.graphView.invalidateGraphs();
|
||||||
}
|
}
|
||||||
|
@ -1,56 +1,58 @@
|
|||||||
package org.solovyev.android.calculator.plot;
|
package org.solovyev.android.calculator.plot;
|
||||||
|
|
||||||
class ZoomTracker {
|
class ZoomTracker {
|
||||||
private float sx1, sy1, sx2, sy2;
|
|
||||||
private float initialDist;
|
private static final float EPS = 1.5f;
|
||||||
|
private static final float MIN_DISTANCE = distance(0f, 50f);
|
||||||
|
public static final String TAG = "ZoomTracker";
|
||||||
|
|
||||||
|
private float initialXDistance;
|
||||||
|
private float initialYDistance;
|
||||||
|
|
||||||
private float initialXValue;
|
private float initialXValue;
|
||||||
private float initialYValue;
|
private float initialYValue;
|
||||||
|
|
||||||
float xValue;
|
float xValue;
|
||||||
float yValue;
|
float yValue;
|
||||||
float moveX, moveY;
|
|
||||||
|
|
||||||
void start(float xValue, float yValue, float x1, float y1, float x2, float y2) {
|
void start(float xValue, float yValue,
|
||||||
sx1 = x1;
|
float x1, float y1,
|
||||||
sy1 = y1;
|
float x2, float y2) {
|
||||||
sx2 = x2;
|
|
||||||
sy2 = y2;
|
initialXDistance = distance(x1, x2);
|
||||||
initialDist = distance(x1, y1, x2, y2);
|
initialYDistance = distance(y1, y2);
|
||||||
|
|
||||||
initialXValue = xValue;
|
initialXValue = xValue;
|
||||||
initialYValue = yValue;
|
initialYValue = yValue;
|
||||||
|
|
||||||
|
this.xValue = xValue;
|
||||||
|
this.yValue = yValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean update(float x1, float y1, float x2, float y2) {
|
boolean update(float x1, float y1, float x2, float y2) {
|
||||||
final float LIMIT = 1.5f;
|
boolean result = false;
|
||||||
if (Math.abs(x1 - sx1) < LIMIT && Math.abs(y1 - sy1) < LIMIT &&
|
|
||||||
Math.abs(x2 - sx2) < LIMIT && Math.abs(y2 - sy2) < LIMIT) {
|
if (initialXDistance > MIN_DISTANCE) {
|
||||||
return false;
|
final float xDistance = distance(x1, x2);
|
||||||
|
if (xDistance > EPS) {
|
||||||
|
xValue = initialXDistance / xDistance * initialXValue;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
moveX = common(x1, sx1, x2, sx2);
|
|
||||||
moveY = common(y1, sy1, y2, sy2);
|
if (initialYDistance > MIN_DISTANCE) {
|
||||||
float dist = distance(x1, y1, x2, y2);
|
final float yDistance = distance(y1, y2);
|
||||||
xValue = initialDist / dist * initialXValue;
|
if (yDistance > EPS) {
|
||||||
yValue = initialDist / dist * initialYValue;
|
yValue = initialYDistance / yDistance * initialYValue;
|
||||||
sx1 = x1;
|
result = true;
|
||||||
sx2 = x2;
|
}
|
||||||
sy1 = y1;
|
}
|
||||||
sy2 = y2;
|
|
||||||
return true;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float distance(float x1, float y1, float x2, float y2) {
|
private static float distance(float x1, float x2) {
|
||||||
final float dx = x1-x2;
|
final float dx = x1 - x2;
|
||||||
final float dy = y1-y2;
|
return dx * dx;
|
||||||
// return (float) Math.sqrt(dx*dx+dy*dy);
|
|
||||||
return Math.max(dx*dx, dy*dy);
|
|
||||||
}
|
|
||||||
|
|
||||||
private float common(float x1, float sx1, float x2, float sx2) {
|
|
||||||
float dx1 = x1 - sx1;
|
|
||||||
float dx2 = x2 - sx2;
|
|
||||||
return (dx1 < 0 && dx2 < 0) ? Math.max(dx1, dx2) :
|
|
||||||
(dx1 > 0 && dx2 > 0) ? Math.min(dx1, dx2):
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ public interface CalculatorPlotter {
|
|||||||
boolean isPlotPossibleFor(@NotNull Generic expression);
|
boolean isPlotPossibleFor(@NotNull Generic expression);
|
||||||
|
|
||||||
void setPlot3d(boolean plot3d);
|
void setPlot3d(boolean plot3d);
|
||||||
|
void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries);
|
||||||
|
|
||||||
void removeAllUnpinned();
|
void removeAllUnpinned();
|
||||||
|
|
||||||
|
@ -372,6 +372,15 @@ public class CalculatorPlotterImpl implements CalculatorPlotter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlotData(boolean plot3d, @NotNull PlotBoundaries plotBoundaries) {
|
||||||
|
if (this.plot3d != plot3d || this.plotBoundaries.equals(plotBoundaries)) {
|
||||||
|
this.plot3d = plot3d;
|
||||||
|
this.plotBoundaries = plotBoundaries;
|
||||||
|
firePlotDataChangedEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void firePlotDataChangedEvent() {
|
private void firePlotDataChangedEvent() {
|
||||||
plotData = new PlotData(getVisibleFunctions(), plot3d, plotBoundaries);
|
plotData = new PlotData(getVisibleFunctions(), plot3d, plotBoundaries);
|
||||||
calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData);
|
calculator.fireCalculatorEvent(CalculatorEventType.plot_data_changed, plotData);
|
||||||
|
Loading…
Reference in New Issue
Block a user