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-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;
|
2017-01-31 22:29:49 +01:00
|
|
|
import org.warp.picalculator.gui.DisplayManager;
|
2017-02-14 20:02:03 +01:00
|
|
|
import org.warp.picalculator.math.MathContext;
|
|
|
|
import org.warp.picalculator.math.Function;
|
|
|
|
import org.warp.picalculator.math.FunctionDynamic;
|
2016-10-02 16:01:41 +02:00
|
|
|
import org.warp.picalculator.math.functions.Expression;
|
|
|
|
import org.warp.picalculator.math.functions.Number;
|
2016-09-19 18:48:27 +02:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public class EquationsSystem extends FunctionDynamic {
|
2016-09-12 16:30:51 +02:00
|
|
|
static final int spacing = 2;
|
2017-01-17 22:32:40 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public EquationsSystem(MathContext root) {
|
2017-01-17 22:32:40 +01:00
|
|
|
super(root);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public EquationsSystem(MathContext root, Function value) {
|
2017-01-31 22:29:49 +01:00
|
|
|
super(root, new Function[] { value });
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-02-14 20:02:03 +01:00
|
|
|
public EquationsSystem(MathContext root, Function[] value) {
|
2017-01-17 22:32:40 +01:00
|
|
|
super(root, 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() {
|
2016-11-25 22:40:43 +01:00
|
|
|
if (functions.length >= 1) {
|
2016-10-02 16:01:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-10-02 16:01:41 +02:00
|
|
|
@Override
|
|
|
|
public List<Function> solveOneStep() throws Error {
|
2017-01-31 22:29:49 +01:00
|
|
|
final List<Function> ret = new ArrayList<>();
|
2016-11-25 22:40:43 +01:00
|
|
|
if (functions.length == 1) {
|
2017-02-14 20:02:03 +01:00
|
|
|
if (functions[0].isSimplified()) {
|
2016-11-25 22:40:43 +01:00
|
|
|
ret.add(functions[0]);
|
2016-10-02 16:01:41 +02:00
|
|
|
return ret;
|
|
|
|
} else {
|
2017-02-14 20:02:03 +01:00
|
|
|
final List<Function> l = functions[0].simplify();
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : l) {
|
2016-10-02 16:01:41 +02:00
|
|
|
if (f instanceof Number) {
|
|
|
|
ret.add(f);
|
|
|
|
} else {
|
2017-01-31 22:29:49 +01:00
|
|
|
ret.add(new Expression(root, new Function[] { f }));
|
2016-10-02 16:01:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else {
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : functions) {
|
2017-02-14 20:02:03 +01:00
|
|
|
if (f.isSimplified() == false) {
|
|
|
|
final List<Function> partial = f.simplify();
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function fnc : partial) {
|
|
|
|
ret.add(new Expression(root, new 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() {
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : functions) {
|
2016-09-12 16:30:51 +02:00
|
|
|
f.setSmall(false);
|
2017-02-14 20:02:03 +01:00
|
|
|
f.recomputeDimensions();
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-09-12 16:30:51 +02:00
|
|
|
width = 0;
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : functions) {
|
2016-09-12 16:30:51 +02:00
|
|
|
if (f.getWidth() > width) {
|
|
|
|
width = f.getWidth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
width += 5;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-09-12 16:30:51 +02:00
|
|
|
height = 3;
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : functions) {
|
|
|
|
height += f.getHeight() + spacing;
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
height = height - spacing + 2;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
line = height / 2;
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2016-09-12 16:30:51 +02:00
|
|
|
@Override
|
|
|
|
public void draw(int x, int y) {
|
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
final int h = getHeight() - 1;
|
2016-09-12 16:30:51 +02:00
|
|
|
final int marginTop = 3;
|
|
|
|
final int marginBottom = (h - 3 - 2) / 2 + marginTop;
|
|
|
|
final int spazioSopra = h - marginBottom;
|
|
|
|
int dy = marginTop;
|
2017-01-31 22:29:49 +01:00
|
|
|
for (final Function f : functions) {
|
2017-02-14 20:02:03 +01:00
|
|
|
f.draw(x + 5, y + dy, null, null);
|
2017-01-31 22:29:49 +01:00
|
|
|
dy += f.getHeight() + spacing;
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 2, y + 0, x + 3, y + 0);
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + marginBottom / 2);
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 2, y + marginBottom / 2 + 1, x + 2, y + marginBottom - 1);
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 0, y + marginBottom, x + 1, y + marginBottom);
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 2, y + marginBottom + 1, x + 2, y + marginBottom + spazioSopra / 2 - 1);
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 1, y + marginBottom + spazioSopra / 2, x + 1, y + h - 1);
|
|
|
|
DisplayManager.renderer.glDrawLine(x + 2, y + h, x + 3, y + h);
|
2016-09-12 16:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getLine() {
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
}
|