2016-09-19 18:48:27 +02:00
|
|
|
package org.warp.picalculator.math.functions.equations;
|
2016-09-12 16:30:51 +02:00
|
|
|
|
2016-09-19 18:48:27 +02:00
|
|
|
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
|
2016-09-12 16:30:51 +02:00
|
|
|
|
2016-09-18 14:33:25 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-09-19 18:48:27 +02:00
|
|
|
import org.warp.picalculator.Error;
|
2016-10-02 16:01:41 +02:00
|
|
|
import org.warp.picalculator.math.functions.Expression;
|
2016-09-19 18:48:27 +02:00
|
|
|
import org.warp.picalculator.math.functions.Function;
|
|
|
|
import org.warp.picalculator.math.functions.FunctionMultipleValues;
|
2016-10-02 16:01:41 +02:00
|
|
|
import org.warp.picalculator.math.functions.Number;
|
2016-09-19 18:48:27 +02:00
|
|
|
|
2016-09-12 16:30:51 +02:00
|
|
|
public class EquationsSystem extends FunctionMultipleValues {
|
|
|
|
static final int spacing = 2;
|
|
|
|
|
2016-11-02 21:56:40 +01:00
|
|
|
public EquationsSystem(Function parent) {
|
|
|
|
super(parent);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 21:56:40 +01:00
|
|
|
public EquationsSystem(Function parent, Function value) {
|
|
|
|
super(parent, new Function[]{value});
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 21:56:40 +01:00
|
|
|
public EquationsSystem(Function parent, Function[] value) {
|
|
|
|
super(parent, value);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSymbol() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-02 16:01:41 +02:00
|
|
|
protected boolean isSolvable() {
|
|
|
|
if (variables.length >= 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Function> solveOneStep() throws Error {
|
|
|
|
List<Function> ret = new ArrayList<>();
|
|
|
|
if (variables.length == 1) {
|
|
|
|
if (variables[0].isSolved()) {
|
|
|
|
ret.add(variables[0]);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
List<Function> l = variables[0].solveOneStep();
|
|
|
|
for (Function f : l) {
|
|
|
|
if (f instanceof Number) {
|
|
|
|
ret.add(f);
|
|
|
|
} else {
|
2016-11-02 21:56:40 +01:00
|
|
|
ret.add(new Expression(this.parent, new Function[]{(Function) f}));
|
2016-10-02 16:01:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (Function f : variables) {
|
|
|
|
if (f.isSolved() == false) {
|
|
|
|
List<Function> partial = f.solveOneStep();
|
|
|
|
for (Function fnc : partial) {
|
2016-11-02 21:56:40 +01:00
|
|
|
ret.add(new Expression(this.parent, new Function[]{(Function) fnc}));
|
2016-10-02 16:01:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2016-09-18 14:33:25 +02:00
|
|
|
}
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void generateGraphics() {
|
|
|
|
for (Function f : variables) {
|
|
|
|
f.setSmall(false);
|
|
|
|
f.generateGraphics();
|
|
|
|
}
|
|
|
|
|
|
|
|
width = 0;
|
|
|
|
for (Function f : variables) {
|
|
|
|
if (f.getWidth() > width) {
|
|
|
|
width = f.getWidth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
width += 5;
|
|
|
|
|
|
|
|
height = 3;
|
|
|
|
for (Function f : variables) {
|
|
|
|
height += f.getHeight()+spacing;
|
|
|
|
}
|
|
|
|
height = height - spacing + 2;
|
|
|
|
|
|
|
|
line = height/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw(int x, int y) {
|
|
|
|
|
|
|
|
final int h = this.getHeight() - 1;
|
|
|
|
final int marginTop = 3;
|
|
|
|
final int marginBottom = (h - 3 - 2) / 2 + marginTop;
|
|
|
|
final int spazioSopra = h - marginBottom;
|
|
|
|
int dy = marginTop;
|
|
|
|
for (Function f : variables) {
|
|
|
|
f.draw(x + 5, y + dy);
|
|
|
|
dy+=f.getHeight()+spacing;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
glDrawLine(x + 2, y + 0, x + 3, y + 0);
|
|
|
|
glDrawLine(x + 1, y + 1, x + 1, y + marginBottom / 2);
|
|
|
|
glDrawLine(x + 2, y + marginBottom / 2 + 1, x + 2, y + marginBottom - 1);
|
|
|
|
glDrawLine(x + 0, y + marginBottom, x + 1, y + marginBottom);
|
|
|
|
glDrawLine(x + 2, y + marginBottom + 1, x + 2, y + marginBottom + spazioSopra / 2 - 1);
|
|
|
|
glDrawLine(x + 1, y + marginBottom + spazioSopra / 2, x + 1, y + h - 1);
|
|
|
|
glDrawLine(x + 2, y + h, x + 3, y + h);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getLine() {
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
}
|