Multiple result support, Plus-Minus sign
This commit is contained in:
parent
2c13397919
commit
c81df8bdc0
BIN
res/font_big.rft
BIN
res/font_big.rft
Binary file not shown.
Binary file not shown.
@ -130,7 +130,7 @@ public class Keyboard {
|
|||||||
if (shift) {
|
if (shift) {
|
||||||
keyPressed(Key.NONE);
|
keyPressed(Key.NONE);
|
||||||
} else if (alpha) {
|
} else if (alpha) {
|
||||||
keyPressed(Key.NONE);
|
keyPressed(Key.LETTER_Y);
|
||||||
} else {
|
} else {
|
||||||
keyPressed(Key.DOT);
|
keyPressed(Key.DOT);
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ public class Keyboard {
|
|||||||
if (shift) {
|
if (shift) {
|
||||||
keyPressed(Key.NONE);
|
keyPressed(Key.NONE);
|
||||||
} else if (alpha) {
|
} else if (alpha) {
|
||||||
keyPressed(Key.NONE);
|
keyPressed(Key.LETTER_X);
|
||||||
} else {
|
} else {
|
||||||
keyPressed(Key.NUM0);
|
keyPressed(Key.NUM0);
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
} else if (row == 8 && col == 4) {
|
} else if (row == 8 && col == 4) {
|
||||||
if (shift) {
|
if (shift) {
|
||||||
keyPressed(Key.NONE);
|
keyPressed(Key.PLUS_MINUS);
|
||||||
} else if (alpha) {
|
} else if (alpha) {
|
||||||
keyPressed(Key.NONE);
|
keyPressed(Key.NONE);
|
||||||
} else {
|
} else {
|
||||||
@ -484,7 +484,7 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static enum Key {
|
public static enum Key {
|
||||||
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, DRG_CYCLE, LETTER_X, SIMPLIFY, SOLVE, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x
|
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, DRG_CYCLE, LETTER_X, LETTER_Y, SIMPLIFY, SOLVE, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,7 +527,7 @@ public class Keyboard {
|
|||||||
|5,8---|4,8---|3,8---|2,8---|1,8-----------------|
|
|5,8---|4,8---|3,8---|2,8---|1,8-----------------|
|
||||||
| 0 | . | | | SOLVE |
|
| 0 | . | | | SOLVE |
|
||||||
| | | | | SIMPLIFY |
|
| | | | | SIMPLIFY |
|
||||||
| | | |DRGCYCL| |
|
| X | Y | Z |DRGCYCL| |
|
||||||
|------|------|------|------|--------------------|
|
|------|------|------|------|--------------------|
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,6 +88,13 @@ public class PIFrame extends JFrame {
|
|||||||
Keyboard.keyPressed(Key.NONE);
|
Keyboard.keyPressed(Key.NONE);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case KeyEvent.VK_Y:
|
||||||
|
if (Keyboard.alpha) {
|
||||||
|
Keyboard.keyPressed(Key.LETTER_Y);
|
||||||
|
} else {
|
||||||
|
Keyboard.keyPressed(Key.NONE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case KeyEvent.VK_B:
|
case KeyEvent.VK_B:
|
||||||
if (Keyboard.shift) {
|
if (Keyboard.shift) {
|
||||||
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE_REVERSE);
|
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE_REVERSE);
|
||||||
@ -186,6 +193,8 @@ public class PIFrame extends JFrame {
|
|||||||
case KeyEvent.VK_ADD:
|
case KeyEvent.VK_ADD:
|
||||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||||
Keyboard.keyPressed(Key.PLUS);
|
Keyboard.keyPressed(Key.PLUS);
|
||||||
|
} else if (Keyboard.shift) {
|
||||||
|
Keyboard.keyPressed(Key.PLUS_MINUS);
|
||||||
} else {
|
} else {
|
||||||
Keyboard.keyPressed(Key.NONE);
|
Keyboard.keyPressed(Key.NONE);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package org.warp.picalculator;
|
|||||||
import static org.warp.engine.Display.Render.getStringWidth;
|
import static org.warp.engine.Display.Render.getStringWidth;
|
||||||
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Display;
|
import org.warp.engine.Display;
|
||||||
@ -32,7 +34,16 @@ public abstract class AnteriorFunction implements Function {
|
|||||||
public abstract String getSymbol();
|
public abstract String getSymbol();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Function solve() throws Error;
|
public abstract List<Function> solveOneStep() throws Error;
|
||||||
|
|
||||||
|
protected int stepsCount = -1;
|
||||||
|
@Override
|
||||||
|
public int getStepsCount() {
|
||||||
|
if (stepsCount == -1) {
|
||||||
|
stepsCount = variable.getStepsCount()+1;
|
||||||
|
}
|
||||||
|
return stepsCount;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
@ -77,11 +88,12 @@ public abstract class AnteriorFunction implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
// try {
|
||||||
return solve().toString();
|
// return solve().toString();
|
||||||
} catch (Error e) {
|
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||||
return e.id.toString();
|
// } catch (Error e) {
|
||||||
}
|
// return e.id.toString();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,6 +3,8 @@ package org.warp.picalculator;
|
|||||||
import static org.warp.engine.Display.Render.getStringWidth;
|
import static org.warp.engine.Display.Render.getStringWidth;
|
||||||
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Display;
|
import org.warp.engine.Display;
|
||||||
@ -32,7 +34,16 @@ public abstract class AnteriorFunctionBase extends FunctionBase {
|
|||||||
public abstract String getSymbol();
|
public abstract String getSymbol();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Number solve() throws Error;
|
public abstract List<Function> solveOneStep() throws Error;
|
||||||
|
|
||||||
|
protected int stepsCount = -1;
|
||||||
|
@Override
|
||||||
|
public int getStepsCount() {
|
||||||
|
if (stepsCount == -1) {
|
||||||
|
stepsCount = variable.getStepsCount()+1;
|
||||||
|
}
|
||||||
|
return stepsCount;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
@ -77,11 +88,12 @@ public abstract class AnteriorFunctionBase extends FunctionBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
// try {
|
||||||
return solve().toString();
|
// return solve().toString();
|
||||||
} catch (Error e) {
|
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||||
return e.id.toString();
|
// } catch (Error e) {
|
||||||
}
|
// return e.id.toString();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.NumeroAvanzato;
|
import org.nevec.rjm.NumeroAvanzato;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Screen;
|
import org.warp.engine.Screen;
|
||||||
@ -13,12 +17,6 @@ public class Calculator {
|
|||||||
public static int currentSession = 0;
|
public static int currentSession = 0;
|
||||||
public static boolean haxMode = true;
|
public static boolean haxMode = true;
|
||||||
|
|
||||||
public static Number solveResult(String string) throws Error {
|
|
||||||
System.out.println("INPUT: " + string);
|
|
||||||
Expression expression = new Expression(string);
|
|
||||||
return expression.solve();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Function parseString(String string) throws Error {
|
public static Function parseString(String string) throws Error {
|
||||||
if (string.contains("{")) {
|
if (string.contains("{")) {
|
||||||
if (!string.startsWith("{")) {
|
if (!string.startsWith("{")) {
|
||||||
@ -55,8 +53,29 @@ public class Calculator {
|
|||||||
if (f instanceof Equation) {
|
if (f instanceof Equation) {
|
||||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
||||||
} else {
|
} else {
|
||||||
es.f2 = es.f.solve();
|
List<Function> results = new ArrayList<>();
|
||||||
es.f2.generateGraphics();
|
List<Function> partialResults = new ArrayList<>();
|
||||||
|
results.add(es.f);
|
||||||
|
while (Utils.allSolved(results) == false) {
|
||||||
|
for (Function itm : results) {
|
||||||
|
if (itm.getStepsCount() > 0) {
|
||||||
|
partialResults.addAll(itm.solveOneStep());
|
||||||
|
} else {
|
||||||
|
partialResults.add(itm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
results = new ArrayList<Function>(partialResults);
|
||||||
|
partialResults.clear();
|
||||||
|
}
|
||||||
|
if (results.size() == 0) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Collections.reverse(results);
|
||||||
|
es.f2 = results;
|
||||||
|
for (Function rf : es.f2) {
|
||||||
|
rf.generateGraphics();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,8 +85,12 @@ public class Calculator {
|
|||||||
EquationScreen es = (EquationScreen) Calculator.sessions[0];
|
EquationScreen es = (EquationScreen) Calculator.sessions[0];
|
||||||
Function f = es.f;
|
Function f = es.f;
|
||||||
if (f instanceof Equation) {
|
if (f instanceof Equation) {
|
||||||
es.f2 = ((Equation)f).solve(letter);
|
List<Function> results = ((Equation)f).solve(letter);
|
||||||
es.f2.generateGraphics();
|
Collections.reverse(results);
|
||||||
|
es.f2 = results;
|
||||||
|
for (Function rf : es.f2) {
|
||||||
|
rf.generateGraphics();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ import static org.warp.engine.Display.Render.glColor3f;
|
|||||||
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
import static org.warp.engine.Display.Render.glFillRect;
|
import static org.warp.engine.Display.Render.glFillRect;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Display;
|
import org.warp.engine.Display;
|
||||||
@ -21,14 +24,53 @@ public class Division extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
if (variable2 == null || variable1 == null) {
|
if (variable1 == null || variable2 == null) {
|
||||||
return new Number("0");
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
}
|
}
|
||||||
if (variable2.solve().getTerm().compareTo(NumeroAvanzatoVec.ZERO) == 0) {
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
if (variable2 instanceof Number && ((Number)variable2).getTerm().compareTo(NumeroAvanzatoVec.ZERO) == 0) {
|
||||||
throw new Error(Errors.DIVISION_BY_ZERO);
|
throw new Error(Errors.DIVISION_BY_ZERO);
|
||||||
}
|
}
|
||||||
return variable1.solve().divide(variable2.solve());
|
result.add(((Number) variable1).divide((Number)variable2));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (size1 < size2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
}
|
||||||
|
if (size2 < size1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Division((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMinus() {
|
public boolean hasMinus() {
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||||
|
|
||||||
import com.rits.cloning.Cloner;
|
import com.rits.cloning.Cloner;
|
||||||
|
|
||||||
public class Equation extends FunctionTwoValues {
|
public class Equation extends FunctionTwoValues {
|
||||||
@ -18,11 +22,71 @@ public class Equation extends FunctionTwoValues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
return new Equation(new Subtraction((FunctionBase)variable1.solve(), (FunctionBase)variable2.solve()).solve(), new Number("0"));
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
if (((Number)variable2).getTerm().isBigInteger(false) && ((Number)variable2).getTerm().toBigInteger(false).compareTo(new BigInteger("0")) == 0) {
|
||||||
|
result.add(this);
|
||||||
|
} else {
|
||||||
|
result.add(new Equation(new Subtraction((FunctionBase)variable1, (FunctionBase)variable2), new Number("0")));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function solve(char variableCharacter) {
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Equation((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int stepsCount = -1;
|
||||||
|
@Override
|
||||||
|
public int getStepsCount() {
|
||||||
|
if (stepsCount == -1) {
|
||||||
|
int val1 = variable1.getStepsCount();
|
||||||
|
int val2 = variable2.getStepsCount();
|
||||||
|
if (val1 > val2) {
|
||||||
|
stepsCount = val1+1;
|
||||||
|
} else {
|
||||||
|
stepsCount = val2+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stepsCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Function> solve(char variableCharacter) {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
ArrayList<Equation> e;
|
ArrayList<Equation> e;
|
||||||
//TODO: WORK IN PROGRESS.
|
//TODO: WORK IN PROGRESS.
|
||||||
|
@ -2,6 +2,9 @@ package org.warp.picalculator;
|
|||||||
|
|
||||||
import static org.warp.engine.Display.Render.glDrawLine;
|
import static org.warp.engine.Display.Render.glDrawLine;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class EquationsSystem extends FunctionMultipleValues {
|
public class EquationsSystem extends FunctionMultipleValues {
|
||||||
static final int spacing = 2;
|
static final int spacing = 2;
|
||||||
|
|
||||||
@ -23,9 +26,14 @@ public class EquationsSystem extends FunctionMultipleValues {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Function solve() throws NumberFormatException, Error {
|
public List<Function> solveOneStep() throws NumberFormatException, Error {
|
||||||
// TODO implementare il calcolo dei sistemi
|
// TODO implementare il calcolo dei sistemi
|
||||||
return variables[0].solve();
|
if (stepsCount == 1) {
|
||||||
|
List<Function> l = new ArrayList<Function>();
|
||||||
|
l.add(variables[0]);
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
return variables[0].solveOneStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,6 +3,8 @@ package org.warp.picalculator;
|
|||||||
import static org.warp.engine.Display.Render.glColor3f;
|
import static org.warp.engine.Display.Render.glColor3f;
|
||||||
import static org.warp.engine.Display.Render.glDrawLine;
|
import static org.warp.engine.Display.Render.glDrawLine;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class EquationsSystemPart extends AnteriorFunction {
|
public class EquationsSystemPart extends AnteriorFunction {
|
||||||
|
|
||||||
public EquationsSystemPart(Equation equazione) {
|
public EquationsSystemPart(Equation equazione) {
|
||||||
@ -15,9 +17,9 @@ public class EquationsSystemPart extends AnteriorFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Equation solve() throws NumberFormatException, Error {
|
public List<Function> solveOneStep() throws NumberFormatException, Error {
|
||||||
// TODO implementare il calcolo dei sistemi
|
// TODO implementare il calcolo dei sistemi
|
||||||
return (Equation) variable.solve();
|
return variable.solveOneStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,11 +8,11 @@ import static org.warp.picalculator.Utils.concat;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.nevec.rjm.NumeroAvanzato;
|
import org.nevec.rjm.NumeroAvanzato;
|
||||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
|
||||||
|
|
||||||
public class Expression extends FunctionMultipleValuesBase {
|
public class Expression extends FunctionMultipleValuesBase {
|
||||||
|
|
||||||
@ -195,6 +195,9 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
case MathematicalSymbols.SUM:
|
case MathematicalSymbols.SUM:
|
||||||
f = new Sum(null, null);
|
f = new Sum(null, null);
|
||||||
break;
|
break;
|
||||||
|
case MathematicalSymbols.SUM_SUBTRACTION:
|
||||||
|
f = new SumSubtraction(null, null);
|
||||||
|
break;
|
||||||
case MathematicalSymbols.MULTIPLICATION:
|
case MathematicalSymbols.MULTIPLICATION:
|
||||||
f = new Multiplication(null, null);
|
f = new Multiplication(null, null);
|
||||||
break;
|
break;
|
||||||
@ -396,7 +399,7 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
if (funzioneTMP instanceof FunctionTwoValuesBase) {
|
if (funzioneTMP instanceof FunctionTwoValuesBase) {
|
||||||
if (step != "SN Functions") {
|
if (step != "SN Functions") {
|
||||||
if (
|
if (
|
||||||
(step == "sums" && (funzioneTMP instanceof Sum) == true && ((funzioneTMP instanceof AnteriorFunctionBase && ((AnteriorFunctionBase) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValuesBase && ((FunctionTwoValuesBase) funzioneTMP).variable1 == null && ((FunctionTwoValuesBase) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunctionBase) && !(funzioneTMP instanceof FunctionTwoValuesBase))))
|
(step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction) == true && ((funzioneTMP instanceof AnteriorFunctionBase && ((AnteriorFunctionBase) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValuesBase && ((FunctionTwoValuesBase) funzioneTMP).variable1 == null && ((FunctionTwoValuesBase) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunctionBase) && !(funzioneTMP instanceof FunctionTwoValuesBase))))
|
||||||
||
|
||
|
||||||
(
|
(
|
||||||
step.equals("prioritary multiplications")
|
step.equals("prioritary multiplications")
|
||||||
@ -427,6 +430,8 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
&&
|
&&
|
||||||
(funzioneTMP instanceof Sum) == false
|
(funzioneTMP instanceof Sum) == false
|
||||||
&&
|
&&
|
||||||
|
(funzioneTMP instanceof SumSubtraction) == false
|
||||||
|
&&
|
||||||
(funzioneTMP instanceof Multiplication) == false
|
(funzioneTMP instanceof Multiplication) == false
|
||||||
&&
|
&&
|
||||||
(funzioneTMP instanceof PrioritaryMultiplication) == false
|
(funzioneTMP instanceof PrioritaryMultiplication) == false
|
||||||
@ -471,13 +476,13 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
|
|
||||||
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
|
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
|
||||||
try {
|
try {
|
||||||
Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionTwoValuesBase) funzioneTMP).getVariable1().solve());
|
Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionTwoValuesBase) funzioneTMP).getVariable1().toString());
|
||||||
} catch (NullPointerException ex2) {}
|
} catch (NullPointerException ex2) {}
|
||||||
try {
|
try {
|
||||||
Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionTwoValuesBase) funzioneTMP).getVariable2().solve());
|
Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionTwoValuesBase) funzioneTMP).getVariable2().toString());
|
||||||
} catch (NullPointerException ex2) {}
|
} catch (NullPointerException ex2) {}
|
||||||
try {
|
try {
|
||||||
Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionTwoValuesBase) funzioneTMP).solve());
|
Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionTwoValuesBase) funzioneTMP).toString());
|
||||||
} catch (NullPointerException ex2) {}
|
} catch (NullPointerException ex2) {}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -502,7 +507,7 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
oldFunctionsList.remove(i + 1);
|
oldFunctionsList.remove(i + 1);
|
||||||
|
|
||||||
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
|
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
|
||||||
FunctionBase var = ((AnteriorFunctionBase) funzioneTMP).getVariable().solve();
|
FunctionBase var = ((AnteriorFunctionBase) funzioneTMP).getVariable();
|
||||||
if (var == null) {
|
if (var == null) {
|
||||||
Utils.debug.println(debugSpaces + " " + "var=null");
|
Utils.debug.println(debugSpaces + " " + "var=null");
|
||||||
} else {
|
} else {
|
||||||
@ -535,7 +540,7 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
}
|
}
|
||||||
Utils.debug.println(debugSpaces + "•Finished correcting classes.");
|
Utils.debug.println(debugSpaces + "•Finished correcting classes.");
|
||||||
|
|
||||||
Number result = solve();
|
String result = toString();
|
||||||
Utils.debug.println(debugSpaces + "•Result:" + result);
|
Utils.debug.println(debugSpaces + "•Result:" + result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -546,17 +551,39 @@ public class Expression extends FunctionMultipleValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
|
List<Function> ret = new ArrayList<>();
|
||||||
if (variables.length == 0) {
|
if (variables.length == 0) {
|
||||||
return new Number("0");
|
stepsCount = -1;
|
||||||
|
return ret;
|
||||||
} else if (variables.length == 1) {
|
} else if (variables.length == 1) {
|
||||||
return (Number) variables[0].solve();
|
if (variables[0].getStepsCount() > 0) {
|
||||||
|
List<Function> l = variables[0].solveOneStep();
|
||||||
|
for (Function f : l) {
|
||||||
|
if (f instanceof Number) {
|
||||||
|
ret.add(f);
|
||||||
} else {
|
} else {
|
||||||
Number result = new Number("0");
|
ret.add(new Expression(new FunctionBase[]{(FunctionBase) f}));
|
||||||
for (Function f : variables) {
|
|
||||||
result = result.add((Number) f.solve());
|
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
stepsCount = -1;
|
||||||
|
return ret;
|
||||||
|
} else {
|
||||||
|
ret.add(variables[0]);
|
||||||
|
stepsCount = -1;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Function f : variables) {
|
||||||
|
if (f.getStepsCount() >= stepsCount - 1) {
|
||||||
|
List<Function> partial = f.solveOneStep();
|
||||||
|
for (Function fnc : partial) {
|
||||||
|
ret.add(new Expression(new FunctionBase[]{(FunctionBase) fnc}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount = -1;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface Function {
|
public interface Function {
|
||||||
public String getSymbol();
|
public String getSymbol();
|
||||||
|
|
||||||
public Function solve() throws Error;
|
public int getStepsCount();
|
||||||
|
|
||||||
|
public List<Function> solveOneStep() throws Error;
|
||||||
|
|
||||||
public void generateGraphics();
|
public void generateGraphics();
|
||||||
|
|
||||||
@ -16,4 +20,10 @@ public interface Function {
|
|||||||
public int getLine();
|
public int getLine();
|
||||||
|
|
||||||
public void setSmall(boolean small);
|
public void setSmall(boolean small);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class FunctionBase implements Function {
|
public abstract class FunctionBase implements Function {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract String getSymbol();
|
public abstract String getSymbol();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Number solve() throws Error;
|
public abstract int getStepsCount();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract List<Function> solveOneStep() throws Error;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void generateGraphics();
|
public abstract void generateGraphics();
|
||||||
|
@ -62,19 +62,35 @@ public abstract class FunctionMultipleValues implements Function {
|
|||||||
@Override
|
@Override
|
||||||
public abstract String getSymbol();
|
public abstract String getSymbol();
|
||||||
|
|
||||||
|
protected int stepsCount = -1;
|
||||||
@Override
|
@Override
|
||||||
public abstract Function solve() throws Error;
|
public int getStepsCount() {
|
||||||
|
if (stepsCount == -1) {
|
||||||
|
int max = 0;
|
||||||
|
int cur = 0;
|
||||||
|
for (Function f : variables) {
|
||||||
|
cur = f.getStepsCount();
|
||||||
|
if (max < cur) {
|
||||||
|
max = cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max+1;
|
||||||
|
} else {
|
||||||
|
return stepsCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void generateGraphics();
|
public abstract void generateGraphics();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
// try {
|
||||||
return solve().toString();
|
// return solve().toString();
|
||||||
} catch (Error e) {
|
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||||
return e.id.toString();
|
// } catch (Error e) {
|
||||||
}
|
// return e.id.toString();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,22 +59,38 @@ public abstract class FunctionMultipleValuesBase extends FunctionBase {
|
|||||||
variables = Arrays.copyOf(variables, length);
|
variables = Arrays.copyOf(variables, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int stepsCount = -1;
|
||||||
@Override
|
@Override
|
||||||
public abstract String getSymbol();
|
public int getStepsCount() {
|
||||||
|
if (stepsCount == -1) {
|
||||||
|
int max = 0;
|
||||||
|
int cur = 0;
|
||||||
|
for (Function f : variables) {
|
||||||
|
cur = f.getStepsCount();
|
||||||
|
if (max < cur) {
|
||||||
|
max = cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max+1;
|
||||||
|
} else {
|
||||||
|
return stepsCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Number solve() throws Error;
|
public abstract String getSymbol();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void generateGraphics();
|
public abstract void generateGraphics();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
// try {
|
||||||
return solve().toString();
|
// return solve().toString();
|
||||||
} catch (Error e) {
|
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||||
return e.id.toString();
|
// } catch (Error e) {
|
||||||
}
|
// return e.id.toString();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,6 +3,8 @@ package org.warp.picalculator;
|
|||||||
import static org.warp.engine.Display.Render.getStringWidth;
|
import static org.warp.engine.Display.Render.getStringWidth;
|
||||||
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.Rational;
|
import org.nevec.rjm.Rational;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Display;
|
import org.warp.engine.Display;
|
||||||
@ -43,7 +45,10 @@ public abstract class FunctionTwoValues implements Function {
|
|||||||
public abstract String getSymbol();
|
public abstract String getSymbol();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Function solve() throws Error;
|
public abstract int getStepsCount();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract List<Function> solveOneStep() throws Error;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
@ -93,11 +98,12 @@ public abstract class FunctionTwoValues implements Function {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
// try {
|
||||||
return solve().toString();
|
// return solve().toString();
|
||||||
} catch (Error e) {
|
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||||
return e.id.toString();
|
// } catch (Error e) {
|
||||||
}
|
// return e.id.toString();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,6 +3,8 @@ package org.warp.picalculator;
|
|||||||
import static org.warp.engine.Display.Render.getStringWidth;
|
import static org.warp.engine.Display.Render.getStringWidth;
|
||||||
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.Rational;
|
import org.nevec.rjm.Rational;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Display;
|
import org.warp.engine.Display;
|
||||||
@ -43,7 +45,7 @@ public abstract class FunctionTwoValuesBase extends FunctionBase {
|
|||||||
public abstract String getSymbol();
|
public abstract String getSymbol();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract Number solve() throws Error;
|
public abstract List<Function> solveOneStep() throws Error;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateGraphics() {
|
public void generateGraphics() {
|
||||||
@ -93,11 +95,12 @@ public abstract class FunctionTwoValuesBase extends FunctionBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
try {
|
// try {
|
||||||
return solve().toString();
|
// return solve().toString();
|
||||||
} catch (Error e) {
|
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||||
return e.id.toString();
|
// } catch (Error e) {
|
||||||
}
|
// return e.id.toString();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,4 +142,19 @@ public abstract class FunctionTwoValuesBase extends FunctionBase {
|
|||||||
}
|
}
|
||||||
return tl.getLine();
|
return tl.getLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int stepsCount = -1;
|
||||||
|
@Override
|
||||||
|
public int getStepsCount() {
|
||||||
|
if (stepsCount == -1) {
|
||||||
|
int val1 = variable1.getStepsCount();
|
||||||
|
int val2 = variable2.getStepsCount();
|
||||||
|
if (val1 > val2) {
|
||||||
|
stepsCount = val1+1;
|
||||||
|
} else {
|
||||||
|
stepsCount = val2+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stepsCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import static org.warp.picalculator.Utils.concat;
|
|||||||
|
|
||||||
public class MathematicalSymbols {
|
public class MathematicalSymbols {
|
||||||
public static final String SUM = "+";
|
public static final String SUM = "+";
|
||||||
|
public static final String SUM_SUBTRACTION = "±";
|
||||||
public static final String SUBTRACTION = "-";
|
public static final String SUBTRACTION = "-";
|
||||||
public static final String MULTIPLICATION = "*";
|
public static final String MULTIPLICATION = "*";
|
||||||
public static final String PRIORITARY_MULTIPLICATION = "▪";
|
public static final String PRIORITARY_MULTIPLICATION = "▪";
|
||||||
@ -29,7 +30,7 @@ public class MathematicalSymbols {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final String[] signums(boolean withMultiplication, boolean withPrioritaryMultiplication) {
|
public static final String[] signums(boolean withMultiplication, boolean withPrioritaryMultiplication) {
|
||||||
String[] ret = new String[] { SUM, DIVISION };
|
String[] ret = new String[] { SUM, SUM_SUBTRACTION, DIVISION };
|
||||||
if (withMultiplication) {
|
if (withMultiplication) {
|
||||||
ret = Utils.add(ret, MULTIPLICATION);
|
ret = Utils.add(ret, MULTIPLICATION);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Multiplication extends FunctionTwoValuesBase {
|
public class Multiplication extends FunctionTwoValuesBase {
|
||||||
|
|
||||||
@ -14,8 +16,49 @@ public class Multiplication extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
return getVariable1().solve().multiply(getVariable2().solve());
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
result.add(((Number)variable1).multiply((Number)variable2));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Multiplication((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,6 +8,8 @@ import static org.warp.engine.Display.Render.glFillRect;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.math.MathContext;
|
import java.math.MathContext;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.BigDecimalMath;
|
import org.nevec.rjm.BigDecimalMath;
|
||||||
import org.nevec.rjm.NumeroAvanzato;
|
import org.nevec.rjm.NumeroAvanzato;
|
||||||
@ -65,11 +67,6 @@ public class Number extends FunctionBase {
|
|||||||
width = calcWidth();
|
width = calcWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Number solve() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSymbol() {
|
public String getSymbol() {
|
||||||
return toString();
|
return toString();
|
||||||
@ -386,6 +383,18 @@ public class Number extends FunctionBase {
|
|||||||
this.small = small;
|
this.small = small;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStepsCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Function> solveOneStep() throws Error {
|
||||||
|
List<Function> result = new ArrayList<>();
|
||||||
|
result.add(this);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Override
|
* @Override
|
||||||
* public void draw(int x, int y, Graphics g) {
|
* public void draw(int x, int y, Graphics g) {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Power extends FunctionTwoValuesBase {
|
public class Power extends FunctionTwoValuesBase {
|
||||||
|
|
||||||
public Power(FunctionBase value1, FunctionBase value2) {
|
public Power(FunctionBase value1, FunctionBase value2) {
|
||||||
@ -25,8 +28,49 @@ public class Power extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws NumberFormatException, Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
return getVariable1().solve().pow(getVariable2().solve());
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
result.add(((Number)variable1).pow((Number)variable2));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Power((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PrioritaryMultiplication extends FunctionTwoValuesBase {
|
public class PrioritaryMultiplication extends FunctionTwoValuesBase {
|
||||||
|
|
||||||
public PrioritaryMultiplication(FunctionBase value1, FunctionBase value2) {
|
public PrioritaryMultiplication(FunctionBase value1, FunctionBase value2) {
|
||||||
@ -12,8 +15,49 @@ public class PrioritaryMultiplication extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
return getVariable1().solve().multiply(getVariable2().solve());
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
result.add(((Number)variable1).multiply((Number)variable2));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new PrioritaryMultiplication((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,9 @@ package org.warp.picalculator;
|
|||||||
|
|
||||||
import static org.warp.engine.Display.Render.glDrawLine;
|
import static org.warp.engine.Display.Render.glDrawLine;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||||
|
|
||||||
public class Root extends FunctionTwoValuesBase {
|
public class Root extends FunctionTwoValuesBase {
|
||||||
@ -29,10 +32,51 @@ public class Root extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws NumberFormatException, Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
Number exponent = new Number(NumeroAvanzatoVec.ONE);
|
Number exponent = new Number(NumeroAvanzatoVec.ONE);
|
||||||
exponent = exponent.divide(getVariable1().solve());
|
exponent = exponent.divide((Number) getVariable1());
|
||||||
return getVariable2().solve().pow(exponent);
|
result.add(((Number)variable1).pow(exponent));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Root((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||||
import org.nevec.rjm.Rational;
|
import org.nevec.rjm.Rational;
|
||||||
|
|
||||||
public class RootSquare extends AnteriorFunctionBase {
|
public class RootSquare extends AnteriorFunctionBase {
|
||||||
@ -24,11 +28,15 @@ public class RootSquare extends AnteriorFunctionBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
|
if (variable == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
try {
|
try {
|
||||||
Number result = getVariable().solve();
|
Number var = (Number) getVariable();
|
||||||
result = result.pow(new Number(new Rational(1, 2)));
|
result.add(var.pow(new Number(new Rational(1, 2))));
|
||||||
return result;
|
|
||||||
} catch(NullPointerException ex) {
|
} catch(NullPointerException ex) {
|
||||||
throw new Error(Errors.ERROR);
|
throw new Error(Errors.ERROR);
|
||||||
} catch(NumberFormatException ex) {
|
} catch(NumberFormatException ex) {
|
||||||
@ -36,6 +44,20 @@ public class RootSquare extends AnteriorFunctionBase {
|
|||||||
} catch(ArithmeticException ex) {
|
} catch(ArithmeticException ex) {
|
||||||
throw new Error(Errors.NUMBER_TOO_SMALL);
|
throw new Error(Errors.NUMBER_TOO_SMALL);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
if (variable.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Function f : l1) {
|
||||||
|
result.add(new RootSquare((FunctionBase)f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package org.warp.picalculator;
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Subtraction extends FunctionTwoValuesBase {
|
public class Subtraction extends FunctionTwoValuesBase {
|
||||||
|
|
||||||
public Subtraction(FunctionBase value1, FunctionBase value2) {
|
public Subtraction(FunctionBase value1, FunctionBase value2) {
|
||||||
@ -12,8 +15,49 @@ public class Subtraction extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
return getVariable1().solve().add(getVariable2().solve().multiply(new Number("-1")));
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number("-1"))));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Subtraction((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,6 +3,9 @@ package org.warp.picalculator;
|
|||||||
import static org.warp.engine.Display.Render.getStringWidth;
|
import static org.warp.engine.Display.Render.getStringWidth;
|
||||||
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
import org.warp.engine.Display;
|
import org.warp.engine.Display;
|
||||||
|
|
||||||
@ -18,10 +21,48 @@ public class Sum extends FunctionTwoValuesBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Number solve() throws Error {
|
public List<Function> solveOneStep() throws Error {
|
||||||
Number val1 = getVariable1().solve();
|
if (variable1 == null || variable2 == null) {
|
||||||
Number val2 = getVariable2().solve();
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
Number result = val1.add(val2);
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
result.add(((Number)variable1).add((Number)variable2));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new Sum((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
117
src/org/warp/picalculator/SumSubtraction.java
Normal file
117
src/org/warp/picalculator/SumSubtraction.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package org.warp.picalculator;
|
||||||
|
|
||||||
|
import static org.warp.engine.Display.Render.getStringWidth;
|
||||||
|
import static org.warp.engine.Display.Render.glDrawStringLeft;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.warp.device.PIDisplay;
|
||||||
|
import org.warp.engine.Display;
|
||||||
|
|
||||||
|
public class SumSubtraction extends FunctionTwoValuesBase {
|
||||||
|
|
||||||
|
public SumSubtraction(FunctionBase value1, FunctionBase value2) {
|
||||||
|
super(value1, value2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSymbol() {
|
||||||
|
return MathematicalSymbols.SUM_SUBTRACTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Function> solveOneStep() throws Error {
|
||||||
|
if (variable1 == null || variable2 == null) {
|
||||||
|
throw new Error(Errors.SYNTAX_ERROR);
|
||||||
|
}
|
||||||
|
ArrayList<Function> result = new ArrayList<>();
|
||||||
|
if (stepsCount == 1) {
|
||||||
|
result.add(((Number)variable1).add((Number)variable2));
|
||||||
|
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number("-1"))));
|
||||||
|
} else {
|
||||||
|
List<Function> l1 = new ArrayList<Function>();
|
||||||
|
List<Function> l2 = new ArrayList<Function>();
|
||||||
|
if (variable1.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l1.addAll(variable1.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l1.add(variable1);
|
||||||
|
}
|
||||||
|
if (variable2.getStepsCount() >= stepsCount - 1) {
|
||||||
|
l2.addAll(variable2.solveOneStep());
|
||||||
|
} else {
|
||||||
|
l2.add(variable2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int size1 = l1.size();
|
||||||
|
int size2 = l2.size();
|
||||||
|
int cur1 = 0;
|
||||||
|
int cur2 = 0;
|
||||||
|
int total = l1.size()*l2.size();
|
||||||
|
Function[][] results = new Function[total][2];
|
||||||
|
for (int i = 0; i < total; i++) {
|
||||||
|
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
|
||||||
|
if (cur1 < cur2 && cur2 % size1 == 0) {
|
||||||
|
cur2+=1;
|
||||||
|
} else if (cur2 < cur1 && cur1 % size2 == 0) {
|
||||||
|
cur1+=1;
|
||||||
|
}
|
||||||
|
if (cur1 >= size1) cur1 = 0;
|
||||||
|
if (cur2 >= size1) cur2 = 0;
|
||||||
|
}
|
||||||
|
for (Function[] f : results) {
|
||||||
|
result.add(new SumSubtraction((FunctionBase)f[0], (FunctionBase)f[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stepsCount=-1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateGraphics() {
|
||||||
|
variable1.setSmall(small);
|
||||||
|
variable1.generateGraphics();
|
||||||
|
|
||||||
|
variable2.setSmall(small);
|
||||||
|
variable2.generateGraphics();
|
||||||
|
|
||||||
|
width = calcWidth();
|
||||||
|
height = calcHeight();
|
||||||
|
line = calcLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(int x, int y) {
|
||||||
|
// glColor3f(127, 127-50+new Random().nextInt(50), 255);
|
||||||
|
// glFillRect(x,y,width,height);
|
||||||
|
// glColor3f(0, 0, 0);
|
||||||
|
|
||||||
|
int ln = getLine();
|
||||||
|
int dx = 0;
|
||||||
|
variable1.draw(dx + x, ln - variable1.getLine() + y);
|
||||||
|
dx += variable1.getWidth();
|
||||||
|
if (small) {
|
||||||
|
Display.Render.setFont(PIDisplay.fonts[1]);
|
||||||
|
} else {
|
||||||
|
Display.Render.setFont(PIDisplay.fonts[0]);
|
||||||
|
}
|
||||||
|
dx += 1;
|
||||||
|
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
||||||
|
dx += getStringWidth(getSymbol());
|
||||||
|
variable2.draw(dx + x, ln - variable2.getLine() + y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int calcWidth() {
|
||||||
|
int dx = 0;
|
||||||
|
dx += variable1.getWidth();
|
||||||
|
dx += 1;
|
||||||
|
dx += getStringWidth(getSymbol());
|
||||||
|
return dx += variable2.getWidth();
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ import java.math.BigDecimal;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.nevec.rjm.BigDecimalMath;
|
import org.nevec.rjm.BigDecimalMath;
|
||||||
import org.nevec.rjm.Rational;
|
import org.nevec.rjm.Rational;
|
||||||
@ -82,7 +83,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList<Function> fl) {
|
public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunctionBase) {
|
if (fl.get(i) instanceof AnteriorFunctionBase) {
|
||||||
if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
|
if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -101,7 +102,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList<Function> fl) {
|
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunctionBase) {
|
if (fl.get(i) instanceof AnteriorFunctionBase) {
|
||||||
if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
|
if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -169,7 +170,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOnlyEmptyNSNFunctions(ArrayList<FunctionBase> fl) {
|
public static boolean areThereOnlyEmptyNSNFunctions(ArrayList<FunctionBase> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof FunctionTwoValuesBase && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof PrioritaryMultiplication) && !(fl.get(i) instanceof Division)) {
|
if (fl.get(i) instanceof FunctionTwoValuesBase && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof PrioritaryMultiplication) && !(fl.get(i) instanceof Division)) {
|
||||||
if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
|
if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -203,7 +204,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereEmptySums(ArrayList<FunctionBase> fl) {
|
public static boolean areThereEmptySums(ArrayList<FunctionBase> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (fl.get(i) instanceof Sum) {
|
if (fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction) {
|
||||||
if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
|
if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -225,7 +226,7 @@ public class Utils {
|
|||||||
|
|
||||||
public static boolean areThereOtherSettedUpFunctions(ArrayList<Function> fl) {
|
public static boolean areThereOtherSettedUpFunctions(ArrayList<Function> fl) {
|
||||||
for (int i = 0; i < fl.size(); i++) {
|
for (int i = 0; i < fl.size(); i++) {
|
||||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunctionBase || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Division)) {
|
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunctionBase || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Division)) {
|
||||||
if (fl.get(i) instanceof AnteriorFunctionBase) {
|
if (fl.get(i) instanceof AnteriorFunctionBase) {
|
||||||
if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
|
if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
|
||||||
return true;
|
return true;
|
||||||
@ -382,4 +383,13 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
return realbytes;
|
return realbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean allSolved(List<Function> expressions) {
|
||||||
|
for (Function itm : expressions) {
|
||||||
|
if (itm.getStepsCount() > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import static org.warp.engine.Display.Render.*;
|
|||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.warp.device.Keyboard.Key;
|
import org.warp.device.Keyboard.Key;
|
||||||
import org.warp.device.PIDisplay;
|
import org.warp.device.PIDisplay;
|
||||||
@ -24,7 +25,7 @@ public class EquationScreen extends Screen {
|
|||||||
public volatile boolean showCaret = true;
|
public volatile boolean showCaret = true;
|
||||||
public volatile float showCaretDelta = 0f;
|
public volatile float showCaretDelta = 0f;
|
||||||
public Function f;
|
public Function f;
|
||||||
public Function f2;
|
public List<Function> f2;
|
||||||
public int ew1;
|
public int ew1;
|
||||||
public int ew2;
|
public int ew2;
|
||||||
public int eh2;
|
public int eh2;
|
||||||
@ -150,8 +151,13 @@ public class EquationScreen extends Screen {
|
|||||||
glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length()));
|
glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length()));
|
||||||
if (f != null)
|
if (f != null)
|
||||||
f.draw(2, 22+1+9+1);
|
f.draw(2, 22+1+9+1);
|
||||||
if (f2 != null)
|
if (f2 != null) {
|
||||||
f2.draw(Display.getWidth() - 2 - f2.getWidth(), Display.getHeight() - 2 - f2.getHeight());
|
int bottomSpacing = 0;
|
||||||
|
for (Function f : f2) {
|
||||||
|
bottomSpacing += f.getHeight()+2;
|
||||||
|
f.draw(Display.getWidth() - 2 - f.getWidth(), Display.getHeight() - bottomSpacing);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -184,6 +190,9 @@ public class EquationScreen extends Screen {
|
|||||||
interpreta(nuovaEquazione);
|
interpreta(nuovaEquazione);
|
||||||
solve();
|
solve();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
if (Utils.debugOn) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
throw new Error(Errors.ERROR);
|
throw new Error(Errors.ERROR);
|
||||||
}
|
}
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
@ -234,6 +243,9 @@ public class EquationScreen extends Screen {
|
|||||||
case MINUS:
|
case MINUS:
|
||||||
typeChar("-");
|
typeChar("-");
|
||||||
return true;
|
return true;
|
||||||
|
case PLUS_MINUS:
|
||||||
|
typeChar("±");
|
||||||
|
return true;
|
||||||
case MULTIPLY:
|
case MULTIPLY:
|
||||||
typeChar("*");
|
typeChar("*");
|
||||||
return true;
|
return true;
|
||||||
@ -265,6 +277,12 @@ public class EquationScreen extends Screen {
|
|||||||
case POWER_OF_x:
|
case POWER_OF_x:
|
||||||
typeChar("^");
|
typeChar("^");
|
||||||
return true;
|
return true;
|
||||||
|
case LETTER_X:
|
||||||
|
typeChar("X");
|
||||||
|
return true;
|
||||||
|
case LETTER_Y:
|
||||||
|
typeChar("Y");
|
||||||
|
return true;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
if (nuovaEquazione.length() > 0) {
|
if (nuovaEquazione.length() > 0) {
|
||||||
if (caretPos > 0) {
|
if (caretPos > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user