From 50e6837edaa716e8731f56f5cc0b5fee4553d631 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Tue, 14 Feb 2017 20:02:03 +0100 Subject: [PATCH 01/10] Finished rewriting calculus engine. Finished rewriting calculus engine and affected classes: functions and rules. --- .../warp/picalculator/TestCalcBenchmark.java | 28 ++ src/org/warp/picalculator/Utils.java | 107 +++++-- src/org/warp/picalculator/gui/math/Block.java | 11 + .../warp/picalculator/gui/math/Container.java | 112 +++++++ .../gui/math/GraphicalElement.java | 33 ++ .../screens/ChooseVariableValueScreen.java | 2 +- .../gui/screens/MathInputScreen.java | 38 +-- .../gui/screens/SolveEquationScreen.java | 2 +- src/org/warp/picalculator/math/Function.java | 56 ++++ .../picalculator/math/FunctionDynamic.java | 165 ++++++++++ .../picalculator/math/FunctionOperator.java | 164 ++++++++++ .../picalculator/math/FunctionSingle.java | 130 ++++++++ .../{Calculator.java => MathContext.java} | 30 +- .../math/functions/AnteriorFunction.java | 150 --------- .../picalculator/math/functions/Division.java | 171 ++-------- .../math/functions/EmptyNumber.java | 70 ++-- .../math/functions/Expression.java | 303 ++++++------------ .../picalculator/math/functions/Function.java | 34 -- .../functions/FunctionMultipleValues.java | 129 -------- .../math/functions/FunctionTwoValues.java | 197 ------------ .../picalculator/math/functions/Joke.java | 73 ++--- .../math/functions/Multiplication.java | 119 ++----- .../picalculator/math/functions/Negative.java | 32 +- .../picalculator/math/functions/Number.java | 155 ++------- .../picalculator/math/functions/Power.java | 75 +---- .../picalculator/math/functions/Root.java | 72 +++-- .../math/functions/RootSquare.java | 42 +-- .../math/functions/Subtraction.java | 20 +- .../warp/picalculator/math/functions/Sum.java | 79 ++--- .../math/functions/SumSubtraction.java | 44 +-- .../math/functions/Undefined.java | 9 +- .../picalculator/math/functions/Variable.java | 121 ++----- .../math/functions/equations/Equation.java | 26 +- .../functions/equations/EquationsSystem.java | 26 +- .../equations/EquationsSystemPart.java | 26 +- .../functions/trigonometry/ArcCosine.java | 12 +- .../math/functions/trigonometry/ArcSine.java | 12 +- .../functions/trigonometry/ArcTangent.java | 12 +- .../math/functions/trigonometry/Cosine.java | 12 +- .../math/functions/trigonometry/Sine.java | 26 +- .../math/functions/trigonometry/Tangent.java | 12 +- .../picalculator/math/rules/ExpandRule1.java | 82 ++--- .../picalculator/math/rules/ExpandRule5.java | 18 +- .../math/rules/ExponentRule1.java | 10 +- .../math/rules/ExponentRule15.java | 17 +- .../math/rules/ExponentRule16.java | 30 +- .../math/rules/ExponentRule17.java | 17 +- .../math/rules/ExponentRule2.java | 6 +- .../math/rules/ExponentRule3.java | 6 +- .../math/rules/ExponentRule4.java | 36 +-- .../math/rules/ExponentRule9.java | 12 +- .../math/rules/FractionsRule1.java | 16 +- .../math/rules/FractionsRule11.java | 22 +- .../math/rules/FractionsRule12.java | 22 +- .../math/rules/FractionsRule14.java | 82 ++--- .../math/rules/FractionsRule2.java | 10 +- .../math/rules/FractionsRule3.java | 6 +- .../math/rules/FractionsRule4.java | 14 +- .../math/rules/FractionsRule5.java | 16 +- .../picalculator/math/rules/NumberRule1.java | 16 +- .../picalculator/math/rules/NumberRule2.java | 28 +- .../picalculator/math/rules/NumberRule3.java | 20 +- .../picalculator/math/rules/NumberRule4.java | 10 +- .../picalculator/math/rules/NumberRule5.java | 20 +- .../picalculator/math/rules/NumberRule6.java | 31 +- .../picalculator/math/rules/NumberRule7.java | 12 +- .../picalculator/math/rules/SyntaxRule1.java | 34 +- .../picalculator/math/rules/SyntaxRule2.java | 34 +- .../math/rules/UndefinedRule1.java | 10 +- .../math/rules/UndefinedRule2.java | 12 +- .../math/rules/VariableRule1.java | 45 ++- .../math/rules/VariableRule2.java | 39 +-- .../math/rules/VariableRule3.java | 39 +-- .../math/rules/methods/DivisionRule1.java | 22 +- .../rules/methods/MultiplicationMethod1.java | 16 +- .../math/rules/methods/SumMethod1.java | 34 +- 76 files changed, 1669 insertions(+), 2112 deletions(-) create mode 100644 src/org/warp/picalculator/TestCalcBenchmark.java create mode 100644 src/org/warp/picalculator/gui/math/Block.java create mode 100644 src/org/warp/picalculator/gui/math/Container.java create mode 100644 src/org/warp/picalculator/gui/math/GraphicalElement.java create mode 100644 src/org/warp/picalculator/math/Function.java create mode 100644 src/org/warp/picalculator/math/FunctionDynamic.java create mode 100644 src/org/warp/picalculator/math/FunctionOperator.java create mode 100644 src/org/warp/picalculator/math/FunctionSingle.java rename src/org/warp/picalculator/math/{Calculator.java => MathContext.java} (79%) delete mode 100644 src/org/warp/picalculator/math/functions/AnteriorFunction.java delete mode 100644 src/org/warp/picalculator/math/functions/Function.java delete mode 100644 src/org/warp/picalculator/math/functions/FunctionMultipleValues.java delete mode 100644 src/org/warp/picalculator/math/functions/FunctionTwoValues.java diff --git a/src/org/warp/picalculator/TestCalcBenchmark.java b/src/org/warp/picalculator/TestCalcBenchmark.java new file mode 100644 index 00000000..d434f82d --- /dev/null +++ b/src/org/warp/picalculator/TestCalcBenchmark.java @@ -0,0 +1,28 @@ +package org.warp.picalculator; + +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.functions.Multiplication; + +public class TestCalcBenchmark { + + public static void main(String[] args) throws Error { + Utils.debugOn = true; + int times = 1; + + MathContext mc = new MathContext(); + long time1 = System.nanoTime(); + mc.parseInputString("5WABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHI"); + long time2 = System.nanoTime(); + for (int i = 0; i < times; i++) { + if (i == 1) { + Utils.debugOn = false; + } + mc.f2 = mc.solveExpression(mc.f); + } + long time3 = System.nanoTime(); +// System.out.println(mc.f2.get(0).toString()); + System.out.println("PARSING\t"+((time2-time1) / 1000000d / ((double) times)) + " milliseconds"); + System.out.println("WORK\t"+((time3-time2) / 1000000d / ((double) times)) + " milliseconds"); + System.out.println("TOTAL\t"+((time3-time1) / 1000000d / ((double) times)) + " milliseconds"); + } +} diff --git a/src/org/warp/picalculator/Utils.java b/src/org/warp/picalculator/Utils.java index 602f3c86..6ae106c7 100644 --- a/src/org/warp/picalculator/Utils.java +++ b/src/org/warp/picalculator/Utils.java @@ -22,11 +22,11 @@ import org.nevec.rjm.BigDecimalMath; import org.nevec.rjm.Rational; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.BinaryFont; -import org.warp.picalculator.math.functions.AnteriorFunction; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Negative; import org.warp.picalculator.math.functions.Number; @@ -127,12 +127,12 @@ public class Utils { public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { - if (fl.get(i) instanceof AnteriorFunction) { - if (((AnteriorFunction) fl.get(i)).getVariable() == null) { + if (fl.get(i) instanceof FunctionSingle) { + if (((FunctionSingle) fl.get(i)).getParameter() == null) { return false; } - } else if (fl.get(i) instanceof FunctionTwoValues) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + } else if (fl.get(i) instanceof FunctionOperator) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) { return false; } } else { @@ -146,12 +146,12 @@ public class Utils { public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { - if (fl.get(i) instanceof AnteriorFunction) { - if (((AnteriorFunction) fl.get(i)).getVariable() == null) { + if (fl.get(i) instanceof FunctionSingle) { + if (((FunctionSingle) fl.get(i)).getParameter() == null) { return false; } - } else if (fl.get(i) instanceof FunctionTwoValues) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + } else if (fl.get(i) instanceof FunctionOperator) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) { return false; } } else { @@ -165,12 +165,12 @@ public class Utils { public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { - if (fl.get(i) instanceof AnteriorFunction) { - if (((AnteriorFunction) fl.get(i)).getVariable() == null) { + if (fl.get(i) instanceof FunctionSingle) { + if (((FunctionSingle) fl.get(i)).getParameter() == null) { return false; } - } else if (fl.get(i) instanceof FunctionTwoValues) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + } else if (fl.get(i) instanceof FunctionOperator) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) { return false; } } else { @@ -184,12 +184,12 @@ public class Utils { public static boolean areThereOnlySettedUpFunctionsAndSystems(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { - if (fl.get(i) instanceof AnteriorFunction) { - if (((AnteriorFunction) fl.get(i)).getVariable() == null) { + if (fl.get(i) instanceof FunctionSingle) { + if (((FunctionSingle) fl.get(i)).getParameter() == null) { return false; } - } else if (fl.get(i) instanceof FunctionTwoValues) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + } else if (fl.get(i) instanceof FunctionOperator) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) { return false; } } else { @@ -202,8 +202,8 @@ public class Utils { public static boolean areThereOnlyEmptySNFunctions(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { - if (fl.get(i) instanceof AnteriorFunction) { - if (((AnteriorFunction) fl.get(i)).getVariable() == null) { + if (fl.get(i) instanceof FunctionSingle) { + if (((FunctionSingle) fl.get(i)).getParameter() == null) { return true; } } @@ -213,8 +213,8 @@ public class Utils { public static boolean areThereOnlyEmptyNSNFunctions(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { - if (fl.get(i) instanceof FunctionTwoValues && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof Division)) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + if (fl.get(i) instanceof FunctionOperator && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof Division)) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) { return true; } } @@ -225,7 +225,7 @@ public class Utils { public static boolean areThereEmptyMultiplications(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) { return true; } } @@ -236,7 +236,7 @@ public class Utils { public static boolean areThereEmptySums(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) { return true; } } @@ -247,7 +247,7 @@ public class Utils { public static boolean areThereEmptySystems(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof EquationsSystemPart) { - if (((EquationsSystemPart) fl.get(i)).getVariable() == null) { + if (((EquationsSystemPart) fl.get(i)).getParameter() == null) { return true; } } @@ -257,13 +257,13 @@ public class Utils { public static boolean areThereOtherSettedUpFunctions(ArrayList fl) { for (int i = 0; i < fl.size(); i++) { - if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunction || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division)) { - if (fl.get(i) instanceof AnteriorFunction) { - if (((AnteriorFunction) fl.get(i)).getVariable() == null) { + if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof FunctionSingle || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division)) { + if (fl.get(i) instanceof FunctionSingle) { + if (((FunctionSingle) fl.get(i)).getParameter() == null) { return true; } - } else if (fl.get(i) instanceof FunctionTwoValues) { - if (((FunctionTwoValues) fl.get(i)).getVariable1() == null || ((FunctionTwoValues) fl.get(i)).getVariable2() == null) { + } else if (fl.get(i) instanceof FunctionOperator) { + if (((FunctionOperator) fl.get(i)).getParameter1() == null || ((FunctionOperator) fl.get(i)).getParameter2() == null) { return true; } } else { @@ -358,7 +358,7 @@ public class Utils { final int wsegno = 5; final int hsegno = h1 + 2; - var.draw(x + wsegno, y + (hsegno - h1)); + var.draw(x + wsegno, y + (hsegno - h1), null, null); DisplayManager.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3); DisplayManager.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2); @@ -449,7 +449,7 @@ public class Utils { public static boolean allSolved(List expressions) throws Error { for (final Function itm : expressions) { - if (itm.isSolved() == false) { + if (itm.isSimplified() == false) { return false; } } @@ -461,7 +461,7 @@ public class Utils { final int size2 = l2.size(); int cur1 = 0; int cur2 = 0; - final int total = l1.size() * l2.size(); + final int total = size1 * size2; final Function[][] results = new Function[total][2]; for (int i = 0; i < total; i++) { results[i] = new Function[] { l1.get(cur1), l2.get(cur2) }; @@ -480,6 +480,45 @@ public class Utils { } return results; } + + + public static Function[][] joinFunctionsResults(ArrayList> ln) { + final int[] sizes = new int[ln.size()]; + for (int i = 0; i < ln.size(); i++) { + sizes[i] = ln.get(i).size(); + } + int[] curs = new int[sizes.length]; + int total = 0; + for (int i = 0; i < ln.size(); i++) { + if (i == 0) { + total = sizes[i]; + } else { + total *= sizes[i]; + } + } + final Function[][] results = new Function[total][sizes.length]; + for (int i = 0; i < total; i++) { + results[i] = new Function[sizes.length]; + for (int j = 0; j < sizes.length; j++) { + results[i][j] = ln.get(j).get(curs[j]); + } + for (int k = 0; k < sizes.length; k++) { + if (i % sizes[k] == 0) { + for (int l = 0; l < sizes.length; l++) { + if (l != k) { + curs[l] += 1; + } + } + } + } + for (int k = 0; k < sizes.length; k++) { + if (curs[k] >= sizes[k]) { + curs[k] = 0; + } + } + } + return results; + } public static boolean isNegative(Function b) { if (b instanceof Negative) { diff --git a/src/org/warp/picalculator/gui/math/Block.java b/src/org/warp/picalculator/gui/math/Block.java new file mode 100644 index 00000000..c33f1316 --- /dev/null +++ b/src/org/warp/picalculator/gui/math/Block.java @@ -0,0 +1,11 @@ +package org.warp.picalculator.gui.math; + +public abstract class Block { + /** + * + * @param x Position relative to the window. + * @param y Position relative to the window. + * @param c Parent container. + */ + public abstract void draw(int x, int y, Container c); +} diff --git a/src/org/warp/picalculator/gui/math/Container.java b/src/org/warp/picalculator/gui/math/Container.java new file mode 100644 index 00000000..4880de8d --- /dev/null +++ b/src/org/warp/picalculator/gui/math/Container.java @@ -0,0 +1,112 @@ +package org.warp.picalculator.gui.math; + +import java.util.ArrayList; + +import org.warp.picalculator.device.graphicengine.Display; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; + +public class Container implements GraphicalElement { + + private final int minWidth; + private final int minHeight; + private final ArrayList content; + private int width; + private int height; + private int line; + + public Container(int minWidth, int minHeight) { + this.minWidth = minWidth; + this.minHeight = minHeight; + this.content = new ArrayList<>(); + } + + public Container(int minWidth, int minHeight, ArrayList content) { + this.minWidth = minWidth; + this.minHeight = minHeight; + this.content = content; + } + + public void addBlock(Block b) { + content.add(b); + recomputeDimensions(); + } + + public void removeBlock(Block b) { + content.remove(b); + recomputeDimensions(); + } + + public void removeAt(int i) { + content.remove(i); + recomputeDimensions(); + } + + public Block getBlockAt(int i) { + return content.get(i); + } + + public void clear() { + content.clear(); + recomputeDimensions(); + } + + /** + * + * @param x Position relative to the window. + * @param y Position relative to the window. + * @param small size of the element. + * @param caretPos remaining positions of the caret. + * @return caretPos - currentElementLength + */ + public int draw(GraphicEngine g, int x, int y, boolean small, int caretPos) { + Renderer r = g.getRenderer(); + return caretPos; + + } + + @Override + public void recomputeDimensions() { + int w = 0; + int h = 0; + int l = 0; + + for (Block b : content) { + w += b.getWidth(); + } + + if (w > minWidth) { + width = w; + } else { + width = minWidth; + } + if (h > minHeight) { + height = h; + } else { + height = minHeight; + } + line = l; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public int getLine() { + return line; + } + + @Override + public int getLength() { + // TODO Auto-generated method stub + return 0; + } + +} \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/math/GraphicalElement.java b/src/org/warp/picalculator/gui/math/GraphicalElement.java new file mode 100644 index 00000000..6c5a152e --- /dev/null +++ b/src/org/warp/picalculator/gui/math/GraphicalElement.java @@ -0,0 +1,33 @@ +package org.warp.picalculator.gui.math; + +public interface GraphicalElement { + + /** + * Recompute element's dimension parameters, like width, height, line or length. + */ + public void recomputeDimensions(); + + /** + * + * @return Width of the element. + */ + public int getWidth(); + + /** + * + * @return Height of the element. + */ + public int getHeight(); + + /** + * + * @return Position of the vertical alignment line of the element, relative to itself. + */ + public int getLine(); + + /** + * Used to compute the position of the caret. + * @return Length (in characters) of the element. + */ + public int getLength(); +} diff --git a/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java b/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java index f9d7d1f4..4c5a7fa0 100644 --- a/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java +++ b/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java @@ -4,7 +4,7 @@ import org.warp.picalculator.Main; import org.warp.picalculator.Utils; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Variable.VariableValue; public class ChooseVariableValueScreen extends Screen { diff --git a/src/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/org/warp/picalculator/gui/screens/MathInputScreen.java index 948fc8d2..6fe471a9 100644 --- a/src/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -19,12 +19,12 @@ import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.math.AngleMode; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionDynamic; +import org.warp.picalculator.math.FunctionSingle; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionMultipleValues; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Variable; import org.warp.picalculator.math.functions.Variable.VariableValue; import org.warp.picalculator.math.functions.equations.Equation; @@ -37,7 +37,7 @@ public class MathInputScreen extends Screen { public volatile int caretPos = 0; public volatile boolean showCaret = true; public volatile float showCaretDelta = 0f; - public Calculator calc; + public MathContext calc; public boolean autoscroll; public int scrollX = 0; public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto @@ -48,7 +48,7 @@ public class MathInputScreen extends Screen { super(); canBeInHistory = true; - calc = new Calculator(); + calc = new MathContext(); } @Override @@ -204,7 +204,7 @@ public class MathInputScreen extends Screen { } } final int y = padding + 20 + padding + fontBig.getCharacterHeight() + 1 + topSpacing; - fnc.draw(padding + scrollA, y); + fnc.draw(padding + scrollA, y, null, null); if (tooLong) { DisplayManager.renderer.glColor(DisplayManager.renderer.glGetClearColor()); DisplayManager.renderer.glFillColor(Main.screenSize[0] - 16 - 2, y, fnc.getHeight(), Main.screenSize[0]); @@ -221,7 +221,7 @@ public class MathInputScreen extends Screen { int bottomSpacing = 0; for (final Function f : calc.f2) { bottomSpacing += f.getHeight() + 2; - f.draw(DisplayManager.engine.getWidth() - 2 - f.getWidth(), DisplayManager.engine.getHeight() - bottomSpacing); + f.draw(DisplayManager.engine.getWidth() - 2 - f.getWidth(), DisplayManager.engine.getHeight() - bottomSpacing, null, null); } if (calc.resultsCount > 1 && calc.resultsCount != calc.f2.size()) { final String resultsCountText = calc.resultsCount + " total results".toUpperCase(); @@ -558,8 +558,8 @@ public class MathInputScreen extends Screen { } else { results.add(f); for (final Function itm : results) { - if (itm.isSolved() == false) { - final List dt = itm.solveOneStep(); + if (itm.isSimplified() == false) { + final List dt = itm.simplify(); partialResults.addAll(dt); } else { partialResults.add(itm); @@ -582,7 +582,7 @@ public class MathInputScreen extends Screen { results.addAll(hs); calc.f2 = results; for (final Function rf : calc.f2) { - rf.generateGraphics(); + rf.recomputeDimensions(); } } Utils.debug.println(calc.f2.toString()); @@ -625,7 +625,7 @@ public class MathInputScreen extends Screen { results.addAll(hs); calc.f2 = results; for (final Function rf : calc.f2) { - rf.generateGraphics(); + rf.recomputeDimensions(); } } } catch (final Exception ex) { @@ -730,12 +730,12 @@ public class MathInputScreen extends Screen { private ArrayList getKnownVariables(Function[] fncs) { final ArrayList res = new ArrayList<>(); for (final Function f : fncs) { - if (f instanceof FunctionTwoValues) { - res.addAll(getKnownVariables(new Function[] { ((FunctionTwoValues) f).getVariable1(), ((FunctionTwoValues) f).getVariable2() })); - } else if (f instanceof FunctionMultipleValues) { - res.addAll(getKnownVariables(((FunctionMultipleValues) f).getVariables())); - } else if (f instanceof AnteriorFunction) { - res.addAll(getKnownVariables(new Function[] { ((AnteriorFunction) f).getVariable() })); + if (f instanceof FunctionOperator) { + res.addAll(getKnownVariables(new Function[] { ((FunctionOperator) f).getParameter1(), ((FunctionOperator) f).getParameter2() })); + } else if (f instanceof FunctionDynamic) { + res.addAll(getKnownVariables(((FunctionDynamic) f).getParameters())); + } else if (f instanceof FunctionSingle) { + res.addAll(getKnownVariables(new Function[] { ((FunctionSingle) f).getParameter() })); } else if (f instanceof Variable) { if (((Variable)f).getType() == Variable.V_TYPE.KNOWN) { if (!res.contains(f)) { diff --git a/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java b/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java index a738423e..2f5e8899 100644 --- a/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java +++ b/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java @@ -4,7 +4,7 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Main; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; public class SolveEquationScreen extends Screen { diff --git a/src/org/warp/picalculator/math/Function.java b/src/org/warp/picalculator/math/Function.java new file mode 100644 index 00000000..f49cd2d5 --- /dev/null +++ b/src/org/warp/picalculator/math/Function.java @@ -0,0 +1,56 @@ +package org.warp.picalculator.math; + +import java.util.List; + +import org.warp.picalculator.Error; + +public interface Function { + + /** + * Returns this function and its children in a string form. + * @return This function and its children in a string form. + */ + @Override + public String toString(); + + @Override + public boolean equals(Object o); + + /** + * Deep clone this function. + * @return A clone of this function. + */ + public Function clone(); + + /** + * Generic method to change a parameter in a known position. + * @param index parameter index. + * @param var parameter. + * @return A new instance of this function. + */ + public Function setParameter(int index, Function var) throws IndexOutOfBoundsException; + + /** + * Generic method to retrieve a parameter in a known position. + * @param index parameter index. + * @return The requested parameter. + */ + public Function getParameter(int index) throws IndexOutOfBoundsException; + + /** + * Retrieve the current Math Context used by this function + * @return Calculator mathContext + */ + public MathContext getMathContext(); + + /** + * Simplify the current function or it's children + */ + public List simplify() throws Error; + + /** + * The current simplification status of this function and it's childrens + * @return boolean + */ + public boolean isSimplified(); +} diff --git a/src/org/warp/picalculator/math/FunctionDynamic.java b/src/org/warp/picalculator/math/FunctionDynamic.java new file mode 100644 index 00000000..b4c8f51d --- /dev/null +++ b/src/org/warp/picalculator/math/FunctionDynamic.java @@ -0,0 +1,165 @@ +package org.warp.picalculator.math; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.warp.picalculator.Error; +import org.warp.picalculator.Utils; + +import com.rits.cloning.Cloner; + +public abstract class FunctionDynamic implements Function { + public FunctionDynamic(MathContext root) { + this.root = root; + functions = new Function[] {}; + } + + public FunctionDynamic(Function[] values) { + if (values.length > 0) { + root = values[0].getMathContext(); + } else { + throw new NullPointerException("Nessun elemento nell'array. Impossibile ricavare il nodo root"); + } + functions = values; + } + + public FunctionDynamic(MathContext root, Function[] values) { + this.root = root; + functions = values; + } + + protected final MathContext root; + protected Function[] functions; + + public Function[] getParameters() { + return Arrays.copyOf(functions, functions.length); + } + + public FunctionDynamic setParameters(final List value) { + FunctionDynamic f = this.clone(); + final int vsize = value.size(); + final Function[] tmp = new Function[vsize]; + for (int i = 0; i < vsize; i++) { + tmp[i] = value.get(i); + } + f.functions = tmp; + return f; + } + + public FunctionDynamic setParameters(final Function[] value) { + FunctionDynamic f = this.clone(); + f.functions = value; + return f; + } + + @Override + public Function getParameter(int index) { + return functions[index]; + } + + @Override + public FunctionDynamic setParameter(int index, Function value) { + FunctionDynamic f = this.clone(); + f.functions[index] = value; + return f; + } + + public FunctionDynamic appendParameter(Function value) { + FunctionDynamic f = this.clone(); + f.functions = Arrays.copyOf(f.functions, f.functions.length + 1); + f.functions[f.functions.length - 1] = value; + return f; + } + + /** + * Retrieve the current number of parameters. + * @return The number of parameters. + */ + public int getParametersLength() { + return functions.length; + } + + public FunctionDynamic setParametersLength(int length) { + FunctionDynamic f = this.clone(); + f.functions = Arrays.copyOf(functions, length); + return f; + } + + @Override + public boolean isSimplified() { + for (final Function variable : functions) { + if (variable.isSimplified() == false) { + return false; + } + } + return !isSolvable(); + } + + /** + * The current simplification status of this function, assuming that its children are already simplified. + * @return true if this function can be solved, otherwise false. + */ + protected abstract boolean isSolvable(); + + @Override + public final ArrayList simplify() throws Error { + boolean solved = true; + Function[] fncs = getParameters(); + for (Function f : fncs) { + if (f.isSimplified() == false) { + solved = false; + break; + } + } + ArrayList result = solved ? solve() : null; + + if (result == null || result.isEmpty()) { + result = new ArrayList<>(); + + final ArrayList> ln = new ArrayList<>(); + for (int i = 0; i < fncs.length; i++) { + ArrayList l = new ArrayList<>(); + if (fncs[i].isSimplified()) { + l.add(fncs[i]); + } else { + l.addAll(fncs[i].simplify()); + } + ln.add(l); + } + + final Function[][] results = Utils.joinFunctionsResults(ln); + + for (final Function[] f : results) { + result.add(this.setParameters(f)); + } + } + + return result; + } + + /** + * Solves only this function, assuming that its children are already simplified and it can be solved. + * @return The solved function. + * @throws Error Errors during computation, like a/0 or similar. + */ + protected abstract ArrayList solve() throws Error; + + @Override + public MathContext getMathContext() { + return root; + } + + @Override + public abstract FunctionDynamic clone(); + + @Override + public int hashCode() { + return functions.hashCode() + 883 * super.hashCode(); + } + + @Override + public boolean equals(Object o) { + return false; + } +} diff --git a/src/org/warp/picalculator/math/FunctionOperator.java b/src/org/warp/picalculator/math/FunctionOperator.java new file mode 100644 index 00000000..aff12093 --- /dev/null +++ b/src/org/warp/picalculator/math/FunctionOperator.java @@ -0,0 +1,164 @@ +package org.warp.picalculator.math; + +import java.util.ArrayList; + +import org.warp.picalculator.Error; +import org.warp.picalculator.Utils; + +public abstract class FunctionOperator implements Function { + + /** + * Create a new instance of FunctionOperator. The Math Context will be the same of value1's. + * @throws NullPointerException when value1 is null. + * @param value1 The parameter of this function. + * @param value2 The parameter of this function. + */ + public FunctionOperator(Function value1, Function value2) throws NullPointerException { + this.mathContext = value1.getMathContext(); + parameter1 = value1; + parameter2 = value2; + } + + /** + * Create a new instance of FunctionOperator. + * @param value1 The parameter of this function. + * @param value2 The parameter of this function. + */ + public FunctionOperator(MathContext mc, Function value1, Function value2) { + this.mathContext = mc; + parameter1 = value1; + parameter2 = value2; + } + + protected final MathContext mathContext; + + protected Function parameter1 = null; + protected Function parameter2 = null; + + /** + * + * @return First parameter. + */ + public Function getParameter1() { + return parameter1; + } + + /** + * + * @return Second parameter. + */ + public Function getParameter2() { + return parameter2; + } + + /** + * + * @param var First parameter. + * @return A new instance of this function. + */ + public FunctionOperator setParameter1(Function var) { + FunctionOperator s = this.clone(); + s.parameter1 = var; + return s; + } + + /** + * + * @param var Second parameter. + * @return A new instance of this function. + */ + public FunctionOperator setParameter2(Function var) { + FunctionOperator s = this.clone(); + s.parameter2 = var; + return s; + } + + @Override + public FunctionOperator setParameter(int index, Function var) throws IndexOutOfBoundsException { + switch(index) { + case 0: + return this.setParameter1(var); + case 1: + return this.setParameter2(var); + default: + throw new IndexOutOfBoundsException(); + } + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + switch(index) { + case 0: + return this.getParameter1(); + case 1: + return this.getParameter2(); + default: + throw new IndexOutOfBoundsException(); + } + } + + @Override + public MathContext getMathContext() { + return mathContext; + } + + @Override + public boolean isSimplified() { + return (parameter1.isSimplified() & parameter2.isSimplified()) ? !isSolvable() : false; + } + + /** + * The current simplification status of this function, assuming that its children are already simplified. + * @return true if this function can be solved, otherwise false. + */ + protected abstract boolean isSolvable(); + + @Override + public final ArrayList simplify() throws Error { + final boolean solved = parameter1.isSimplified() & parameter2.isSimplified(); + ArrayList result = solved ? solve() : null;; + + if (result == null || result.isEmpty()) { + result = new ArrayList<>(); + + final ArrayList l1 = new ArrayList<>(); + final ArrayList l2 = new ArrayList<>(); + if (parameter1.isSimplified()) { + l1.add(parameter1); + } else { + l1.addAll(parameter1.simplify()); + } + if (parameter2.isSimplified()) { + l2.add(parameter2); + } else { + l2.addAll(parameter2.simplify()); + } + + final Function[][] results = Utils.joinFunctionsResults(l1, l2); + + for (final Function[] f : results) { + result.add(this.setParameter1(f[0]).setParameter2(f[1])); + } + } + + return result; + } + + /** + * Solves only this function, assuming that its children are already simplified and it can be solved. + * @return The solved function. + * @throws Error Errors during computation, like a/0 or similar. + */ + protected abstract ArrayList solve() throws Error; + + @Override + public abstract FunctionOperator clone(); + + @Override + public int hashCode() { + return parameter1.hashCode() + 7 * parameter2.hashCode() + 883 * super.hashCode(); + } + + @Override + public abstract boolean equals(Object o); +} diff --git a/src/org/warp/picalculator/math/FunctionSingle.java b/src/org/warp/picalculator/math/FunctionSingle.java new file mode 100644 index 00000000..e9ec6d52 --- /dev/null +++ b/src/org/warp/picalculator/math/FunctionSingle.java @@ -0,0 +1,130 @@ +package org.warp.picalculator.math; + +import java.util.ArrayList; + +import org.warp.picalculator.Error; + +public abstract class FunctionSingle implements Function { + + /** + * Create a new instance of FunctionSingle. The Math Context will be the same of value's. + * @throws NullPointerException when value is null. + * @param value The parameter of this function. + */ + public FunctionSingle(Function value) throws NullPointerException { + mathContext = value.getMathContext(); + parameter = value; + } + + /** + * Create a new instance of FunctionSingle. + * @param mathContext Math Context + * @param value The parameter of this function. + */ + public FunctionSingle(MathContext mathContext, Function value) { + this.mathContext = mathContext; + parameter = value; + } + + private final MathContext mathContext; + + /** + * Function parameter.
+ * MUST NOT BE MODIFIED IF ALREADY SET UP. + */ + protected Function parameter; + + /** + * + * @return Parameter. + */ + public Function getParameter() { + return parameter; + } + /** + * + * @param var Parameter. + * @return A new instance of this function. + */ + public FunctionSingle setParameter(Function value) { + FunctionSingle s = this.clone(); + s.parameter = value; + return s; + } + + @Override + public FunctionSingle setParameter(int index, Function var) throws IndexOutOfBoundsException { + if (index == 0) { + return this.setParameter(var); + } else { + throw new IndexOutOfBoundsException(); + } + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + if (index == 0) { + return this.getParameter(); + } else { + throw new IndexOutOfBoundsException(); + } + } + + @Override + public MathContext getMathContext() { + return mathContext; + } + + @Override + public final ArrayList simplify() throws Error { + final boolean simplified = parameter.isSimplified(); + ArrayList result = simplified ? solve() : null; + + if (result == null || result.isEmpty()) { + result = new ArrayList<>(); + + final ArrayList l1 = new ArrayList<>(); + if (parameter.isSimplified()) { + l1.add(parameter); + } else { + l1.addAll(parameter.simplify()); + } + + for (final Function f : l1) { + result.add(this.setParameter(f)); + } + } + + return result; + } + + + /** + * Solves only this function, assuming that its children are already simplified and it can be solved. + * @return The solved function. + * @throws Error Errors during computation, like a/0 or similar. + */ + protected abstract ArrayList solve() throws Error; + + @Override + public boolean isSimplified() { + return parameter.isSimplified() ? !isSolvable() : false; + } + + /** + * The current simplification status of this function, assuming that its children are already simplified. + * @return true if this function can be solved, otherwise false. + */ + protected abstract boolean isSolvable(); + + @Override + public abstract FunctionSingle clone(); + + @Override + public int hashCode() { + return parameter.hashCode() + 883 * super.hashCode(); + } + + @Override + public abstract boolean equals(Object o); +} diff --git a/src/org/warp/picalculator/math/Calculator.java b/src/org/warp/picalculator/math/MathContext.java similarity index 79% rename from src/org/warp/picalculator/math/Calculator.java rename to src/org/warp/picalculator/math/MathContext.java index 1dfaa585..eb335446 100644 --- a/src/org/warp/picalculator/math/Calculator.java +++ b/src/org/warp/picalculator/math/MathContext.java @@ -7,13 +7,12 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Errors; import org.warp.picalculator.Utils; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Variable.VariableValue; import org.warp.picalculator.math.functions.equations.Equation; import org.warp.picalculator.math.functions.equations.EquationsSystem; -public class Calculator { +public class MathContext { public AngleMode angleMode = AngleMode.DEG; public boolean exactMode = false; @@ -22,7 +21,7 @@ public class Calculator { public ArrayList variablesValues; public int resultsCount; - public Calculator() { + public MathContext() { f = new ArrayList<>(); f2 = new ArrayList<>(); variablesValues = new ArrayList<>(); @@ -37,7 +36,7 @@ public class Calculator { final String[] parts = string.substring(1).split("\\{"); final EquationsSystem s = new EquationsSystem(this); for (final String part : parts) { - s.addFunctionToEnd(parseEquationString(part)); + s.appendParameter(parseEquationString(part)); } return s; } else if (string.contains("=")) { @@ -50,15 +49,9 @@ public class Calculator { public Function parseEquationString(String string) throws Error { final String[] parts = string.split("="); if (parts.length == 1) { - final Equation e = new Equation(this, null, null); - e.setVariable1(new Expression(this, parts[0])); - e.setVariable2(new Number(this, BigInteger.ZERO)); - return e; + return new Equation(this, new Expression(this, parts[0]), new Number(this, BigInteger.ZERO)); } else if (parts.length == 2) { - final Equation e = new Equation(this, null, null); - e.setVariable1(new Expression(this, parts[0])); - e.setVariable2(new Expression(this, parts[1])); - return e; + return new Equation(this, new Expression(this, parts[0]), new Expression(this, parts[1])); } else { throw new Error(Errors.SYNTAX_ERROR); } @@ -74,11 +67,11 @@ public class Calculator { results.add(f); while (Utils.allSolved(results) == false) { for (final Function itm : results) { - if (itm.isSolved() == false) { + if (itm.isSimplified() == false) { final long t1 = System.currentTimeMillis(); - final List dt = itm.solveOneStep(); + final List dt = itm.simplify(); final long t2 = System.currentTimeMillis(); - if (t2 - t1 >= 3000) { + if (!Utils.debugOn & (t2 - t1 >= 3000)) { throw new Error(Errors.TIMEOUT); } partialResults.addAll(dt); @@ -117,13 +110,6 @@ public class Calculator { } } f = fncs; - for (final Function f : f) { - try { - f.generateGraphics(); - } catch (final NullPointerException ex) { - throw new Error(Errors.SYNTAX_ERROR); - } - } } /*public void solve(EquationScreen equationScreen, char letter) throws Error { diff --git a/src/org/warp/picalculator/math/functions/AnteriorFunction.java b/src/org/warp/picalculator/math/functions/AnteriorFunction.java deleted file mode 100644 index fba6b833..00000000 --- a/src/org/warp/picalculator/math/functions/AnteriorFunction.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.warp.picalculator.math.functions; - -import java.util.ArrayList; - -import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; - -import com.rits.cloning.Cloner; - -public abstract class AnteriorFunction implements Function { - public AnteriorFunction(Function value) { - root = value.getRoot(); - variable = value; - } - - public AnteriorFunction(Calculator root, Function value) { - this.root = root; - variable = value; - } - - protected abstract Function NewInstance(Calculator root, Function value); - - protected final Calculator root; - protected Function variable; - protected int width; - protected int height; - protected int line; - protected boolean small; - - public Function getVariable() { - return variable; - } - - public void setVariable(Function value) { - variable = value; - } - - @Override - public Calculator getRoot() { - return root; - } - - @Override - public abstract String getSymbol(); - - @Override - public final ArrayList solveOneStep() throws Error { - final boolean solved = variable.isSolved(); - ArrayList result = solved ? solve() : null; - - if (result == null || result.isEmpty()) { - result = new ArrayList<>(); - - final ArrayList l1 = new ArrayList<>(); - if (variable.isSolved()) { - l1.add(variable); - } else { - l1.addAll(variable.solveOneStep()); - } - - for (final Function f : l1) { - result.add(NewInstance(root, f)); - } - } - - return result; - } - - protected abstract ArrayList solve() throws Error; - - @Override - public boolean isSolved() { - return variable.isSolved() ? !isSolvable() : false; - } - - protected abstract boolean isSolvable(); - - @Override - public void generateGraphics() { - variable.setSmall(small); - variable.generateGraphics(); - - width = Utils.getFont(small).getStringWidth(getSymbol()) + 1 + getVariable().getWidth(); - height = variable.getHeight(); - line = variable.getLine(); - } - - @Override - public void draw(int x, int y) { - final float h1 = getVariable().getHeight(); - final int wsegno = Utils.getFont(small).getStringWidth(getSymbol()); - final float hsegno = Utils.getFontHeight(small); - final float maxh = getHeight(); - Utils.getFont(small).use(DisplayManager.engine); - - DisplayManager.renderer.glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), getSymbol()); - getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2)); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - - @Override - public String toString() { -// try { -// return solve().toString(); - String val1 = "null"; - if (variable != null) { - val1 = variable.toString(); - } - return getSymbol() + val1; -// } catch (Error e) { -// return e.id.toString(); -// } - } - - @Override - public AnteriorFunction clone() { - final Cloner cloner = new Cloner(); - return cloner.deepClone(this); - } - - @Override - public void setSmall(boolean small) { - this.small = small; - } - - @Override - public int hashCode() { - return variable.hashCode() + 883 * getSymbol().hashCode(); - } - - @Override - public abstract boolean equals(Object o); -} diff --git a/src/org/warp/picalculator/math/functions/Division.java b/src/org/warp/picalculator/math/functions/Division.java index 3a18bcab..549f41ff 100644 --- a/src/org/warp/picalculator/math/functions/Division.java +++ b/src/org/warp/picalculator/math/functions/Division.java @@ -6,7 +6,10 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.gui.math.GraphicalElement; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.FractionsRule1; import org.warp.picalculator.math.rules.FractionsRule11; @@ -15,24 +18,16 @@ import org.warp.picalculator.math.rules.FractionsRule2; import org.warp.picalculator.math.rules.FractionsRule3; import org.warp.picalculator.math.rules.UndefinedRule2; -public class Division extends FunctionTwoValues { +public class Division extends FunctionOperator { - public Division(Calculator root, Function value1, Function value2) { + public Division(MathContext root, Function value1, Function value2) { super(root, value1, value2); } - @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { - return new Division(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.DIVISION; - } - @Override protected boolean isSolvable() { + Function variable1 = getParameter1(); + Function variable2 = getParameter2(); if (FractionsRule1.compare(this)) { return true; } @@ -52,7 +47,7 @@ public class Division extends FunctionTwoValues { return true; } if (variable1 instanceof Number && variable2 instanceof Number) { - if (root.exactMode) { + if (getMathContext().exactMode) { try { return ((Number)variable1).divide((Number)variable2).isInteger(); } catch (Error e) { @@ -67,6 +62,8 @@ public class Division extends FunctionTwoValues { @Override public ArrayList solve() throws Error { + Function variable1 = getParameter1(); + Function variable2 = getParameter2(); ArrayList result = new ArrayList<>(); if (FractionsRule1.compare(this)) { result = FractionsRule1.execute(this); @@ -85,148 +82,18 @@ public class Division extends FunctionTwoValues { } return result; } - - public boolean hasMinus() { - final String numerator = variable1.toString(); - if (numerator.startsWith("-")) { - return true; - } - return false; - } - - public void draw(int x, int y, boolean small, boolean drawMinus) { - final boolean beforedrawminus = this.drawMinus; - this.drawMinus = drawMinus; - draw(x, y); - this.drawMinus = beforedrawminus; - } - - private boolean drawMinus = true; - - @Override - public void generateGraphics() { - variable1.generateGraphics(); - - variable2.generateGraphics(); - - width = calcWidth(); - height = calcHeight(); - line = variable1.getHeight() + 1; - } - - @Override - public void draw(int x, int y) { -// glColor3f(255, 127-50+new Random().nextInt(50), 0); -// glFillRect(x,y,width,height); -// glColor3f(0, 0, 0); - - final Object var1 = variable1; - final Object var2 = variable2; - boolean minus = false; - int minusw = 0; - int minush = 0; - String numerator = ((Function) var1).toString(); - if (numerator.startsWith("-") && ((Function) var1) instanceof Number) { - minus = true; - numerator = numerator.substring(1); - } - int w1 = 0; - int h1 = 0; - Utils.getFont(small).use(DisplayManager.engine); - if (minus) { - w1 = Utils.getFont(small).getStringWidth(numerator); - h1 = Utils.getFont(small).getCharacterHeight(); - } else { - w1 = ((Function) var1).getWidth(); - h1 = ((Function) var1).getHeight(); - } - final int w2 = ((Function) var2).getWidth(); - int maxw; - if (w1 > w2) { - maxw = 1 + w1; - } else { - maxw = 1 + w2; - } - if (minus && drawMinus) { - minusw = Utils.getFont(small).getCharacterWidth() /* Width of minus */ + 1; - minush = Utils.getFont(small).getCharacterHeight(); - DisplayManager.renderer.glDrawStringLeft(x + 1, y + h1 + 1 + 1 - (minush / 2), "-"); - DisplayManager.renderer.glDrawStringLeft((int) (x + 1 + minusw + 1 + (maxw - w1) / 2d), y, numerator); - } else { - ((Function) var1).draw((int) (x + 1 + minusw + (maxw - w1) / 2d), y); - } - ((Function) var2).draw((int) (x + 1 + minusw + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1); - DisplayManager.renderer.glFillColor(x + 1 + minusw, y + h1 + 1, maxw, 1); - } - - @Override - public int getHeight() { - return height; - } - - @Override - protected int calcHeight() { - - boolean minus = false; - String numerator = variable1.toString(); - if (numerator.startsWith("-") && variable1 instanceof Number) { - minus = true; - numerator = numerator.substring(1); - } - int h1 = 0; - if (minus) { - h1 = Utils.getFontHeight(small); - } else { - h1 = variable1.getHeight(); - } - final int h2 = variable2.getHeight(); - return h1 + 3 + h2; - } - - @Override - public int getLine() { - return line; - } - - @Override - public int getWidth() { - return width; - } - - @Override - protected int calcWidth() { - boolean minus = false; - String numerator = variable1.toString(); - if (numerator.startsWith("-") && variable1 instanceof Number) { - minus = true; - numerator = numerator.substring(1); - } - int w1 = 0; - if (minus) { - w1 = Utils.getFont(small).getStringWidth(numerator); - } else { - w1 = variable1.getWidth(); - } - final int w2 = variable2.getWidth(); - int maxw = 0; - if (w1 > w2) { - maxw = w1 + 1; - } else { - maxw = w2 + 1; - } - if (minus && drawMinus) { - return 1 + Utils.getFont(small).getCharacterWidth() /* Width of minus */ + 1 + maxw; - } else { - return 1 + maxw; - } - } - + @Override public boolean equals(Object o) { if (o instanceof Division) { - final FunctionTwoValues f = (FunctionTwoValues) o; - return variable1.equals(f.variable1) && variable2.equals(f.variable2); + final FunctionOperator f = (FunctionOperator) o; + return getParameter1().equals(f.getParameter1()) && getParameter2().equals(f.getParameter2()); } return false; } + + @Override + public FunctionOperator clone() { + return new Division(this.getMathContext(), this.getParameter1(), this.getParameter2()); + } } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/EmptyNumber.java b/src/org/warp/picalculator/math/functions/EmptyNumber.java index fb499cd3..f9ab9ce7 100644 --- a/src/org/warp/picalculator/math/functions/EmptyNumber.java +++ b/src/org/warp/picalculator/math/functions/EmptyNumber.java @@ -1,76 +1,58 @@ package org.warp.picalculator.math.functions; +import java.util.ArrayList; import java.util.List; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; public class EmptyNumber implements Function { - public EmptyNumber(Calculator root) { + public EmptyNumber(MathContext root) { this.root = root; } - private final Calculator root; + private final MathContext root; + @Override - public String getSymbol() { - return " "; - } - - @Override - public List solveOneStep() throws Error { + public ArrayList simplify() throws Error { // TODO Auto-generated method stub return null; } @Override - public boolean isSolved() { + public boolean isSimplified() { return false; } @Override - public void generateGraphics() { - - } - - @Override - public void draw(int x, int y) { - DisplayManager.renderer.glDrawStringLeft(x, y, "␀"); - } - - @Override - public int getWidth() { - return Utils.getFont(small).getStringWidth("␀"); - } - - @Override - public int getHeight() { - return Utils.getFont(small).getCharacterHeight(); - } - - @Override - public int getLine() { - return Utils.getFont(small).getCharacterHeight() / 2; - } - - @Override - public Calculator getRoot() { + public MathContext getMathContext() { return root; } - - private boolean small = false; - - @Override - public void setSmall(boolean small) { - this.small = small; - } - + @Override public boolean equals(Object o) { return o instanceof EmptyNumber; } + + @Override + public Function clone() { + return new EmptyNumber(root); + } + + @Override + public Function setParameter(int index, Function var) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + } diff --git a/src/org/warp/picalculator/math/functions/Expression.java b/src/org/warp/picalculator/math/functions/Expression.java index e615cd4d..b82fb8f7 100644 --- a/src/org/warp/picalculator/math/functions/Expression.java +++ b/src/org/warp/picalculator/math/functions/Expression.java @@ -13,7 +13,11 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Errors; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionDynamic; +import org.warp.picalculator.math.FunctionSingle; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.functions.trigonometry.ArcCosine; import org.warp.picalculator.math.functions.trigonometry.ArcSine; @@ -22,27 +26,27 @@ import org.warp.picalculator.math.functions.trigonometry.Cosine; import org.warp.picalculator.math.functions.trigonometry.Sine; import org.warp.picalculator.math.functions.trigonometry.Tangent; -public class Expression extends FunctionMultipleValues { +public class Expression extends FunctionDynamic { - public Expression(Calculator root) { + public Expression(MathContext root) { super(root); } - public Expression(Calculator root, Function[] values) { + public Expression(MathContext root, Function[] values) { super(root, values); } - public Expression(Calculator root, Function value) { + public Expression(MathContext root, Function value) { super(root, new Function[]{value}); } private boolean initialParenthesis = false; - public Expression(Calculator root, String string) throws Error { + public Expression(MathContext root, String string) throws Error { this(root, string, "", true); } - public Expression(Calculator root, String string, String debugSpaces, boolean initialParenthesis) throws Error { + public Expression(MathContext root, String string, String debugSpaces, boolean initialParenthesis) throws Error { super(root); this.initialParenthesis = initialParenthesis; boolean isNumber = false; @@ -65,7 +69,7 @@ public class Expression extends FunctionMultipleValues { // If the expression is already a number: // Se l'espressione è già un numero: final Number t = new Number(root, string); - setVariables(new Function[] { t }); + functions = new Function[] { t }; Utils.debug.println(debugSpaces + "•Result:" + t.toString()); } else { // Else prepare the expression: @@ -215,8 +219,8 @@ public class Expression extends FunctionMultipleValues { debugSpaces += " "; // Convert the expression to a list of objects - final Expression imputRawParenthesis = new Expression(root); - imputRawParenthesis.setVariables(new Function[] {}); + Expression imputRawParenthesis = new Expression(root); + imputRawParenthesis = (Expression) imputRawParenthesis.setParameters(new Function[] {}); String tmp = ""; final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax()); for (int i = 0; i < processExpression.length(); i++) { @@ -322,30 +326,30 @@ public class Expression extends FunctionMultipleValues { if (f instanceof Expression) { tmp = ""; } else if (f instanceof Variable) { - if (imputRawParenthesis.getVariablesLength() == 0) { + if (imputRawParenthesis.getParametersLength() == 0) { if (tmp.length() > 0) { - imputRawParenthesis.addFunctionToEnd(new Number(root, tmp)); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp)); Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp); - imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null)); - Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol()); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Multiplication(root, null, null)); + Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getClass().getSimpleName()); } } else { - final Function precedentFunction = imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1); + final Function precedentFunction = imputRawParenthesis.getParameter(imputRawParenthesis.getParametersLength() - 1); if (tmp.length() > 0) { if (precedentFunction instanceof Number || precedentFunction instanceof Variable) { - imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null)); - Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol()); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Multiplication(root, null, null)); + Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getClass().getSimpleName()); } if (tmp.equals("-")) { - imputRawParenthesis.addFunctionToEnd(new Subtraction(root, null, null)); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Subtraction(root, null, null)); } else { - imputRawParenthesis.addFunctionToEnd(new Number(root, tmp)); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp)); Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp); } } if (tmp.length() > 0 || (precedentFunction instanceof Number || precedentFunction instanceof Variable)) { - imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null)); - Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol()); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Multiplication(root, null, null)); + Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getClass().getSimpleName()); } } } else { @@ -355,12 +359,12 @@ public class Expression extends FunctionMultipleValues { tmp = "-1"; } } - imputRawParenthesis.addFunctionToEnd(new Number(root, tmp)); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp)); Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp); } } - imputRawParenthesis.addFunctionToEnd(f); - Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getSymbol() + (f instanceof Number ? " (number)" : " (variable)")); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(f); + Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getClass().getSimpleName() + (f instanceof Number ? " (number)" : " (variable)")); tmp = ""; } else { try { @@ -378,7 +382,7 @@ public class Expression extends FunctionMultipleValues { if (tmp.length() > 0) { Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp); try { - imputRawParenthesis.addFunctionToEnd(new Number(root, tmp)); + imputRawParenthesis = (Expression) imputRawParenthesis.appendParameter(new Number(root, tmp)); } catch (final NumberFormatException ex) { throw new Error(Errors.SYNTAX_ERROR); } @@ -394,13 +398,13 @@ public class Expression extends FunctionMultipleValues { // Fine suddivisione di insieme Utils.debug.println(debugSpaces + "•Removing useless parentheses"); - for (int i = 0; i < imputRawParenthesis.functions.length; i++) { - if (imputRawParenthesis.functions[i] instanceof Expression) { - final Expression par = (Expression) imputRawParenthesis.functions[i]; - if (par.functions.length == 1) { - final Function subFunz = par.functions[0]; + for (int i = 0; i < imputRawParenthesis.getParametersLength(); i++) { + if (imputRawParenthesis.getParameter(i) instanceof Expression) { + final Expression par = (Expression) imputRawParenthesis.getParameter(i); + if (par.getParametersLength() == 1) { + final Function subFunz = par.getParameter(0); if (subFunz instanceof Expression || subFunz instanceof Number || subFunz instanceof Variable) { - imputRawParenthesis.functions[i] = subFunz; + imputRawParenthesis = (Expression) imputRawParenthesis.setParameter(i, subFunz); Utils.debug.println(debugSpaces + " •Useless parentheses removed"); } } @@ -410,7 +414,7 @@ public class Expression extends FunctionMultipleValues { // Inizia l'affinazione dell'espressione Utils.debug.println(debugSpaces + "•Pushing classes..."); - final Function[] oldFunctionsArray = imputRawParenthesis.getVariables(); + final Function[] oldFunctionsArray = imputRawParenthesis.getParameters(); final ArrayList oldFunctionsList = new ArrayList<>(); for (int i = 0; i < oldFunctionsArray.length; i++) { Function funzione = oldFunctionsArray[i]; @@ -458,15 +462,15 @@ public class Expression extends FunctionMultipleValues { } Utils.debug.println(debugSpaces + " •Phase: " + step); while (i < oldFunctionsList.size() && change == false && oldFunctionsList.size() > 1) { - final Function funzioneTMP = oldFunctionsList.get(i); - if (funzioneTMP instanceof FunctionTwoValues) { + Function funzioneTMP = oldFunctionsList.get(i); + if (funzioneTMP instanceof FunctionOperator) { if (step != "SN Functions") { - if ((step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction || funzioneTMP instanceof Subtraction) == true && ((funzioneTMP instanceof AnteriorFunction && ((AnteriorFunction) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValues && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunction) && !(funzioneTMP instanceof FunctionTwoValues)))) || (step.equals("multiplications") && ((funzioneTMP instanceof Multiplication) || (funzioneTMP instanceof Division)) && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (step == "NSN Functions" && (funzioneTMP instanceof Sum) == false && (funzioneTMP instanceof SumSubtraction) == false && (funzioneTMP instanceof Subtraction) == false && (funzioneTMP instanceof Multiplication) == false && (funzioneTMP instanceof Division) == false && ((funzioneTMP instanceof AnteriorFunction && ((AnteriorFunction) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValues && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunction) && !(funzioneTMP instanceof FunctionTwoValues))))) { + if ((step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction || funzioneTMP instanceof Subtraction) == true && ((funzioneTMP instanceof FunctionSingle && ((FunctionSingle) funzioneTMP).getParameter() == null) || (funzioneTMP instanceof FunctionOperator && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (!(funzioneTMP instanceof FunctionSingle) && !(funzioneTMP instanceof FunctionOperator)))) || (step.equals("multiplications") && ((funzioneTMP instanceof Multiplication) || (funzioneTMP instanceof Division)) && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (step == "NSN Functions" && (funzioneTMP instanceof Sum) == false && (funzioneTMP instanceof SumSubtraction) == false && (funzioneTMP instanceof Subtraction) == false && (funzioneTMP instanceof Multiplication) == false && (funzioneTMP instanceof Division) == false && ((funzioneTMP instanceof FunctionSingle && ((FunctionSingle) funzioneTMP).getParameter() == null) || (funzioneTMP instanceof FunctionOperator && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (!(funzioneTMP instanceof FunctionSingle) && !(funzioneTMP instanceof FunctionOperator))))) { change = true; if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) { - ((FunctionTwoValues) funzioneTMP).setVariable1(oldFunctionsList.get(i - 1)); - ((FunctionTwoValues) funzioneTMP).setVariable2(oldFunctionsList.get(i + 1)); + funzioneTMP = ((FunctionOperator) funzioneTMP).setParameter1(oldFunctionsList.get(i - 1)); + funzioneTMP = ((FunctionOperator) funzioneTMP).setParameter2(oldFunctionsList.get(i + 1)); oldFunctionsList.set(i, funzioneTMP); // è importante togliere prima gli elementi @@ -475,15 +479,15 @@ public class Expression extends FunctionMultipleValues { 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.getClass().getSimpleName()); try { - Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionTwoValues) funzioneTMP).getVariable1().toString()); + Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionOperator) funzioneTMP).getParameter1().toString()); } catch (final NullPointerException ex2) {} try { - Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionTwoValues) funzioneTMP).getVariable2().toString()); + Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionOperator) funzioneTMP).getParameter2().toString()); } catch (final NullPointerException ex2) {} try { - Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionTwoValues) funzioneTMP).toString()); + Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionOperator) funzioneTMP).toString()); } catch (final NullPointerException ex2) {} } else { @@ -491,15 +495,15 @@ public class Expression extends FunctionMultipleValues { } } } - } else if (funzioneTMP instanceof AnteriorFunction) { - if ((step == "SN Functions" && ((AnteriorFunction) funzioneTMP).variable == null)) { + } else if (funzioneTMP instanceof FunctionSingle) { + if ((step == "SN Functions" && ((FunctionSingle) funzioneTMP).getParameter() == null)) { if (i + 1 < oldFunctionsList.size()) { final Function nextFunc = oldFunctionsList.get(i + 1); - if (nextFunc instanceof AnteriorFunction && ((AnteriorFunction) nextFunc).variable == null) { + if (nextFunc instanceof FunctionSingle && ((FunctionSingle) nextFunc).getParameter() == null) { } else { change = true; - ((AnteriorFunction) funzioneTMP).setVariable(nextFunc); + funzioneTMP = ((FunctionSingle) funzioneTMP).setParameter(nextFunc); oldFunctionsList.set(i, funzioneTMP); // è importante togliere prima gli elementi in @@ -507,8 +511,8 @@ public class Expression extends FunctionMultipleValues { // scalano da destra a sinistra. oldFunctionsList.remove(i + 1); - Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol()); - final Function var = ((AnteriorFunction) funzioneTMP).getVariable(); + Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getClass().getSimpleName()); + final Function var = ((FunctionSingle) funzioneTMP).getParameter(); if (var == null) { Utils.debug.println(debugSpaces + " " + "var=null"); } else { @@ -533,9 +537,9 @@ public class Expression extends FunctionMultipleValues { } while (((oldFunctionsList.size() != before || step != "sums") && oldFunctionsList.size() > 1)); } if (oldFunctionsList.isEmpty()) { - setVariables(new Function[] { new Number(root, 0) }); + super.functions = new Function[] { new Number(root, 0) }; } else { - setVariables(oldFunctionsList); + super.functions = oldFunctionsList.toArray(new Function[oldFunctionsList.size()]); } dsl = debugSpaces.length(); @@ -550,18 +554,13 @@ public class Expression extends FunctionMultipleValues { } } - @Override - public String getSymbol() { - return "Parentesi"; - } - @Override protected boolean isSolvable() { - if (functions.length > 1) { + if (getParametersLength() > 1) { return true; - } else if (functions.length == 1) { - final Function f = functions[0]; - if (f.isSolved() == false) { + } else if (getParametersLength() == 1) { + final Function f = getParameter(0); + if (f.isSimplified() == false) { return true; } else { return !parenthesisNeeded(); @@ -571,14 +570,14 @@ public class Expression extends FunctionMultipleValues { } @Override - public List solveOneStep() throws Error { - final List ret = new ArrayList<>(); - if (functions.length == 1) { - if (functions[0].isSolved() || !parenthesisNeeded()) { - ret.add(functions[0]); + public ArrayList solve() throws Error { + final ArrayList ret = new ArrayList<>(); + if (getParametersLength() == 1) { + if (getParameter(0).isSimplified() || !parenthesisNeeded()) { + ret.add(getParameter(0)); return ret; } else { - final List l = functions[0].solveOneStep(); + final List l = getParameter(0).simplify(); for (final Function f : l) { if (f instanceof Number || f instanceof Variable) { ret.add(f); @@ -589,9 +588,9 @@ public class Expression extends FunctionMultipleValues { return ret; } } else { - for (final Function f : functions) { - if (f.isSolved() == false) { - final List partial = f.solveOneStep(); + for (final Function f : getParameters()) { + if (f.isSimplified() == false) { + final List partial = f.simplify(); for (final Function fnc : partial) { ret.add(new Expression(root, new Function[] { fnc })); } @@ -600,35 +599,23 @@ public class Expression extends FunctionMultipleValues { return ret; } } - - @Override - public void generateGraphics() { - for (final Function var : functions) { - var.setSmall(small); - var.generateGraphics(); - } - - width = calcWidth(); - height = calcHeight(); - line = calcLine(); - } - + public boolean parenthesisNeeded() { boolean parenthesisneeded = true; if (initialParenthesis) { parenthesisneeded = false; } else { - if (functions.length == 1) { - final Function f = functions[0]; + if (getParametersLength() == 1) { + final Function f = getParameter(0); if (f instanceof Number || f instanceof Variable || f instanceof Expression || f instanceof Division || f instanceof Joke || f instanceof Undefined || f instanceof Power || f instanceof Sine || f instanceof Cosine || f instanceof Tangent || f instanceof ArcSine || f instanceof ArcCosine || f instanceof ArcTangent || f instanceof RootSquare) { parenthesisneeded = false; } if (f instanceof Multiplication) { - if (((Multiplication) f).getVariable1() instanceof Number) { - parenthesisneeded = !(((Multiplication) f).getVariable2() instanceof Variable); - } else if (((Multiplication) f).getVariable2() instanceof Number) { - parenthesisneeded = !(((Multiplication) f).getVariable1() instanceof Variable); - } else if (((Multiplication) f).getVariable1() instanceof Variable || ((Multiplication) f).getVariable2() instanceof Variable) { + if (((Multiplication) f).getParameter1() instanceof Number) { + parenthesisneeded = !(((Multiplication) f).getParameter2() instanceof Variable); + } else if (((Multiplication) f).getParameter2() instanceof Number) { + parenthesisneeded = !(((Multiplication) f).getParameter1() instanceof Variable); + } else if (((Multiplication) f).getParameter1() instanceof Variable || ((Multiplication) f).getParameter2() instanceof Variable) { parenthesisneeded = false; } } @@ -636,137 +623,26 @@ public class Expression extends FunctionMultipleValues { } return parenthesisneeded; } - - @Override - public void draw(int x, int y) { - if (parenthesisNeeded() == false) { - functions[0].draw(x, y); - } else { - final float miny = y; - final float maxy = y + getHeight(); - final int h = getHeight(); - x += 1; - DisplayManager.renderer.glDrawLine(x, y + 2, x, y + 2); - DisplayManager.renderer.glDrawLine( x + 1, y + 1, x + 1, y + 1); - DisplayManager.renderer.glDrawLine( x + 2, y, x + 2, y); - - DisplayManager.renderer.glDrawLine(x, y + 2, x, y + h - 3); - - DisplayManager.renderer.glDrawLine(x, y + h - 3, x, y + h - 3); - DisplayManager.renderer.glDrawLine(x + 1, y + h - 2, x + 1, y + h - 2); - DisplayManager.renderer.glDrawLine(x + 2, y + h - 1, x + 2, y + h - 1); - x += 4; - for (final Function f : functions) { - final float fheight = f.getHeight(); - final float y2 = miny + ((maxy - miny) / 2 - fheight / 2); - f.draw(x, (int) y2); - x += f.getWidth(); - } - x += 2; - DisplayManager.renderer.glDrawLine(x, y, x, y); - DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + 1); - DisplayManager.renderer.glDrawLine(x + 2, y + 2, x + 2, y + 2); - - DisplayManager.renderer.glDrawLine(x + 2, y + 2, x + 2, y + h - 3); - - DisplayManager.renderer.glDrawLine(x, y + h - 1, x, y + h - 1); - DisplayManager.renderer.glDrawLine(x + 1, y + h - 2, x + 1, y + h - 2); - DisplayManager.renderer.glDrawLine(x + 2, y + h - 3, x + 2, y + h - 3); - x += 4; - } - } - - @Override - public int getWidth() { - return width; - } - - private int calcWidth() { - if (parenthesisNeeded() == false) { - return functions[0].getWidth(); - } else { - int w = 0; - for (final Function f : functions) { - w += f.getWidth(); - } - return 1 + 4 + w + 2 + 4; - } - } - - @Override - public int getHeight() { - return height; - } - - private int calcHeight() { - if (initialParenthesis || functions.length == 1) { - return functions[0].getHeight(); - } else { - Function tmin = null; - Function tmax = null; - for (final Function t : functions) { - if (tmin == null || t.getLine() >= tmin.getLine()) { - tmin = t; - } - if (tmax == null || t.getHeight() - t.getLine() >= tmax.getHeight() - tmax.getLine()) { - tmax = t; - } - } - if (tmin == null) { - return Utils.getFontHeight(small); - } - return tmin.getLine() + tmax.getHeight() - tmax.getLine(); - } - } - - @Override - public int getLine() { - return line; - } - - private int calcLine() { - if (initialParenthesis || functions.length == 1) { - return functions[0].getLine(); - } else { - Function tl = null; - for (final Function t : functions) { - if (tl == null || t.getLine() >= tl.getLine()) { - tl = t; - } - } - if (tl == null) { - return Utils.getFontHeight(small) / 2; - } - return tl.getLine(); - } - } - + @Override public String toString() { - String vars = "null"; - if (functions != null && functions.length > 0) { - if (functions.length == 1) { - if (functions[0] != null) { - vars = functions[0].toString(); - } - } else { - for (final Function variable : functions) { - if (variable != null) { - vars += ", " + variable.toString(); - } - } - vars = vars.substring(2); + String s = "("; + if (functions.length > 0) { + for (Function f : functions) { + s+=f.toString()+","; } + s = s.substring(0, s.length()-1); } - return "(" + vars + ")"; + s+=")"; + return s; } @Override public boolean equals(Object o) { if (o instanceof Expression) { final Expression f = (Expression) o; - final Function[] exprFuncs1 = functions; - final Function[] exprFuncs2 = f.functions; + final Function[] exprFuncs1 = getParameters(); + final Function[] exprFuncs2 = f.getParameters(); if (exprFuncs1.length == exprFuncs2.length) { for (int i = 0; i < exprFuncs1.length; i++) { if (exprFuncs1[i].equals(exprFuncs2[i]) == false) { @@ -775,13 +651,18 @@ public class Expression extends FunctionMultipleValues { } return true; } - } else if (o != null & getVariablesLength() == 1) { + } else if (o != null & getParametersLength() == 1) { final Function f = (Function) o; - return (functions[0].equals(f)); - } else if (o == null & getVariablesLength() == 0) { + return (getParameter(0).equals(f)); + } else if (o == null & getParametersLength() == 0) { return true; } return false; } + @Override + public Expression clone() { + return new Expression(root, functions); + } + } diff --git a/src/org/warp/picalculator/math/functions/Function.java b/src/org/warp/picalculator/math/functions/Function.java deleted file mode 100644 index 80542913..00000000 --- a/src/org/warp/picalculator/math/functions/Function.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.warp.picalculator.math.functions; - -import java.util.List; - -import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; - -public interface Function { - public String getSymbol(); - - public List solveOneStep() throws Error; - - public boolean isSolved(); - - public void generateGraphics() throws NullPointerException; - - public void draw(int x, int y); - - public int getWidth(); - - public int getHeight(); - - public int getLine(); - - public Calculator getRoot(); - - public void setSmall(boolean small); - - @Override - public int hashCode(); - - @Override - public boolean equals(Object o); -} diff --git a/src/org/warp/picalculator/math/functions/FunctionMultipleValues.java b/src/org/warp/picalculator/math/functions/FunctionMultipleValues.java deleted file mode 100644 index d61ab0e9..00000000 --- a/src/org/warp/picalculator/math/functions/FunctionMultipleValues.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.warp.picalculator.math.functions; - -import java.util.Arrays; -import java.util.List; - -import org.warp.picalculator.math.Calculator; - -import com.rits.cloning.Cloner; - -public abstract class FunctionMultipleValues implements Function { - public FunctionMultipleValues(Calculator root) { - this.root = root; - functions = new Function[] {}; - } - - public FunctionMultipleValues(Function[] values) { - if (values.length > 0) { - root = values[0].getRoot(); - } else { - throw new NullPointerException("Nessun elemento nell'array. Impossibile ricavare il nodo root"); - } - functions = values; - } - - public FunctionMultipleValues(Calculator root, Function[] values) { - this.root = root; - functions = values; - } - - protected final Calculator root; - protected Function[] functions; - protected int width; - protected int height; - protected int line; - protected boolean small; - - public Function[] getVariables() { - return functions; - } - - public void setVariables(final List value) { - final int vsize = value.size(); - final Function[] tmp = new Function[vsize]; - for (int i = 0; i < vsize; i++) { - tmp[i] = value.get(i); - } - functions = tmp; - } - - public void setVariables(final Function[] value) { - functions = value; - } - - public Function getVariable(int index) { - return functions[index]; - } - - public void setVariable(int index, Function value) { - functions[index] = value; - } - - public void addFunctionToEnd(Function value) { - final int index = functions.length; - setVariablesLength(index + 1); - functions[index] = value; - } - - public int getVariablesLength() { - return functions.length; - } - - public void setVariablesLength(int length) { - functions = Arrays.copyOf(functions, length); - } - - @Override - public abstract String getSymbol(); - - @Override - public boolean isSolved() { - for (final Function variable : functions) { - if (!variable.isSolved()) { - return false; - } - } - return !isSolvable(); - } - - protected abstract boolean isSolvable(); - - @Override - public Calculator getRoot() { - return root; - } - - @Override - public abstract void generateGraphics(); - - @Override - public String toString() { -// try { -// return solve().toString(); - return "TODO: fare una nuova alternativa a solve().toString()"; -// } catch (Error e) { -// return e.id.toString(); -// } - } - - @Override - public Function clone() { - final Cloner cloner = new Cloner(); - return cloner.deepClone(this); - } - - @Override - public void setSmall(boolean small) { - this.small = small; - } - - @Override - public int hashCode() { - return functions.hashCode() + 883 * getSymbol().hashCode(); - } - - @Override - public boolean equals(Object o) { - return false; - } -} diff --git a/src/org/warp/picalculator/math/functions/FunctionTwoValues.java b/src/org/warp/picalculator/math/functions/FunctionTwoValues.java deleted file mode 100644 index b4802162..00000000 --- a/src/org/warp/picalculator/math/functions/FunctionTwoValues.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.warp.picalculator.math.functions; - -import java.util.ArrayList; - -import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; - -import com.rits.cloning.Cloner; - -public abstract class FunctionTwoValues implements Function { - public FunctionTwoValues(Calculator root, Function value1, Function value2) { - this.root = root; - variable1 = value1; - variable2 = value2; - } - - protected abstract Function NewInstance(Calculator root, Function value1, Function value2); - - protected final Calculator root; - - protected Function variable1 = null; - protected Function variable2 = null; - protected int width; - protected int height; - protected int line; - protected boolean small; - - public Function getVariable1() { - return variable1; - } - - public void setVariable1(Function value) { - variable1 = value; - } - - @Override - public Calculator getRoot() { - return root; - } - - public Function getVariable2() { - return variable2; - } - - public void setVariable2(Function value) { - variable2 = value; - } - - @Override - public abstract String getSymbol(); - - @Override - public boolean isSolved() { - return (variable1.isSolved() & variable2.isSolved()) ? !isSolvable() : false; - } - - protected abstract boolean isSolvable(); - - @Override - public final ArrayList solveOneStep() throws Error { - final boolean solved = variable1.isSolved() & variable2.isSolved(); - ArrayList result = solved ? solve() : null;; - - if (result == null || result.isEmpty()) { - result = new ArrayList<>(); - - final ArrayList l1 = new ArrayList<>(); - final ArrayList l2 = new ArrayList<>(); - if (variable1.isSolved()) { - l1.add(variable1); - } else { - l1.addAll(variable1.solveOneStep()); - } - if (variable2.isSolved()) { - l2.add(variable2); - } else { - l2.addAll(variable2.solveOneStep()); - } - - final Function[][] results = Utils.joinFunctionsResults(l1, l2); - - for (final Function[] f : results) { - result.add(NewInstance(root, f[0], f[1])); - } - } - - return result; - } - - protected abstract ArrayList solve() throws Error; - - @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) { - final int ln = getLine(); - int dx = 0; - variable1.draw(dx + x, ln - variable1.getLine() + y); - dx += 1 + variable1.getWidth(); - if (drawSignum()) { - Utils.getFont(small).use(DisplayManager.engine); - DisplayManager.renderer.glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol()); - dx += Utils.getFont(small).getStringWidth(getSymbol()); - } - variable2.draw(dx + x, ln - variable2.getLine() + y); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - - @Override - public String toString() { - String val1 = "null"; - String val2 = "null"; - if (variable1 != null) { - val1 = variable1.toString(); - } - if (variable2 != null) { - val2 = variable2.toString(); - } - return val1 + getSymbol() + val2; - } - - @Override - public FunctionTwoValues clone() { - final Cloner cloner = new Cloner(); - return cloner.deepClone(this); - } - - public boolean drawSignum() { - return true; - } - - @Override - public void setSmall(boolean small) { - this.small = small; - } - - protected int calcWidth() { - return variable1.getWidth() + 1 + (drawSignum() ? Utils.getFont(small).getStringWidth(getSymbol()) : 0) + variable2.getWidth(); - } - - protected int calcHeight() { - - Function tmin = variable1; - Function tmax = variable1; - if (tmin == null || variable2.getLine() >= tmin.getLine()) { - tmin = variable2; - } - if (tmax == null || variable2.getHeight() - variable2.getLine() >= tmax.getHeight() - tmax.getLine()) { - tmax = variable2; - } - return tmin.getLine() + tmax.getHeight() - tmax.getLine(); - } - - protected int calcLine() { - Function tl = variable1; - if (tl == null || variable2.getLine() >= tl.getLine()) { - tl = variable2; - } - return tl.getLine(); - } - - @Override - public int hashCode() { - return variable1.hashCode() + 7 * variable2.hashCode() + 883 * getSymbol().hashCode(); - } - - @Override - public abstract boolean equals(Object o); -} diff --git a/src/org/warp/picalculator/math/functions/Joke.java b/src/org/warp/picalculator/math/functions/Joke.java index 13bf9b99..312125f3 100644 --- a/src/org/warp/picalculator/math/functions/Joke.java +++ b/src/org/warp/picalculator/math/functions/Joke.java @@ -1,5 +1,6 @@ package org.warp.picalculator.math.functions; +import java.util.ArrayList; import java.util.List; import org.warp.picalculator.Error; @@ -7,7 +8,8 @@ import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; public class Joke implements Function { @@ -17,78 +19,41 @@ public class Joke implements Function { private static final String[] jokes = new String[] { "♓", "TORNADO", "SHARKNADO" }; private static final int[] jokesFont = new int[] { 4, -1, -1 }; private final byte joke; - private final Calculator root; + private final MathContext root; - public Joke(Calculator root, byte joke) { + public Joke(MathContext root, byte joke) { this.root = root; this.joke = joke; } @Override - public String getSymbol() { - return "joke"; - } - - @Override - public List solveOneStep() throws Error { + public ArrayList simplify() throws Error { return null; } @Override - public boolean isSolved() { + public boolean isSimplified() { return true; } @Override - public void generateGraphics() { - - } - - @Override - public void draw(int x, int y) { - final BinaryFont rf = DisplayManager.renderer.getCurrentFont(); - if (jokesFont[joke] >= 0) { - DisplayManager.fonts[jokesFont[joke]].use(DisplayManager.engine); - } - DisplayManager.renderer.glDrawStringLeft(x, y, jokes[joke]); - if (jokesFont[joke] >= 0) { - rf.use(DisplayManager.engine); - } - } - - @Override - public int getWidth() { - if (jokesFont[joke] >= 0) { - return DisplayManager.fonts[jokesFont[joke]].getStringWidth(jokes[joke]); - } else { - return Utils.getFont(small).getStringWidth(jokes[joke]); - } - } - - @Override - public int getHeight() { - if (jokesFont[joke] >= 0) { - return DisplayManager.fonts[jokesFont[joke]].getCharacterHeight(); - } else { - return Utils.getFont(small).getCharacterHeight(); - } - } - - @Override - public int getLine() { - return getHeight() / 2; - } - - @Override - public Calculator getRoot() { + public MathContext getMathContext() { return root; } - private boolean small = false; + @Override + public Function clone() { + return new Joke(root, joke); + } @Override - public void setSmall(boolean small) { - this.small = small; + public Function setParameter(int index, Function var) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); } } diff --git a/src/org/warp/picalculator/math/functions/Multiplication.java b/src/org/warp/picalculator/math/functions/Multiplication.java index 38dcefa3..8dffd225 100644 --- a/src/org/warp/picalculator/math/functions/Multiplication.java +++ b/src/org/warp/picalculator/math/functions/Multiplication.java @@ -3,7 +3,10 @@ package org.warp.picalculator.math.functions; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExponentRule15; import org.warp.picalculator.math.rules.ExponentRule16; @@ -14,28 +17,20 @@ import org.warp.picalculator.math.rules.NumberRule6; import org.warp.picalculator.math.rules.SyntaxRule1; import org.warp.picalculator.math.rules.methods.MultiplicationMethod1; -public class Multiplication extends FunctionTwoValues { +public class Multiplication extends FunctionOperator { - public Multiplication(Calculator root, Function value1, Function value2) { + public Multiplication(MathContext root, Function value1, Function value2) { super(root, value1, value2); if (value1 instanceof Variable && value2 instanceof Variable == false) { - variable1 = value2; - variable2 = value1; + parameter1 = value2; + parameter2 = value1; } } - @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { - return new Multiplication(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.MULTIPLICATION; - } - @Override protected boolean isSolvable() { + Function variable1 = getParameter1(); + Function variable2 = getParameter2(); if (variable1 instanceof Number & variable2 instanceof Number) { return true; } @@ -85,92 +80,36 @@ public class Multiplication extends FunctionTwoValues { result = FractionsRule14.execute(this); } else if (MultiplicationMethod1.compare(this)) { result = MultiplicationMethod1.execute(this); - } else if (variable1.isSolved() & variable2.isSolved()) { - result.add(((Number) variable1).multiply((Number) variable2)); + } else if (parameter1.isSimplified() & parameter2.isSimplified()) { + result.add(((Number) parameter1).multiply((Number) parameter2)); } return result; } - @Override - public boolean drawSignum() { - final Function[] tmpVar = new Function[] { variable1, variable2 }; - final boolean[] ok = new boolean[] { false, false }; - for (int val = 0; val < 2; val++) { - while (!ok[val]) { - if (tmpVar[val] instanceof Division) { - ok[0] = true; - ok[1] = true; - } else if (tmpVar[val] instanceof Variable) { - ok[val] = true; - } else if (tmpVar[val] instanceof Number) { - if (val == 0) { - ok[val] = true; - } else { - if (!(tmpVar[0] instanceof Number)) { - ok[val] = true; - } else { - break; - } - } - } else if (tmpVar[val] instanceof Power) { - tmpVar[val] = ((Power) tmpVar[val]).variable1; - } else if (tmpVar[val] instanceof Root) { - if (val == 0) { - break; - } - ok[val] = true; - } else if (tmpVar[val] instanceof RootSquare) { - if (val == 0) { - break; - } - ok[val] = true; - } else if (tmpVar[val] instanceof Undefined) { - break; - } else if (tmpVar[val] instanceof Joke) { - break; - } else if (tmpVar[val] instanceof Negative) { - if (val == 1) { - break; - } - ok[val] = true; - } else if (tmpVar[val] instanceof Expression) { - if (((Expression)tmpVar[val]).parenthesisNeeded() == true) { - ok[0] = true; - ok[1] = true; - } else { - break; - } - } else if (tmpVar[val] instanceof FunctionTwoValues) { - if (val == 0) { - tmpVar[val] = ((FunctionTwoValues) tmpVar[val]).variable2; - } else { - tmpVar[val] = ((FunctionTwoValues) tmpVar[val]).variable1; - } - } else if (tmpVar[val] instanceof AnteriorFunction) { - tmpVar[val] = ((AnteriorFunction) tmpVar[val]).variable; - } else { - ok[val] = true; - } - } - } - - if (ok[0] == true && ok[1] == true) { - return false; - } else { - return true; - } - } - @Override public boolean equals(Object o) { if (o instanceof Multiplication) { - final FunctionTwoValues f = (FunctionTwoValues) o; - if (variable1.equals(f.variable1) && variable2.equals(f.variable2)) { + final FunctionOperator f = (FunctionOperator) o; + if (parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2())) { return true; - } else if (variable1.equals(f.variable2) && variable2.equals(f.variable1)) { + } else if (parameter1.equals(f.getParameter2()) && parameter2.equals(f.getParameter1())) { return true; } } return false; } + + @Override + public Multiplication clone() { + return new Multiplication(mathContext, parameter1, parameter2); + } + + @Override + public String toString() { + if (parameter1 != null && parameter2 != null) { + return parameter1.toString()+"*"+parameter2.toString(); + } else { + return super.toString(); + } + } } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/Negative.java b/src/org/warp/picalculator/math/functions/Negative.java index 3a228f17..d4207281 100644 --- a/src/org/warp/picalculator/math/functions/Negative.java +++ b/src/org/warp/picalculator/math/functions/Negative.java @@ -7,19 +7,21 @@ import org.warp.picalculator.Errors; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExpandRule1; import org.warp.picalculator.math.rules.ExpandRule5; -public class Negative extends AnteriorFunction { +public class Negative extends FunctionSingle { - public Negative(Calculator root, Function value) { + public Negative(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new Negative(root, value); } @@ -29,13 +31,13 @@ public class Negative extends AnteriorFunction { } @Override - public void generateGraphics() { + public void recomputeDimensions() { variable.setSmall(small); - variable.generateGraphics(); + variable.recomputeDimensions(); - height = getVariable().getHeight(); - width = Utils.getFont(small).getCharacterWidth() /* Width of - */ + getVariable().getWidth(); - line = getVariable().getLine(); + height = getParameter().getHeight(); + width = Utils.getFont(small).getCharacterWidth() /* Width of - */ + getParameter().getWidth(); + line = getParameter().getLine(); } @Override @@ -62,10 +64,10 @@ public class Negative extends AnteriorFunction { result = ExpandRule1.execute(this); } else if (ExpandRule5.compare(this)) { result = ExpandRule5.execute(this); - } else if (variable.isSolved()) { + } else if (variable.isSimplified()) { try { - final Number var = (Number) getVariable(); - result.add(var.multiply(new Number(root, "-1"))); + final Number var = (Number) getParameter(); + result.add(var.multiply(new Number(mathContext, "-1"))); } catch (final NullPointerException ex) { throw new Error(Errors.ERROR); } catch (final NumberFormatException ex) { @@ -75,14 +77,14 @@ public class Negative extends AnteriorFunction { } } else { final ArrayList l1 = new ArrayList<>(); - if (variable.isSolved()) { + if (variable.isSimplified()) { l1.add(variable); } else { - l1.addAll(variable.solveOneStep()); + l1.addAll(variable.simplify()); } for (final Function f : l1) { - result.add(new Negative(root, f)); + result.add(new Negative(mathContext, f)); } } return result; diff --git a/src/org/warp/picalculator/math/functions/Number.java b/src/org/warp/picalculator/math/functions/Number.java index f1f34f29..f8bc20e3 100644 --- a/src/org/warp/picalculator/math/functions/Number.java +++ b/src/org/warp/picalculator/math/functions/Number.java @@ -12,42 +12,39 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.BinaryFont; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import com.rits.cloning.Cloner; public class Number implements Function { - private final Calculator root; + private final MathContext root; protected BigDecimal term; - protected int width; - protected int height; - protected int line; - protected boolean small; - public Number(Calculator root, BigInteger val) { + public Number(MathContext root, BigInteger val) { this.root = root; term = new BigDecimal(val).setScale(Utils.scale, Utils.scaleMode2); } - public Number(Calculator root, BigDecimal val) { + public Number(MathContext root, BigDecimal val) { this.root = root; term = val.setScale(Utils.scale, Utils.scaleMode2); } - public Number(Calculator root, String s) throws Error { + public Number(MathContext root, String s) throws Error { this(root, new BigDecimal(s).setScale(Utils.scale, Utils.scaleMode2)); } - public Number(Calculator root, int s) { + public Number(MathContext root, int s) { this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2)); } - public Number(Calculator root, float s) { + public Number(MathContext root, float s) { this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2)); } - public Number(Calculator root, double s) { + public Number(MathContext root, double s) { this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2)); } @@ -59,18 +56,6 @@ public class Number implements Function { term = val.setScale(Utils.scale, Utils.scaleMode2); } - @Override - public void generateGraphics() { - line = calcLine(); //TODO pp - height = calcHeight(); - width = calcWidth(); - } - - @Override - public String getSymbol() { - return toString(); - } - public Number add(Number f) { final Number ret = new Number(root, getTerm().add(f.getTerm())); return ret; @@ -120,115 +105,13 @@ public class Number implements Function { return s; } -// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) { -// boolean beforedrawminus = this.drawMinus; -// this.drawMinus = drawMinus; -// draw(x, y, small); -// this.drawMinus = beforedrawminus; -// } - - private boolean drawMinus = true; - - @Override - public void draw(int x, int y) { - Utils.getFont(small).use(DisplayManager.engine); - String t = toString(); - - if (t.startsWith("-")) { - if (drawMinus) { - - } else { - t = t.substring(1); - } - } - if (t.contains("ℯ℮")) { - final BinaryFont defaultf = Utils.getFont(small); - final BinaryFont smallf = Utils.getFont(true); - final String s = t.substring(0, t.indexOf("ℯ℮") + 2); - final int sw = defaultf.getStringWidth(s); - DisplayManager.renderer.glDrawStringLeft(x + 1, y + smallf.getCharacterHeight() - 2, s); - smallf.use(DisplayManager.engine); - DisplayManager.renderer.glDrawStringLeft(x + 1 + sw - 3, y, t.substring(t.indexOf("ℯ℮") + 2)); - } else { - DisplayManager.renderer.glDrawStringLeft(x + 1, y, t); - } - } - - public int getHeight(boolean drawMinus) { - final boolean beforedrawminus = this.drawMinus; - this.drawMinus = drawMinus; - final int h = getHeight(); - this.drawMinus = beforedrawminus; - return h; - } - - @Override - public int getHeight() { - return height; - } - - private int calcHeight() { - final String t = toString(); - if (t.contains("ℯ℮")) { - return Utils.getFontHeight(small) - 2 + Utils.getFontHeight(true); - } else { - final int h1 = Utils.getFontHeight(small); - return h1; - } - } - - @Override - public int getWidth() { - return width; - } - - public int calcWidth() { - String t = toString(); - if (t.startsWith("-")) { - if (drawMinus) { - - } else { - t = t.substring(1); - } - } - if (t.contains("ℯ℮")) { - final BinaryFont defaultf = Utils.getFont(small); - final BinaryFont smallf = Utils.getFont(true); - final String s = t.substring(0, t.indexOf("ℯ℮") + 2); - final int sw = defaultf.getStringWidth(s); - return 1 + sw - 3 + smallf.getStringWidth(t.substring(t.indexOf("ℯ℮") + 2)); - } else { - return Utils.getFont(small).getStringWidth(t) + 1; - } - } - - @Override - public int getLine() { - return line; - } - - private int calcLine() { - final String t = toString(); - if (t.contains("ℯ℮")) { - return (Utils.getFontHeight(small) / 2) - 2 + Utils.getFontHeight(true); - } else { - return Utils.getFontHeight(small) / 2; - } - } - @Override public Number clone() { - final Cloner cloner = new Cloner(); - return cloner.deepClone(this); + return new Number(root, term); } - + @Override - public void setSmall(boolean small) { - this.small = small; - } - - @Override - public boolean isSolved() { + public boolean isSimplified() { if (root.exactMode) { return isInteger(); } else { @@ -237,7 +120,7 @@ public class Number implements Function { } @Override - public List solveOneStep() throws Error { + public List simplify() throws Error { final List result = new ArrayList<>(); if (root.exactMode) { Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces())); @@ -284,7 +167,7 @@ public class Number implements Function { } @Override - public Calculator getRoot() { + public MathContext getMathContext() { return root; } @@ -340,4 +223,14 @@ public class Number implements Function { return fs; } + + @Override + public Function setParameter(int index, Function var) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } } diff --git a/src/org/warp/picalculator/math/functions/Power.java b/src/org/warp/picalculator/math/functions/Power.java index 19938e70..8a758107 100644 --- a/src/org/warp/picalculator/math/functions/Power.java +++ b/src/org/warp/picalculator/math/functions/Power.java @@ -3,7 +3,9 @@ package org.warp.picalculator.math.functions; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExponentRule1; import org.warp.picalculator.math.rules.ExponentRule2; @@ -14,25 +16,15 @@ import org.warp.picalculator.math.rules.FractionsRule4; import org.warp.picalculator.math.rules.FractionsRule5; import org.warp.picalculator.math.rules.UndefinedRule1; -public class Power extends FunctionTwoValues { +public class Power extends FunctionOperator { - public Power(Calculator root, Function value1, Function value2) { + public Power(MathContext root, Function value1, Function value2) { super(root, value1, value2); } - @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { - return new Power(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.POWER; - } - @Override protected boolean isSolvable() { - if (variable1 instanceof Number & variable2 instanceof Number) { + if (parameter1 instanceof Number & parameter2 instanceof Number) { return true; } if (UndefinedRule1.compare(this)) { @@ -62,19 +54,6 @@ public class Power extends FunctionTwoValues { return false; } - @Override - public void generateGraphics() { - variable1.setSmall(small); - variable1.generateGraphics(); - - variable2.setSmall(true); - variable2.generateGraphics(); - - height = variable1.getHeight() + variable2.getHeight() - 4; - line = variable2.getHeight() - 4 + variable1.getLine(); - width = getVariable1().getWidth() + getVariable2().getWidth() + 1; - } - @Override public ArrayList solve() throws Error { final ArrayList result = new ArrayList<>(); @@ -94,45 +73,23 @@ public class Power extends FunctionTwoValues { result.addAll(FractionsRule4.execute(this)); } else if (FractionsRule5.compare(this)) { result.addAll(FractionsRule5.execute(this)); - } else if (variable1 instanceof Number & variable2 instanceof Number) { - result.add(((Number) variable1).pow((Number) variable2)); + } else if (parameter1 instanceof Number & parameter2 instanceof Number) { + result.add(((Number) parameter1).pow((Number) parameter2)); } return result; } - - @Override - public void draw(int x, int y) { -// glColor3f(0, 127-50+new Random().nextInt(50), 0); -// glFillRect(x,y,width,height); -// glColor3f(0, 0, 0); - - int dx = 0; - variable1.draw(dx + x, getHeight() - variable1.getHeight() + y); - dx += variable1.getWidth(); - variable2.draw(dx + x, y); - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - - @Override - public int getWidth() { - return width; - } - + @Override public boolean equals(Object o) { if (o instanceof Power) { - final FunctionTwoValues f = (FunctionTwoValues) o; - return variable1.equals(f.variable1) && variable2.equals(f.variable2); + final FunctionOperator f = (FunctionOperator) o; + return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2()); } return false; } + + @Override + public Power clone() { + return new Power(mathContext, parameter1, parameter2); + } } diff --git a/src/org/warp/picalculator/math/functions/Root.java b/src/org/warp/picalculator/math/functions/Root.java index 7e5359a8..57159435 100644 --- a/src/org/warp/picalculator/math/functions/Root.java +++ b/src/org/warp/picalculator/math/functions/Root.java @@ -6,17 +6,19 @@ import java.util.ArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; -public class Root extends FunctionTwoValues { +public class Root extends FunctionOperator { - public Root(Calculator root, Function value1, Function value2) { + public Root(MathContext root, Function value1, Function value2) { super(root, value1, value2); } @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { + protected Function NewInstance(MathContext root, Function value1, Function value2) { return new Root(root, value1, value2); } @@ -27,36 +29,36 @@ public class Root extends FunctionTwoValues { @Override public void generateGraphics() { - variable1.setSmall(true); - variable1.generateGraphics(); + parameter1.setSmall(true); + parameter1.recomputeDimensions(); - variable2.setSmall(small); - variable2.generateGraphics(); + parameter2.setSmall(small); + parameter2.recomputeDimensions(); - width = 1 + variable1.getWidth() + 2 + variable2.getWidth() + 2; - height = variable1.getHeight() + variable2.getHeight() - 2; - line = variable1.getHeight() + variable2.getLine() - 2; + width = 1 + parameter1.getWidth() + 2 + parameter2.getWidth() + 2; + height = parameter1.getHeight() + parameter2.getHeight() - 2; + line = parameter1.getHeight() + parameter2.getLine() - 2; } @Override protected boolean isSolvable() { - if (variable1 instanceof Number & variable2 instanceof Number) { - if (root.exactMode == false) { + if (parameter1 instanceof Number & parameter2 instanceof Number) { + if (mathContext.exactMode == false) { return true; } try { - Number exponent = new Number(root, BigDecimal.ONE); - exponent = exponent.divide((Number) variable1); - final Number resultVal = ((Number) variable2).pow(exponent); - final Number originalVariable = resultVal.pow(new Number(root, 2)); - if (originalVariable.equals(variable2)) { + Number exponent = new Number(mathContext, BigDecimal.ONE); + exponent = exponent.divide((Number) parameter1); + final Number resultVal = ((Number) parameter2).pow(exponent); + final Number originalVariable = resultVal.pow(new Number(mathContext, 2)); + if (originalVariable.equals(parameter2)) { return true; } } catch (Exception | Error ex) { ex.printStackTrace(); } } - if (variable1 instanceof Number && ((Number) variable1).equals(new Number(root, 2))) { + if (parameter1 instanceof Number && ((Number) parameter1).equals(new Number(mathContext, 2))) { return true; } return false; @@ -65,38 +67,38 @@ public class Root extends FunctionTwoValues { @Override public ArrayList solve() throws Error { final ArrayList result = new ArrayList<>(); - if (root.exactMode) { - if (variable1 instanceof Number && ((Number) variable1).equals(new Number(root, 2))) { - result.add(new RootSquare(root, variable2)); + if (mathContext.exactMode) { + if (parameter1 instanceof Number && ((Number) parameter1).equals(new Number(mathContext, 2))) { + result.add(new RootSquare(mathContext, parameter2)); } else { - Number exponent = new Number(root, BigInteger.ONE); - exponent = exponent.divide((Number) variable1); - result.add(((Number) variable2).pow(exponent)); + Number exponent = new Number(mathContext, BigInteger.ONE); + exponent = exponent.divide((Number) parameter1); + result.add(((Number) parameter2).pow(exponent)); } } else { - final Number exp = (Number) variable1; - final Number numb = (Number) variable2; + final Number exp = (Number) parameter1; + final Number numb = (Number) parameter2; - result.add(numb.pow(new Number(root, 1).divide(exp))); + result.add(numb.pow(new Number(mathContext, 1).divide(exp))); } return result; } @Override - public void draw(int x, int y) { + public void draw(int x, int y, boolean small, int caretPos) { // glColor3f(0, 255, 0); // glFillRect(x,y,width,height); // glColor3f(0, 0, 0); final int w1 = getVariable2().getWidth(); final int h1 = getVariable2().getHeight(); - final int w2 = getVariable1().getWidth(); - final int h2 = getVariable1().getHeight(); + final int w2 = getParameter1().getWidth(); + final int h2 = getParameter1().getHeight(); final int height = getHeight(); final int hh = (int) Math.ceil((double) h1 / 2); - getVariable1().draw(x + 1, y); - getVariable2().draw(x + 1 + w2 + 2, y + h2 - 2); + getParameter1().draw(x + 1, y, null, null); + getVariable2().draw(x + 1 + w2 + 2, y + h2 - 2, null, null); DisplayManager.renderer.glDrawLine(x + 1 + w2 - 2, y + height - 2, x + 1 + w2 - 2, y + height - 2); DisplayManager.renderer.glDrawLine(x + 1 + w2 - 1, y + height - 1, x + 1 + w2 - 1, y + height - 1); @@ -124,8 +126,8 @@ public class Root extends FunctionTwoValues { @Override public boolean equals(Object o) { if (o instanceof Root) { - final FunctionTwoValues f = (FunctionTwoValues) o; - return variable1.equals(f.variable1) && variable2.equals(f.variable2); + final FunctionOperator f = (FunctionOperator) o; + return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2); } return false; } diff --git a/src/org/warp/picalculator/math/functions/RootSquare.java b/src/org/warp/picalculator/math/functions/RootSquare.java index 5df55fc0..1896fe50 100644 --- a/src/org/warp/picalculator/math/functions/RootSquare.java +++ b/src/org/warp/picalculator/math/functions/RootSquare.java @@ -5,17 +5,19 @@ import java.util.ArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -public class RootSquare extends AnteriorFunction { +public class RootSquare extends FunctionSingle { - public RootSquare(Calculator root, Function value) { + public RootSquare(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new RootSquare(root, value); } @@ -25,26 +27,26 @@ public class RootSquare extends AnteriorFunction { } @Override - public void generateGraphics() { + public void recomputeDimensions() { variable.setSmall(small); - variable.generateGraphics(); + variable.recomputeDimensions(); - height = getVariable().getHeight() + 2; - width = 1 + 4 + getVariable().getWidth() + 1; - line = getVariable().getLine() + 2; + height = getParameter().getHeight() + 2; + width = 1 + 4 + getParameter().getWidth() + 1; + line = getParameter().getLine() + 2; } @Override protected boolean isSolvable() { if (variable instanceof Number) { - if (root.exactMode == false) { + if (mathContext.exactMode == false) { return true; } try { - Number exponent = new Number(root, BigInteger.ONE); - exponent = exponent.divide(new Number(root, 2)); + Number exponent = new Number(mathContext, BigInteger.ONE); + exponent = exponent.divide(new Number(mathContext, 2)); final Number resultVal = ((Number) variable).pow(exponent); - final Number originalVariable = resultVal.pow(new Number(root, 2)); + final Number originalVariable = resultVal.pow(new Number(mathContext, 2)); if (originalVariable.equals(variable)) { return true; } @@ -58,26 +60,26 @@ public class RootSquare extends AnteriorFunction { @Override public ArrayList solve() throws Error { final ArrayList result = new ArrayList<>(); - if (root.exactMode) { - Number exponent = new Number(root, BigInteger.ONE); - exponent = exponent.divide(new Number(root, 2)); + if (mathContext.exactMode) { + Number exponent = new Number(mathContext, BigInteger.ONE); + exponent = exponent.divide(new Number(mathContext, 2)); result.add(((Number) variable).pow(exponent)); } else { - final Number exp = new Number(root, 2); + final Number exp = new Number(mathContext, 2); final Number numb = (Number) variable; - result.add(numb.pow(new Number(root, 1).divide(exp))); + result.add(numb.pow(new Number(mathContext, 1).divide(exp))); } return result; } @Override - public void draw(int x, int y) { + public int draw(int x, int y, boolean small, int caretPos) { // glColor3f(0, 255, 0); // glFillRect(x,y,width,height); // glColor3f(0, 0, 0); - Utils.writeSquareRoot(getVariable(), x, y, small); + Utils.writeSquareRoot(getParameter(), x, y, small); } @Override diff --git a/src/org/warp/picalculator/math/functions/Subtraction.java b/src/org/warp/picalculator/math/functions/Subtraction.java index 490e4ce4..6ec25c9e 100644 --- a/src/org/warp/picalculator/math/functions/Subtraction.java +++ b/src/org/warp/picalculator/math/functions/Subtraction.java @@ -3,7 +3,9 @@ package org.warp.picalculator.math.functions; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExpandRule1; import org.warp.picalculator.math.rules.ExpandRule5; @@ -14,14 +16,14 @@ import org.warp.picalculator.math.rules.VariableRule2; import org.warp.picalculator.math.rules.VariableRule3; import org.warp.picalculator.math.rules.methods.SumMethod1; -public class Subtraction extends FunctionTwoValues { +public class Subtraction extends FunctionOperator { - public Subtraction(Calculator root, Function value1, Function value2) { + public Subtraction(MathContext root, Function value1, Function value2) { super(root, value1, value2); } @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { + protected Function NewInstance(MathContext root, Function value1, Function value2) { return new Subtraction(root, value1, value2); } @@ -32,7 +34,7 @@ public class Subtraction extends FunctionTwoValues { @Override protected boolean isSolvable() { - if (variable1 instanceof Number & variable2 instanceof Number) { + if (parameter1 instanceof Number & parameter2 instanceof Number) { return true; } if (VariableRule1.compare(this)) { @@ -81,8 +83,8 @@ public class Subtraction extends FunctionTwoValues { result = NumberRule5.execute(this); } else if (SumMethod1.compare(this)) { result = SumMethod1.execute(this); - } else if (variable1.isSolved() & variable2.isSolved()) { - result.add(((Number) variable1).add(((Number) variable2).multiply(new Number(root, "-1")))); + } else if (parameter1.isSimplified() & parameter2.isSimplified()) { + result.add(((Number) parameter1).add(((Number) parameter2).multiply(new Number(mathContext, "-1")))); } return result; } @@ -90,8 +92,8 @@ public class Subtraction extends FunctionTwoValues { @Override public boolean equals(Object o) { if (o instanceof Subtraction) { - final FunctionTwoValues f = (FunctionTwoValues) o; - return variable1.equals(f.variable1) && variable2.equals(f.variable2); + final FunctionOperator f = (FunctionOperator) o; + return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2); } return false; } diff --git a/src/org/warp/picalculator/math/functions/Sum.java b/src/org/warp/picalculator/math/functions/Sum.java index 97ddcea0..525cd99b 100644 --- a/src/org/warp/picalculator/math/functions/Sum.java +++ b/src/org/warp/picalculator/math/functions/Sum.java @@ -7,7 +7,9 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Errors; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.NumberRule3; import org.warp.picalculator.math.rules.NumberRule5; @@ -18,25 +20,15 @@ import org.warp.picalculator.math.rules.VariableRule2; import org.warp.picalculator.math.rules.VariableRule3; import org.warp.picalculator.math.rules.methods.SumMethod1; -public class Sum extends FunctionTwoValues { +public class Sum extends FunctionOperator { - public Sum(Calculator root, Function value1, Function value2) { + public Sum(MathContext root, Function value1, Function value2) { super(root, value1, value2); } - @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { - return new Sum(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.SUM; - } - @Override protected boolean isSolvable() { - if (variable1 instanceof Number & variable2 instanceof Number) { + if (parameter1 instanceof Number & parameter2 instanceof Number) { return true; } if (SyntaxRule2.compare(this)) { @@ -68,7 +60,7 @@ public class Sum extends FunctionTwoValues { @Override public ArrayList solve() throws Error { - if (variable1 == null || variable2 == null) { + if (parameter1 == null || parameter2 == null) { throw new Error(Errors.SYNTAX_ERROR); } ArrayList result = new ArrayList<>(); @@ -88,61 +80,40 @@ public class Sum extends FunctionTwoValues { result = NumberRule7.execute(this); } else if (SumMethod1.compare(this)) { result = SumMethod1.execute(this); - } else if (variable1.isSolved() & variable2.isSolved()) { - if ((root.getChild().equals(this))) { - if (((Number) variable1).term.compareTo(new BigDecimal(2)) == 0 && ((Number) variable2).term.compareTo(new BigDecimal(2)) == 0) { - result.add(new Joke(root, Joke.FISH)); + } else if (parameter1.isSimplified() & parameter2.isSimplified()) { + if ((mathContext.getChild().equals(this))) { + if (((Number) parameter1).term.compareTo(new BigDecimal(2)) == 0 && ((Number) parameter2).term.compareTo(new BigDecimal(2)) == 0) { + result.add(new Joke(mathContext, Joke.FISH)); return result; - } else if (((Number) variable1).term.compareTo(new BigDecimal(20)) == 0 && ((Number) variable2).term.compareTo(new BigDecimal(20)) == 0) { - result.add(new Joke(root, Joke.TORNADO)); + } else if (((Number) parameter1).term.compareTo(new BigDecimal(20)) == 0 && ((Number) parameter2).term.compareTo(new BigDecimal(20)) == 0) { + result.add(new Joke(mathContext, Joke.TORNADO)); return result; - } else if (((Number) variable1).term.compareTo(new BigDecimal(29)) == 0 && ((Number) variable2).term.compareTo(new BigDecimal(29)) == 0) { - result.add(new Joke(root, Joke.SHARKNADO)); + } else if (((Number) parameter1).term.compareTo(new BigDecimal(29)) == 0 && ((Number) parameter2).term.compareTo(new BigDecimal(29)) == 0) { + result.add(new Joke(mathContext, Joke.SHARKNADO)); return result; } } - result.add(((Number) variable1).add((Number) variable2)); + result.add(((Number) parameter1).add((Number) parameter2)); } return result; } - @Override - public void generateGraphics() { - variable1.setSmall(small); - variable1.generateGraphics(); - - variable2.setSmall(small); - variable2.generateGraphics(); - - width = calcWidth(); - height = calcHeight(); - line = calcLine(); - } - - @Override - public int getWidth() { - return width; - } - - @Override - protected int calcWidth() { - int dx = 0; - dx += variable1.getWidth(); - dx += 1; - dx += Utils.getFont(small).getStringWidth(getSymbol()); - return dx += variable2.getWidth(); - } - @Override public boolean equals(Object o) { if (o instanceof Sum) { - final FunctionTwoValues f = (FunctionTwoValues) o; - if (variable1.equals(f.variable1) && variable2.equals(f.variable2)) { + final FunctionOperator f = (FunctionOperator) o; + if (parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2())) { return true; - } else if (variable1.equals(f.variable2) && variable2.equals(f.variable1)) { + } else if (parameter1.equals(f.getParameter2()) && parameter2.equals(f.getParameter1())) { return true; } } return false; } + + @Override + public Sum clone() { + return new Sum(mathContext, parameter1, parameter2); + } + } diff --git a/src/org/warp/picalculator/math/functions/SumSubtraction.java b/src/org/warp/picalculator/math/functions/SumSubtraction.java index 32b16d4c..dd017aa2 100644 --- a/src/org/warp/picalculator/math/functions/SumSubtraction.java +++ b/src/org/warp/picalculator/math/functions/SumSubtraction.java @@ -7,21 +7,23 @@ import org.warp.picalculator.Errors; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExpandRule1; import org.warp.picalculator.math.rules.NumberRule3; import org.warp.picalculator.math.rules.NumberRule4; import org.warp.picalculator.math.rules.NumberRule5; -public class SumSubtraction extends FunctionTwoValues { +public class SumSubtraction extends FunctionOperator { - public SumSubtraction(Calculator root, Function value1, Function value2) { + public SumSubtraction(MathContext root, Function value1, Function value2) { super(root, value1, value2); } @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { + protected Function NewInstance(MathContext root, Function value1, Function value2) { return new SumSubtraction(root, value1, value2); } @@ -32,7 +34,7 @@ public class SumSubtraction extends FunctionTwoValues { @Override protected boolean isSolvable() { - if (variable1 instanceof Number & variable2 instanceof Number) { + if (parameter1 instanceof Number & parameter2 instanceof Number) { return true; } if (NumberRule3.compare(this)) { @@ -52,7 +54,7 @@ public class SumSubtraction extends FunctionTwoValues { @Override public ArrayList solve() throws Error { - if (variable1 == null || variable2 == null) { + if (parameter1 == null || parameter2 == null) { throw new Error(Errors.SYNTAX_ERROR); } ArrayList result = new ArrayList<>(); @@ -64,20 +66,20 @@ public class SumSubtraction extends FunctionTwoValues { result = NumberRule4.execute(this); } else if (NumberRule5.compare(this)) { result = NumberRule5.execute(this); - } else if (variable1.isSolved() & variable2.isSolved()) { - result.add(((Number) variable1).add((Number) variable2)); - result.add(((Number) variable1).add(((Number) variable2).multiply(new Number(root, "-1")))); + } else if (parameter1.isSimplified() & parameter2.isSimplified()) { + result.add(((Number) parameter1).add((Number) parameter2)); + result.add(((Number) parameter1).add(((Number) parameter2).multiply(new Number(mathContext, "-1")))); } return result; } @Override public void generateGraphics() { - variable1.setSmall(small); - variable1.generateGraphics(); + parameter1.setSmall(small); + parameter1.recomputeDimensions(); - variable2.setSmall(small); - variable2.generateGraphics(); + parameter2.setSmall(small); + parameter2.recomputeDimensions(); width = calcWidth(); height = calcHeight(); @@ -85,20 +87,20 @@ public class SumSubtraction extends FunctionTwoValues { } @Override - public void draw(int x, int y) { + public void draw(int x, int y, boolean small, int caretPos) { // glColor3f(127, 127-50+new Random().nextInt(50), 255); // glFillRect(x,y,width,height); // glColor3f(0, 0, 0); final int ln = getLine(); int dx = 0; - variable1.draw(dx + x, ln - variable1.getLine() + y); - dx += variable1.getWidth(); + parameter1.draw(dx + x, ln - parameter1.getLine() + y, null, null); + dx += parameter1.getWidth(); Utils.getFont(small).use(DisplayManager.engine); dx += 1; DisplayManager.renderer.glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol()); dx += Utils.getFont(small).getStringWidth(getSymbol()); - variable2.draw(dx + x, ln - variable2.getLine() + y); + parameter2.draw(dx + x, ln - parameter2.getLine() + y, null, null); } @Override @@ -109,17 +111,17 @@ public class SumSubtraction extends FunctionTwoValues { @Override protected int calcWidth() { int dx = 0; - dx += variable1.getWidth(); + dx += parameter1.getWidth(); dx += 1; dx += Utils.getFont(small).getStringWidth(getSymbol()); - return dx += variable2.getWidth(); + return dx += parameter2.getWidth(); } @Override public boolean equals(Object o) { if (o instanceof SumSubtraction) { - final FunctionTwoValues f = (FunctionTwoValues) o; - return variable1.equals(f.variable1) && variable2.equals(f.variable2); + final FunctionOperator f = (FunctionOperator) o; + return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2); } return false; } diff --git a/src/org/warp/picalculator/math/functions/Undefined.java b/src/org/warp/picalculator/math/functions/Undefined.java index 05b1ff83..93e5741f 100644 --- a/src/org/warp/picalculator/math/functions/Undefined.java +++ b/src/org/warp/picalculator/math/functions/Undefined.java @@ -6,13 +6,14 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; public class Undefined implements Function { - protected final Calculator root; + protected final MathContext root; - public Undefined(Calculator root) { + public Undefined(MathContext root) { this.root = root; } @@ -63,7 +64,7 @@ public class Undefined implements Function { } @Override - public Calculator getRoot() { + public MathContext getRoot() { return root; } diff --git a/src/org/warp/picalculator/math/functions/Variable.java b/src/org/warp/picalculator/math/functions/Variable.java index f46c02cd..8d346eb6 100644 --- a/src/org/warp/picalculator/math/functions/Variable.java +++ b/src/org/warp/picalculator/math/functions/Variable.java @@ -6,28 +6,24 @@ import java.util.List; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import com.rits.cloning.Cloner; public class Variable implements Function { protected char var; - protected int width; - protected int height; - protected int line; - protected int[] varColor; - protected boolean small; - protected final Calculator root; + protected final MathContext root; protected V_TYPE type = V_TYPE.KNOWN; - public Variable(Calculator root, char val, V_TYPE type) { + public Variable(MathContext root, char val, V_TYPE type) { this.root = root; var = val; this.type = type; } - public Variable(Calculator root, String s, V_TYPE type) throws Error { + public Variable(MathContext root, String s, V_TYPE type) throws Error { this(root, s.charAt(0), type); } @@ -47,84 +43,11 @@ public class Variable implements Function { return new Variable(root, var, typ); } - @Override - public void generateGraphics() { - line = calcLine(); - height = calcHeight(); - width = calcWidth(); - varColor = new int[3]; - switch (type) { - case KNOWN: - varColor[0] = 0; - varColor[1] = 200; - varColor[2] = 0; - break; - case UNKNOWN: - varColor[0] = 200; - varColor[1] = 0; - varColor[2] = 0; - break; - case SOLUTION: - varColor[0] = 0; - varColor[1] = 0; - varColor[2] = 200; - break; - } - } - - @Override - public String getSymbol() { - return toString(); - } - @Override public String toString() { return "" + getChar(); } - -// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) { -// boolean beforedrawminus = this.drawMinus; -// this.drawMinus = drawMinus; -// draw(x, y, small); -// this.drawMinus = beforedrawminus; -// } - - @Override - public void draw(int x, int y) { - Utils.getFont(small).use(DisplayManager.engine); - DisplayManager.renderer.glColor3i(varColor[0], varColor[1], varColor[2]); - DisplayManager.renderer.glDrawStringLeft(x + 1, y, toString()); - DisplayManager.renderer.glColor3i(0, 0, 0); - } - - @Override - public int getHeight() { - return height; - } - - private int calcHeight() { - final int h1 = Utils.getFontHeight(small); - return h1; - } - - @Override - public int getWidth() { - return width; - } - - public int calcWidth() { - return Utils.getFont(small).getStringWidth(toString()) + 1; - } - - @Override - public int getLine() { - return line; - } - - private int calcLine() { - return Utils.getFontHeight(small) / 2; - } - + public static class VariableValue { public final Variable v; public final Number n; @@ -136,23 +59,12 @@ public class Variable implements Function { } @Override - public Variable clone() { - final Cloner cloner = new Cloner(); - return cloner.deepClone(this); - } - - @Override - public void setSmall(boolean small) { - this.small = small; - } - - @Override - public boolean isSolved() { + public boolean isSimplified() { return true; } @Override - public List solveOneStep() throws Error { + public List simplify() throws Error { final List result = new ArrayList<>(); result.add(this); return result; @@ -172,13 +84,28 @@ public class Variable implements Function { } @Override - public Calculator getRoot() { + public MathContext getMathContext() { return root; } + @Override + public Variable clone() { + return new Variable(root, var, type); + } + public static enum V_TYPE { KNOWN, UNKNOWN, SOLUTION } + + @Override + public Function setParameter(int index, Function var) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } } diff --git a/src/org/warp/picalculator/math/functions/equations/Equation.java b/src/org/warp/picalculator/math/functions/equations/Equation.java index df01cf6c..10e0bc6f 100644 --- a/src/org/warp/picalculator/math/functions/equations/Equation.java +++ b/src/org/warp/picalculator/math/functions/equations/Equation.java @@ -8,24 +8,24 @@ import java.util.Set; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.SolveMethod; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Subtraction; import com.rits.cloning.Cloner; -public class Equation extends FunctionTwoValues { +public class Equation extends FunctionOperator { - public Equation(Calculator root, Function value1, Function value2) { + public Equation(MathContext root, Function value1, Function value2) { super(root, value1, value2); } @Override - protected Function NewInstance(Calculator root, Function value1, Function value2) { + protected Function NewInstance(MathContext root, Function value1, Function value2) { return new Equation(root, value1, value2); } @@ -36,7 +36,7 @@ public class Equation extends FunctionTwoValues { @Override protected boolean isSolvable() { - if (variable1 instanceof Number & variable2 instanceof Number) { + if (parameter1 instanceof Number & parameter2 instanceof Number) { return true; } return false; @@ -44,17 +44,17 @@ public class Equation extends FunctionTwoValues { @Override public ArrayList solve() throws Error { - if (variable1 == null || variable2 == null) { + if (parameter1 == null || parameter2 == null) { throw new Error(Errors.SYNTAX_ERROR); } final ArrayList result = new ArrayList<>(); - if (variable1.isSolved() & variable2.isSolved()) { - if (((Number) variable2).getTerm().compareTo(new BigDecimal(0)) == 0) { + if (parameter1.isSimplified() & parameter2.isSimplified()) { + if (((Number) parameter2).getTerm().compareTo(new BigDecimal(0)) == 0) { result.add(this); } else { - final Equation e = new Equation(root, null, null); - e.setVariable1(new Subtraction(root, variable1, variable2)); - e.setVariable2(new Number(root, "0")); + final Equation e = new Equation(mathContext, null, null); + e.setParameter1(new Subtraction(mathContext, parameter1, parameter2)); + e.setParameter2(new Number(mathContext, "0")); result.add(e); } } diff --git a/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java b/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java index cead9005..af33e4ac 100644 --- a/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java +++ b/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java @@ -5,24 +5,24 @@ import java.util.List; import org.warp.picalculator.Error; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionDynamic; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionMultipleValues; import org.warp.picalculator.math.functions.Number; -public class EquationsSystem extends FunctionMultipleValues { +public class EquationsSystem extends FunctionDynamic { static final int spacing = 2; - public EquationsSystem(Calculator root) { + public EquationsSystem(MathContext root) { super(root); } - public EquationsSystem(Calculator root, Function value) { + public EquationsSystem(MathContext root, Function value) { super(root, new Function[] { value }); } - public EquationsSystem(Calculator root, Function[] value) { + public EquationsSystem(MathContext root, Function[] value) { super(root, value); } @@ -43,11 +43,11 @@ public class EquationsSystem extends FunctionMultipleValues { public List solveOneStep() throws Error { final List ret = new ArrayList<>(); if (functions.length == 1) { - if (functions[0].isSolved()) { + if (functions[0].isSimplified()) { ret.add(functions[0]); return ret; } else { - final List l = functions[0].solveOneStep(); + final List l = functions[0].simplify(); for (final Function f : l) { if (f instanceof Number) { ret.add(f); @@ -59,8 +59,8 @@ public class EquationsSystem extends FunctionMultipleValues { } } else { for (final Function f : functions) { - if (f.isSolved() == false) { - final List partial = f.solveOneStep(); + if (f.isSimplified() == false) { + final List partial = f.simplify(); for (final Function fnc : partial) { ret.add(new Expression(root, new Function[] { fnc })); } @@ -74,7 +74,7 @@ public class EquationsSystem extends FunctionMultipleValues { public void generateGraphics() { for (final Function f : functions) { f.setSmall(false); - f.generateGraphics(); + f.recomputeDimensions(); } width = 0; @@ -103,7 +103,7 @@ public class EquationsSystem extends FunctionMultipleValues { final int spazioSopra = h - marginBottom; int dy = marginTop; for (final Function f : functions) { - f.draw(x + 5, y + dy); + f.draw(x + 5, y + dy, null, null); dy += f.getHeight() + spacing; } diff --git a/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java b/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java index 7aad21b4..649bbc12 100644 --- a/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java +++ b/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java @@ -5,19 +5,19 @@ import java.util.List; import org.warp.picalculator.Error; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -public class EquationsSystemPart extends AnteriorFunction { +public class EquationsSystemPart extends FunctionSingle { - public EquationsSystemPart(Calculator root, Equation equazione) { + public EquationsSystemPart(MathContext root, Equation equazione) { super(root, equazione); } @Override - protected Function NewInstance(Calculator root, Function value) { + protected Function NewInstance(MathContext root, Function value) { return new EquationsSystemPart(root, (Equation) value); } @@ -27,22 +27,22 @@ public class EquationsSystemPart extends AnteriorFunction { } @Override - public void generateGraphics() { + public void recomputeDimensions() { variable.setSmall(false); - variable.generateGraphics(); + variable.recomputeDimensions(); - width = 5 + getVariable().getWidth(); - height = 3 + getVariable().getHeight() + 2; - line = 3 + getVariable().getLine(); + width = 5 + getParameter().getWidth(); + height = 3 + getParameter().getHeight() + 2; + line = 3 + getParameter().getLine(); } @Override - public void draw(int x, int y) { + public int draw(int x, int y, boolean small, int caretPos) { final int h = getHeight() - 1; final int paddingTop = 3; final int spazioSotto = (h - 3 - 2) / 2 + paddingTop; final int spazioSopra = h - spazioSotto; - variable.draw(x + 5, y + paddingTop); + variable.draw(x + 5, y + paddingTop, null, null); DisplayManager.renderer.glDrawLine(x + 2, y + 0, x + 3, y + 0); DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + spazioSotto / 2); DisplayManager.renderer.glDrawLine(x + 2, y + spazioSotto / 2 + 1, x + 2, y + spazioSotto - 1); diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java index 4945a4e0..c984e039 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java @@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -public class ArcCosine extends AnteriorFunction { +public class ArcCosine extends FunctionSingle { - public ArcCosine(Calculator root, Function value) { + public ArcCosine(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new ArcCosine(root, value); } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java index 03ec67da..45a7d66e 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java @@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -public class ArcSine extends AnteriorFunction { +public class ArcSine extends FunctionSingle { - public ArcSine(Calculator root, Function value) { + public ArcSine(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new ArcSine(root, value); } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java index 3130014e..bb9fb487 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java @@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -public class ArcTangent extends AnteriorFunction { +public class ArcTangent extends FunctionSingle { - public ArcTangent(Calculator root, Function value) { + public ArcTangent(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new ArcTangent(root, value); } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java b/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java index 9ff4c11a..21a5cbd5 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java @@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -public class Cosine extends AnteriorFunction { +public class Cosine extends FunctionSingle { - public Cosine(Calculator root, Function value) { + public Cosine(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new Cosine(root, value); } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Sine.java b/src/org/warp/picalculator/math/functions/trigonometry/Sine.java index 29310a1d..0ba6dc02 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Sine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Sine.java @@ -5,20 +5,20 @@ import java.util.ArrayList; import org.nevec.rjm.BigDecimalMath; import org.warp.picalculator.Error; import org.warp.picalculator.math.AngleMode; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; -public class Sine extends AnteriorFunction { +public class Sine extends FunctionSingle { - public Sine(Calculator root, Function value) { + public Sine(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new Sine(root, value); } @@ -30,12 +30,12 @@ public class Sine extends AnteriorFunction { @Override protected boolean isSolvable() { if (variable instanceof Number) { - if (root.exactMode == false) { + if (mathContext.exactMode == false) { return true; } } - if (root.angleMode == AngleMode.DEG) { - final Function[] solvableValues = new Function[] { new Number(root, 0), new Number(root, 30), new Number(root, 90), }; + if (mathContext.angleMode == AngleMode.DEG) { + final Function[] solvableValues = new Function[] { new Number(mathContext, 0), new Number(mathContext, 30), new Number(mathContext, 90), }; } return false; } @@ -44,8 +44,8 @@ public class Sine extends AnteriorFunction { public ArrayList solve() throws Error { final ArrayList results = new ArrayList<>(); if (variable instanceof Number) { - if (root.exactMode == false) { - results.add(new Number(root, BigDecimalMath.sin(((Number) variable).getTerm()))); + if (mathContext.exactMode == false) { + results.add(new Number(mathContext, BigDecimalMath.sin(((Number) variable).getTerm()))); } } return results; @@ -54,8 +54,8 @@ public class Sine extends AnteriorFunction { @Override public boolean equals(Object o) { if (o instanceof Sine) { - final AnteriorFunction f = (AnteriorFunction) o; - if (variable.equals(f.getVariable())) { + final FunctionSingle f = (FunctionSingle) o; + if (variable.equals(f.getParameter())) { return true; } } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java b/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java index 1d327041..6e029ceb 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java @@ -3,19 +3,19 @@ package org.warp.picalculator.math.functions.trigonometry; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathematicalSymbols; -import org.warp.picalculator.math.functions.AnteriorFunction; -import org.warp.picalculator.math.functions.Function; -public class Tangent extends AnteriorFunction { +public class Tangent extends FunctionSingle { - public Tangent(Calculator root, Function value) { + public Tangent(MathContext root, Function value) { super(root, value); } @Override - public Function NewInstance(Calculator root, Function value) { + public Function NewInstance(MathContext root, Function value) { return new Tangent(root, value); } diff --git a/src/org/warp/picalculator/math/rules/ExpandRule1.java b/src/org/warp/picalculator/math/rules/ExpandRule1.java index d4ed3b2c..852c9610 100644 --- a/src/org/warp/picalculator/math/rules/ExpandRule1.java +++ b/src/org/warp/picalculator/math/rules/ExpandRule1.java @@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Negative; import org.warp.picalculator.math.functions.Subtraction; import org.warp.picalculator.math.functions.Sum; @@ -25,28 +25,28 @@ public class ExpandRule1 { public static boolean compare(Function f) { if (f instanceof Negative) { final Negative fnc = (Negative) f; - if (fnc.getVariable() instanceof Expression) { - final Expression expr = (Expression) fnc.getVariable(); - if (expr.getVariablesLength() == 1) { - if (expr.getVariable(0) instanceof Sum) { + if (fnc.getParameter() instanceof Expression) { + final Expression expr = (Expression) fnc.getParameter(); + if (expr.getParametersLength() == 1) { + if (expr.getParameter(0) instanceof Sum) { return true; - } else if (expr.getVariable(0) instanceof Subtraction) { + } else if (expr.getParameter(0) instanceof Subtraction) { return true; - } else if (expr.getVariable(0) instanceof SumSubtraction) { + } else if (expr.getParameter(0) instanceof SumSubtraction) { return true; } } } } else if (f instanceof Subtraction || f instanceof SumSubtraction) { - final FunctionTwoValues fnc = (FunctionTwoValues) f; - if (fnc.getVariable2() instanceof Expression) { - final Expression expr = (Expression) fnc.getVariable2(); - if (expr.getVariablesLength() == 1) { - if (expr.getVariable(0) instanceof Sum) { + final FunctionOperator fnc = (FunctionOperator) f; + if (fnc.getParameter2() instanceof Expression) { + final Expression expr = (Expression) fnc.getParameter2(); + if (expr.getParametersLength() == 1) { + if (expr.getParameter(0) instanceof Sum) { return true; - } else if (expr.getVariable(0) instanceof Subtraction) { + } else if (expr.getParameter(0) instanceof Subtraction) { return true; - } else if (expr.getVariable(0) instanceof SumSubtraction) { + } else if (expr.getParameter(0) instanceof SumSubtraction) { return true; } } @@ -57,15 +57,15 @@ public class ExpandRule1 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); Expression expr = null; int fromSubtraction = 0; - FunctionTwoValues subtraction = null; + FunctionOperator subtraction = null; if (f instanceof Negative) { - expr = ((Expression) ((Negative) f).getVariable()); + expr = ((Expression) ((Negative) f).getParameter()); } else if (f instanceof Subtraction || f instanceof SumSubtraction) { - expr = ((Expression) ((FunctionTwoValues) f).getVariable2()); + expr = ((Expression) ((FunctionOperator) f).getParameter2()); if (f instanceof Subtraction) { fromSubtraction = 1; } else { @@ -77,48 +77,36 @@ public class ExpandRule1 { } - final Function fnc = expr.getVariable(0); + final Function fnc = expr.getParameter(0); if (fnc instanceof Sum) { - final Function a = ((Sum) fnc).getVariable1(); - final Function b = ((Sum) fnc).getVariable2(); - final Subtraction fnc2 = new Subtraction(root, null, b); - fnc2.setVariable1(new Negative(root, a)); + final Function a = ((Sum) fnc).getParameter1(); + final Function b = ((Sum) fnc).getParameter2(); + final Subtraction fnc2 = new Subtraction(root, new Negative(root, a), b); if (fromSubtraction > 0) { - subtraction = new Subtraction(root, null, null); - subtraction.setVariable1(((FunctionTwoValues) f).getVariable1()); - subtraction.setVariable2(fnc2); + subtraction = new Subtraction(root, ((FunctionOperator) f).getParameter1(), fnc2); result.add(subtraction); } else { result.add(fnc2); } } else if (fnc instanceof Subtraction) { - final Function a = ((Subtraction) fnc).getVariable1(); - final Function b = ((Subtraction) fnc).getVariable2(); - final Sum fnc2 = new Sum(root, null, b); - fnc2.setVariable1(new Negative(root, a)); + final Function a = ((Subtraction) fnc).getParameter1(); + final Function b = ((Subtraction) fnc).getParameter2(); + final Sum fnc2 = new Sum(root, new Negative(root, a), b); if (fromSubtraction > 0) { - subtraction = new Subtraction(root, null, null); - subtraction.setVariable1(((FunctionTwoValues) f).getVariable1()); - subtraction.setVariable2(fnc2); + subtraction = new Subtraction(root, ((FunctionOperator) f).getParameter1(), fnc2); result.add(subtraction); } else { result.add(fnc2); } } else if (fnc instanceof SumSubtraction) { - final Function a = ((SumSubtraction) fnc).getVariable1(); - final Function b = ((SumSubtraction) fnc).getVariable2(); - final Sum fnc2 = new Sum(root, null, b); - fnc2.setVariable1(new Negative(root, a)); - final Subtraction fnc3 = new Subtraction(root, null, b); - fnc3.setVariable1(new Negative(root, a)); + final Function a = ((SumSubtraction) fnc).getParameter1(); + final Function b = ((SumSubtraction) fnc).getParameter2(); + final Sum fnc2 = new Sum(root, new Negative(root, a), b); + final Subtraction fnc3 = new Subtraction(root, new Negative(root, a), b); if (fromSubtraction > 0) { - subtraction = new SumSubtraction(root, null, null); - subtraction.setVariable1(((FunctionTwoValues) f).getVariable1()); - subtraction.setVariable2(fnc2); + subtraction = new SumSubtraction(root, ((FunctionOperator) f).getParameter1(), fnc2); result.add(subtraction); - subtraction = new SumSubtraction(root, null, null); - subtraction.setVariable1(((FunctionTwoValues) f).getVariable1()); - subtraction.setVariable2(fnc3); + subtraction = new SumSubtraction(root, ((FunctionOperator) f).getParameter1(), fnc3); result.add(subtraction); result.add(subtraction); } else { diff --git a/src/org/warp/picalculator/math/rules/ExpandRule5.java b/src/org/warp/picalculator/math/rules/ExpandRule5.java index 52fba71f..81e402f6 100644 --- a/src/org/warp/picalculator/math/rules/ExpandRule5.java +++ b/src/org/warp/picalculator/math/rules/ExpandRule5.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Negative; import org.warp.picalculator.math.functions.Subtraction; @@ -20,15 +20,15 @@ public class ExpandRule5 { public static boolean compare(Function f) { if (f instanceof Negative) { final Negative fnc = (Negative) f; - if (fnc.getVariable() instanceof Expression) { - final Expression e = (Expression) fnc.getVariable(); - return e.getVariablesLength() == 1 && e.getVariable(0) instanceof Negative; + if (fnc.getParameter() instanceof Expression) { + final Expression e = (Expression) fnc.getParameter(); + return e.getParametersLength() == 1 && e.getParameter(0) instanceof Negative; } } else if (f instanceof Subtraction) { final Subtraction fnc = (Subtraction) f; - if (fnc.getVariable2() instanceof Expression) { - final Expression e = (Expression) fnc.getVariable2(); - return e.getVariablesLength() == 1 && e.getVariable(0) instanceof Negative; + if (fnc.getParameter2() instanceof Expression) { + final Expression e = (Expression) fnc.getParameter2(); + return e.getParametersLength() == 1 && e.getParameter(0) instanceof Negative; } } return false; @@ -40,10 +40,10 @@ public class ExpandRule5 { if (f instanceof Negative) { final Negative fnc = (Negative) f; - result.add(((Negative) ((Expression) fnc.getVariable()).getVariable(0)).getVariable()); + result.add(((Negative) ((Expression) fnc.getParameter()).getParameter(0)).getParameter()); } else if (f instanceof Subtraction) { final Subtraction fnc = (Subtraction) f; - result.add(((Negative) ((Expression) fnc.getVariable2()).getVariable(0)).getVariable()); + result.add(((Negative) ((Expression) fnc.getParameter2()).getParameter(0)).getParameter()); } return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule1.java b/src/org/warp/picalculator/math/rules/ExponentRule1.java index cd94a8f5..7b06b7e8 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule1.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule1.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -19,15 +19,15 @@ public class ExponentRule1 { public static boolean compare(Function f) { final Power fnc = (Power) f; - final Calculator root = f.getRoot(); - if (fnc.getVariable1().equals(new Number(root, 1))) { + final MathContext root = f.getMathContext(); + if (fnc.getParameter1().equals(new Number(root, 1))) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); result.add(new Number(root, 1)); return result; diff --git a/src/org/warp/picalculator/math/rules/ExponentRule15.java b/src/org/warp/picalculator/math/rules/ExponentRule15.java index bdbac082..dabe4789 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule15.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule15.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -21,23 +21,20 @@ public class ExponentRule15 { public static boolean compare(Function f) { final Multiplication fnc = (Multiplication) f; - if (fnc.getVariable1().equals(fnc.getVariable2())) { + if (fnc.getParameter1().equals(fnc.getParameter2())) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final Multiplication fnc = (Multiplication) f; - final Power p = new Power(root, null, null); - final Expression expr = new Expression(root); - final Function a = fnc.getVariable1(); - expr.addFunctionToEnd(a); + final Function a = fnc.getParameter1(); + final Expression expr = new Expression(root, a); final Number two = new Number(root, 2); - p.setVariable1(expr); - p.setVariable2(two); + final Power p = new Power(root, expr, two); result.add(p); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule16.java b/src/org/warp/picalculator/math/rules/ExponentRule16.java index 4bede1c6..aac92f59 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule16.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule16.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -22,26 +22,26 @@ public class ExponentRule16 { public static boolean compare(Function f) { final Multiplication fnc = (Multiplication) f; - if (fnc.getVariable1() instanceof Power && fnc.getVariable2() instanceof Power) { - return ((Power)fnc.getVariable1()).getVariable1().equals(((Power)fnc.getVariable2()).getVariable1()); - } else if (fnc.getVariable1() instanceof Power) { - return ((Power)fnc.getVariable1()).getVariable1().equals(fnc.getVariable2()); - } else if (fnc.getVariable2() instanceof Power) { - return ((Power)fnc.getVariable2()).getVariable1().equals(fnc.getVariable1()); + if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) { + return ((Power)fnc.getParameter1()).getParameter1().equals(((Power)fnc.getParameter2()).getParameter1()); + } else if (fnc.getParameter1() instanceof Power) { + return ((Power)fnc.getParameter1()).getParameter1().equals(fnc.getParameter2()); + } else if (fnc.getParameter2() instanceof Power) { + return ((Power)fnc.getParameter2()).getParameter1().equals(fnc.getParameter1()); } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final Multiplication fnc = (Multiplication) f; - if (fnc.getVariable1() instanceof Power && fnc.getVariable2() instanceof Power) { - result.add(new Power(root, ((Power)fnc.getVariable1()).getVariable1(), new Sum(root, new Expression(root, ((Power)fnc.getVariable1()).getVariable2()), new Expression(root, ((Power)fnc.getVariable2()).getVariable2())))); - } else if (fnc.getVariable1() instanceof Power) { - result.add(new Power(root, ((Power)fnc.getVariable1()).getVariable1(), new Sum(root, new Expression(root, ((Power)fnc.getVariable1()).getVariable2()), new Number(root, 1)))); - } else if (fnc.getVariable2() instanceof Power) { - result.add(new Power(root, ((Power)fnc.getVariable1()).getVariable1(), new Sum(root, new Number(root, 1), new Expression(root, ((Power)fnc.getVariable2()).getVariable2())))); + if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) { + result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Expression(root, ((Power)fnc.getParameter2()).getParameter2())))); + } else if (fnc.getParameter1() instanceof Power) { + result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Number(root, 1)))); + } else if (fnc.getParameter2() instanceof Power) { + result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Number(root, 1), new Expression(root, ((Power)fnc.getParameter2()).getParameter2())))); } return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule17.java b/src/org/warp/picalculator/math/rules/ExponentRule17.java index b10086fd..bfc98a27 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule17.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule17.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -23,7 +23,7 @@ public class ExponentRule17 { public static boolean compare(Function f) { if (f instanceof Root) { final Root fnc = (Root) f; - if (fnc.getVariable1().equals(fnc.getVariable2())) { + if (fnc.getParameter1().equals(fnc.getParameter2())) { return true; } } @@ -31,16 +31,13 @@ public class ExponentRule17 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final Multiplication fnc = (Multiplication) f; - final Power p = new Power(fnc.getRoot(), null, null); - final Expression expr = new Expression(root); - final Function a = fnc.getVariable1(); - expr.addFunctionToEnd(a); + final Function a = fnc.getParameter1(); + final Expression expr = new Expression(root, a); final Number two = new Number(root, 2); - p.setVariable1(expr); - p.setVariable2(two); + final Power p = new Power(fnc.getMathContext(), expr, two); result.add(p); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule2.java b/src/org/warp/picalculator/math/rules/ExponentRule2.java index 755fc5ff..0e0c9709 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule2.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule2.java @@ -3,7 +3,7 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -18,7 +18,7 @@ public class ExponentRule2 { public static boolean compare(Function f) { final Power fnc = (Power) f; - if (fnc.getVariable2().equals(new Number(f.getRoot(), 1))) { + if (fnc.getParameter2().equals(new Number(f.getMathContext(), 1))) { return true; } return false; @@ -26,7 +26,7 @@ public class ExponentRule2 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); - result.add(((Power) f).getVariable1()); + result.add(((Power) f).getParameter1()); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule3.java b/src/org/warp/picalculator/math/rules/ExponentRule3.java index 50c640d5..7f7e9999 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule3.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule3.java @@ -3,7 +3,7 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -18,7 +18,7 @@ public class ExponentRule3 { public static boolean compare(Function f) { final Power fnc = (Power) f; - if (fnc.getVariable2().equals(new Number(f.getRoot(), 0))) { + if (fnc.getParameter2().equals(new Number(f.getMathContext(), 0))) { return true; } return false; @@ -26,7 +26,7 @@ public class ExponentRule3 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); - result.add(new Number(f.getRoot(), 1)); + result.add(new Number(f.getMathContext(), 1)); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule4.java b/src/org/warp/picalculator/math/rules/ExponentRule4.java index c2200403..bf9756da 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule4.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule4.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -21,34 +21,26 @@ public class ExponentRule4 { public static boolean compare(Function f) { final Power fnc = (Power) f; - if (fnc.getVariable1() instanceof Expression && ((Expression) fnc.getVariable1()).getVariablesLength() == 1 && ((Expression) fnc.getVariable1()).getVariable(0) instanceof Multiplication && fnc.getVariable2() instanceof Number) { + if (fnc.getParameter1() instanceof Expression && ((Expression) fnc.getParameter1()).getParametersLength() == 1 && ((Expression) fnc.getParameter1()).getParameter(0) instanceof Multiplication && fnc.getParameter2() instanceof Number) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final Power fnc = (Power) f; - final Expression expr = (Expression) fnc.getVariable1(); - final Multiplication mult = (Multiplication) expr.getVariable(0); - final Function a = mult.getVariable1(); - final Function b = mult.getVariable2(); - final Number n = (Number) fnc.getVariable2(); - final Multiplication retMult = new Multiplication(root, null, null); - final Power p1 = new Power(root, null, null); - final Expression e1 = new Expression(root); - e1.addFunctionToEnd(a); - p1.setVariable1(e1); - p1.setVariable2(n); - final Power p2 = new Power(root, null, null); - final Expression e2 = new Expression(root); - e2.addFunctionToEnd(b); - p2.setVariable1(e2); - p2.setVariable2(n); - retMult.setVariable1(p1); - retMult.setVariable2(p2); + final Expression expr = (Expression) fnc.getParameter1(); + final Multiplication mult = (Multiplication) expr.getParameter(0); + final Function a = mult.getParameter1(); + final Function b = mult.getParameter2(); + final Number n = (Number) fnc.getParameter2(); + final Expression e1 = new Expression(root, a); + final Power p1 = new Power(root, e1, n); + final Expression e2 = new Expression(root, b); + final Power p2 = new Power(root, e2, n); + final Multiplication retMult = new Multiplication(root, p1, p2); result.add(retMult); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule9.java b/src/org/warp/picalculator/math/rules/ExponentRule9.java index f27a907c..12ab6957 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule9.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule9.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -21,18 +21,18 @@ public class ExponentRule9 { public static boolean compare(Function f) { final Power fnc = (Power) f; - if (fnc.getVariable1() instanceof Power) { + if (fnc.getParameter1() instanceof Power) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final Power powC = (Power) f; - final Power powB = (Power) powC.getVariable1(); - final Power p = new Power(root, powB.getVariable1(), new Multiplication(root, new Expression(root, powB.getVariable2()), new Expression(root, powC.getVariable2()))); + final Power powB = (Power) powC.getParameter1(); + final Power p = new Power(root, powB.getParameter1(), new Multiplication(root, new Expression(root, powB.getParameter2()), new Expression(root, powC.getParameter2()))); result.add(p); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule1.java b/src/org/warp/picalculator/math/rules/FractionsRule1.java index 5dac1a13..d635a7fc 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule1.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule1.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; /** @@ -18,13 +18,13 @@ import org.warp.picalculator.math.functions.Number; public class FractionsRule1 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final Division fnc = (Division) f; - if (fnc.getVariable1() instanceof Number) { - final Number numb1 = (Number) fnc.getVariable1(); + if (fnc.getParameter1() instanceof Number) { + final Number numb1 = (Number) fnc.getParameter1(); if (numb1.equals(new Number(root, 0))) { - if (fnc.getVariable2() instanceof Number) { - final Number numb2 = (Number) fnc.getVariable2(); + if (fnc.getParameter2() instanceof Number) { + final Number numb2 = (Number) fnc.getParameter2(); if (numb2.equals(new Number(root, 0))) { return false; } @@ -37,7 +37,7 @@ public class FractionsRule1 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); - result.add(new Number(f.getRoot(), 0)); + result.add(new Number(f.getMathContext(), 0)); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule11.java b/src/org/warp/picalculator/math/rules/FractionsRule11.java index 22a94225..0e380a3d 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule11.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule11.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; /** @@ -22,14 +22,14 @@ public class FractionsRule11 { Function a; Function c; Division div2; - if (fnc.getVariable2() instanceof Division) { - div2 = (Division) fnc.getVariable2(); + if (fnc.getParameter2() instanceof Division) { + div2 = (Division) fnc.getParameter2(); } else { return false; } - a = fnc.getVariable1(); - c = div2.getVariable2(); - return new Multiplication(fnc.getRoot(), a, c).isSolved() == false; + a = fnc.getParameter1(); + c = div2.getParameter2(); + return new Multiplication(fnc.getMathContext(), a, c).isSimplified() == false; } public static ArrayList execute(Function f) throws Error { @@ -39,12 +39,12 @@ public class FractionsRule11 { Function b; Function c; - Division div2 = (Division) fnc.getVariable2(); + Division div2 = (Division) fnc.getParameter2(); - a = fnc.getVariable1(); - b = div2.getVariable1(); - c = div2.getVariable2(); - result.add(new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), b)); + a = fnc.getParameter1(); + b = div2.getParameter1(); + c = div2.getParameter2(); + result.add(new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), b)); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule12.java b/src/org/warp/picalculator/math/rules/FractionsRule12.java index 99f8bea6..91db82da 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule12.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule12.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; /** @@ -21,11 +21,11 @@ public class FractionsRule12 { final Division fnc = (Division) f; Function a; Function c; - if (fnc.getVariable1() instanceof Division) { - final Division div2 = (Division) fnc.getVariable1(); - a = fnc.getVariable1(); - c = div2.getVariable2(); - return new Multiplication(fnc.getRoot(), a, c).isSolved() == false; + if (fnc.getParameter1() instanceof Division) { + final Division div2 = (Division) fnc.getParameter1(); + a = fnc.getParameter1(); + c = div2.getParameter2(); + return new Multiplication(fnc.getMathContext(), a, c).isSimplified() == false; } return false; } @@ -37,11 +37,11 @@ public class FractionsRule12 { Function b; Function c; - final Division div2 = (Division) fnc.getVariable1(); - a = fnc.getVariable2(); - b = div2.getVariable1(); - c = div2.getVariable2(); - result.add(new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), b)); + final Division div2 = (Division) fnc.getParameter1(); + a = fnc.getParameter2(); + b = div2.getParameter1(); + c = div2.getParameter2(); + result.add(new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), b)); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule14.java b/src/org/warp/picalculator/math/rules/FractionsRule14.java index c2e2b13c..86132e59 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule14.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule14.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; /** @@ -23,26 +23,26 @@ public class FractionsRule14 { Function b; Function c; Function d; - if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Division) { - final Division div1 = (Division) fnc.getVariable1(); - final Division div2 = (Division) fnc.getVariable2(); - a = div1.getVariable1(); - b = div1.getVariable2(); - c = div2.getVariable1(); - d = div2.getVariable2(); - return new Multiplication(f.getRoot(), a, c).isSolved() == false || new Multiplication(f.getRoot(), b, d).isSolved() == false; - } else if (fnc.getVariable1() instanceof Division) { - final Division div1 = (Division) fnc.getVariable1(); - a = div1.getVariable1(); - b = div1.getVariable2(); - c = fnc.getVariable2(); - return new Multiplication(f.getRoot(), a, c).isSolved() == false; - } else if (fnc.getVariable2() instanceof Division) { - final Division div2 = (Division) fnc.getVariable2(); - a = fnc.getVariable1(); - c = div2.getVariable1(); - d = div2.getVariable2(); - return new Multiplication(f.getRoot(), a, c).isSolved() == false; + if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) { + final Division div1 = (Division) fnc.getParameter1(); + final Division div2 = (Division) fnc.getParameter2(); + a = div1.getParameter1(); + b = div1.getParameter2(); + c = div2.getParameter1(); + d = div2.getParameter2(); + return new Multiplication(f.getMathContext(), a, c).isSimplified() == false || new Multiplication(f.getMathContext(), b, d).isSimplified() == false; + } else if (fnc.getParameter1() instanceof Division) { + final Division div1 = (Division) fnc.getParameter1(); + a = div1.getParameter1(); + b = div1.getParameter2(); + c = fnc.getParameter2(); + return new Multiplication(f.getMathContext(), a, c).isSimplified() == false; + } else if (fnc.getParameter2() instanceof Division) { + final Division div2 = (Division) fnc.getParameter2(); + a = fnc.getParameter1(); + c = div2.getParameter1(); + d = div2.getParameter2(); + return new Multiplication(f.getMathContext(), a, c).isSimplified() == false; } return false; } @@ -55,28 +55,28 @@ public class FractionsRule14 { Function c; Function d; - if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Division) { - final Division div1 = (Division) fnc.getVariable1(); - final Division div2 = (Division) fnc.getVariable2(); - a = div1.getVariable1(); - b = div1.getVariable2(); - c = div2.getVariable1(); - d = div2.getVariable2(); - final Division div = new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), b), new Expression(fnc.getRoot(), d))); + if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Division) { + final Division div1 = (Division) fnc.getParameter1(); + final Division div2 = (Division) fnc.getParameter2(); + a = div1.getParameter1(); + b = div1.getParameter2(); + c = div2.getParameter1(); + d = div2.getParameter2(); + final Division div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), b), new Expression(fnc.getMathContext(), d))); result.add(div); - } else if (fnc.getVariable1() instanceof Division) { - final Division div1 = (Division) fnc.getVariable1(); - a = div1.getVariable1(); - b = div1.getVariable2(); - c = fnc.getVariable2(); - final Division div = new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), b); + } else if (fnc.getParameter1() instanceof Division) { + final Division div1 = (Division) fnc.getParameter1(); + a = div1.getParameter1(); + b = div1.getParameter2(); + c = fnc.getParameter2(); + final Division div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), b); result.add(div); - } else if (fnc.getVariable2() instanceof Division) { - final Division div2 = (Division) fnc.getVariable2(); - a = fnc.getVariable1(); - c = div2.getVariable1(); - d = div2.getVariable2(); - final Division div = new Division(fnc.getRoot(), new Multiplication(fnc.getRoot(), new Expression(fnc.getRoot(), a), new Expression(fnc.getRoot(), c)), d); + } else if (fnc.getParameter2() instanceof Division) { + final Division div2 = (Division) fnc.getParameter2(); + a = fnc.getParameter1(); + c = div2.getParameter1(); + d = div2.getParameter2(); + final Division div = new Division(fnc.getMathContext(), new Multiplication(fnc.getMathContext(), new Expression(fnc.getMathContext(), a), new Expression(fnc.getMathContext(), c)), d); result.add(div); } return result; diff --git a/src/org/warp/picalculator/math/rules/FractionsRule2.java b/src/org/warp/picalculator/math/rules/FractionsRule2.java index 586a720e..d4e2b95e 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule2.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule2.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; /** @@ -18,9 +18,9 @@ public class FractionsRule2 { public static boolean compare(Function f) { final Division fnc = (Division) f; - if (fnc.getVariable2() instanceof Number) { - final Number numb = (Number) fnc.getVariable2(); - if (numb.equals(new Number(f.getRoot(), 1))) { + if (fnc.getParameter2() instanceof Number) { + final Number numb = (Number) fnc.getParameter2(); + if (numb.equals(new Number(f.getMathContext(), 1))) { return true; } } @@ -30,7 +30,7 @@ public class FractionsRule2 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); final Division fnc = (Division) f; - result.add(fnc.getVariable1()); + result.add(fnc.getParameter1()); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule3.java b/src/org/warp/picalculator/math/rules/FractionsRule3.java index 46d9283a..22b6b5d2 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule3.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule3.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; /** @@ -18,7 +18,7 @@ public class FractionsRule3 { public static boolean compare(Function f) { final Division fnc = (Division) f; - if (fnc.getVariable1().equals(fnc.getVariable2())) { + if (fnc.getParameter1().equals(fnc.getParameter2())) { return true; } return false; @@ -26,7 +26,7 @@ public class FractionsRule3 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); - result.add(new Number(f.getRoot(), 1)); + result.add(new Number(f.getMathContext(), 1)); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule4.java b/src/org/warp/picalculator/math/rules/FractionsRule4.java index d411e7f9..a5e37fdb 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule4.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule4.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -19,9 +19,9 @@ public class FractionsRule4 { public static boolean compare(Function f) { final Power fnc = (Power) f; - if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) { - final Number n2 = (Number) fnc.getVariable2(); - if (n2.equals(new Number(f.getRoot(), -1))) { + if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) { + final Number n2 = (Number) fnc.getParameter2(); + if (n2.equals(new Number(f.getMathContext(), -1))) { return true; } } @@ -31,9 +31,9 @@ public class FractionsRule4 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); final Power fnc = (Power) f; - final Function a = ((Division) fnc.getVariable1()).getVariable1(); - final Function b = ((Division) fnc.getVariable1()).getVariable2(); - final Division res = new Division(f.getRoot(), b, a); + final Function a = ((Division) fnc.getParameter1()).getParameter1(); + final Function b = ((Division) fnc.getParameter1()).getParameter2(); + final Division res = new Division(f.getMathContext(), b, a); result.add(res); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule5.java b/src/org/warp/picalculator/math/rules/FractionsRule5.java index f9a9a0bc..b6992173 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule5.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule5.java @@ -4,9 +4,9 @@ import java.math.BigDecimal; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; @@ -21,8 +21,8 @@ public class FractionsRule5 { public static boolean compare(Function f) { final Power fnc = (Power) f; - if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) { - final Number n2 = (Number) fnc.getVariable2(); + if (fnc.getParameter1() instanceof Division && fnc.getParameter2() instanceof Number) { + final Number n2 = (Number) fnc.getParameter2(); if (n2.getTerm().compareTo(BigDecimal.ZERO) < 0) { return true; } @@ -31,12 +31,12 @@ public class FractionsRule5 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final Power fnc = (Power) f; - final Function a = ((Division) fnc.getVariable1()).getVariable1(); - final Function b = ((Division) fnc.getVariable1()).getVariable2(); - final Function c = ((Number) fnc.getVariable2()).multiply(new Number(root, "-1")); + final Function a = ((Division) fnc.getParameter1()).getParameter1(); + final Function b = ((Division) fnc.getParameter1()).getParameter2(); + final Function c = ((Number) fnc.getParameter2()).multiply(new Number(root, "-1")); final Division dv = new Division(root, b, a); final Power pow = new Power(root, dv, c); result.add(pow); diff --git a/src/org/warp/picalculator/math/rules/NumberRule1.java b/src/org/warp/picalculator/math/rules/NumberRule1.java index 79ef49b2..cb8832ff 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule1.java +++ b/src/org/warp/picalculator/math/rules/NumberRule1.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; @@ -18,16 +18,16 @@ import org.warp.picalculator.math.functions.Number; public class NumberRule1 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final Multiplication mult = (Multiplication) f; - if (mult.getVariable1() instanceof Number) { - final Number numb = (Number) mult.getVariable1(); + if (mult.getParameter1() instanceof Number) { + final Number numb = (Number) mult.getParameter1(); if (numb.equals(new Number(root, 0))) { return true; } } - if (mult.getVariable2() instanceof Number) { - final Number numb = (Number) mult.getVariable2(); + if (mult.getParameter2() instanceof Number) { + final Number numb = (Number) mult.getParameter2(); if (numb.equals(new Number(root, 0))) { return true; } @@ -37,7 +37,7 @@ public class NumberRule1 { public static ArrayList execute(Function f) throws Error { final ArrayList result = new ArrayList<>(); - result.add(new Number(f.getRoot(), "0")); + result.add(new Number(f.getMathContext(), "0")); return result; } diff --git a/src/org/warp/picalculator/math/rules/NumberRule2.java b/src/org/warp/picalculator/math/rules/NumberRule2.java index 8438ceb6..5259c96d 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule2.java +++ b/src/org/warp/picalculator/math/rules/NumberRule2.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; @@ -18,16 +18,16 @@ import org.warp.picalculator.math.functions.Number; public class NumberRule2 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final Multiplication mult = (Multiplication) f; - if (mult.getVariable1() instanceof Number) { - final Number numb = (Number) mult.getVariable1(); + if (mult.getParameter1() instanceof Number) { + final Number numb = (Number) mult.getParameter1(); if (numb.equals(new Number(root, 1))) { return true; } } - if (mult.getVariable2() instanceof Number) { - final Number numb = (Number) mult.getVariable2(); + if (mult.getParameter2() instanceof Number) { + final Number numb = (Number) mult.getParameter2(); if (numb.equals(new Number(root, 1))) { return true; } @@ -36,22 +36,22 @@ public class NumberRule2 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); Function a = null; boolean aFound = false; final Multiplication mult = (Multiplication) f; - if (aFound == false & mult.getVariable1() instanceof Number) { - final Number numb = (Number) mult.getVariable1(); + if (aFound == false & mult.getParameter1() instanceof Number) { + final Number numb = (Number) mult.getParameter1(); if (numb.equals(new Number(root, 1))) { - a = mult.getVariable2(); + a = mult.getParameter2(); aFound = true; } } - if (aFound == false && mult.getVariable2() instanceof Number) { - final Number numb = (Number) mult.getVariable2(); + if (aFound == false && mult.getParameter2() instanceof Number) { + final Number numb = (Number) mult.getParameter2(); if (numb.equals(new Number(root, 1))) { - a = mult.getVariable1(); + a = mult.getParameter1(); aFound = true; } } diff --git a/src/org/warp/picalculator/math/rules/NumberRule3.java b/src/org/warp/picalculator/math/rules/NumberRule3.java index 2556e1b5..519999cf 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule3.java +++ b/src/org/warp/picalculator/math/rules/NumberRule3.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Negative; import org.warp.picalculator.math.functions.Number; @@ -26,20 +26,20 @@ public class NumberRule3 { public static boolean compare(Function f) { if (f instanceof Subtraction) { final Subtraction sub = (Subtraction) f; - if (sub.getVariable1().equals(sub.getVariable2())) { + if (sub.getParameter1().equals(sub.getParameter2())) { return true; } } else if (f instanceof Sum) { final Sum sub = (Sum) f; - if (sub.getVariable1() instanceof Negative) { - final Negative neg = (Negative) sub.getVariable1(); - if (neg.getVariable().equals(sub.getVariable2())) { + if (sub.getParameter1() instanceof Negative) { + final Negative neg = (Negative) sub.getParameter1(); + if (neg.getParameter().equals(sub.getParameter2())) { return true; } } } else if (f instanceof SumSubtraction) { final SumSubtraction sub = (SumSubtraction) f; - if (sub.getVariable1().equals(sub.getVariable2())) { + if (sub.getParameter1().equals(sub.getParameter2())) { return true; } } @@ -47,12 +47,10 @@ public class NumberRule3 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); if (f instanceof SumSubtraction) { - final Multiplication mul = new Multiplication(root, null, null); - mul.setVariable1(new Number(root, 2)); - mul.setVariable2(f); + final Multiplication mul = new Multiplication(root, new Number(root, 2), f); result.add(mul); } result.add(new Number(root, 0)); diff --git a/src/org/warp/picalculator/math/rules/NumberRule4.java b/src/org/warp/picalculator/math/rules/NumberRule4.java index 40f6c406..18ea5f37 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule4.java +++ b/src/org/warp/picalculator/math/rules/NumberRule4.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Subtraction; import org.warp.picalculator.math.functions.Sum; import org.warp.picalculator.math.functions.SumSubtraction; @@ -26,11 +26,11 @@ public class NumberRule4 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); final SumSubtraction ss = (SumSubtraction) f; - result.add(new Sum(root, ss.getVariable1(), ss.getVariable2())); - result.add(new Subtraction(root, ss.getVariable1(), ss.getVariable2())); + result.add(new Sum(root, ss.getParameter1(), ss.getParameter2())); + result.add(new Subtraction(root, ss.getParameter1(), ss.getParameter2())); return result; } diff --git a/src/org/warp/picalculator/math/rules/NumberRule5.java b/src/org/warp/picalculator/math/rules/NumberRule5.java index 3de422f3..448e8d49 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule5.java +++ b/src/org/warp/picalculator/math/rules/NumberRule5.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Number; /** @@ -23,21 +23,21 @@ import org.warp.picalculator.math.functions.Number; public class NumberRule5 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); - final FunctionTwoValues fnc = (FunctionTwoValues) f; - if (fnc.getVariable1().equals(new Number(root, 0)) || fnc.getVariable2().equals(new Number(root, 0))) { + final MathContext root = f.getMathContext(); + final FunctionOperator fnc = (FunctionOperator) f; + if (fnc.getParameter1().equals(new Number(root, 0)) || fnc.getParameter2().equals(new Number(root, 0))) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); - final FunctionTwoValues fnc = (FunctionTwoValues) f; - Function a = fnc.getVariable1(); + final FunctionOperator fnc = (FunctionOperator) f; + Function a = fnc.getParameter1(); if (a.equals(new Number(root, 0))) { - a = fnc.getVariable2(); + a = fnc.getParameter2(); } result.add(a); return result; diff --git a/src/org/warp/picalculator/math/rules/NumberRule6.java b/src/org/warp/picalculator/math/rules/NumberRule6.java index 7e451277..13fdf5a6 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule6.java +++ b/src/org/warp/picalculator/math/rules/NumberRule6.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Negative; import org.warp.picalculator.math.functions.Number; @@ -19,16 +19,16 @@ import org.warp.picalculator.math.functions.Number; public class NumberRule6 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final Multiplication mult = (Multiplication) f; - if (mult.getVariable1() instanceof Number) { - final Number numb = (Number) mult.getVariable1(); + if (mult.getParameter1() instanceof Number) { + final Number numb = (Number) mult.getParameter1(); if (numb.equals(new Number(root, -1))) { return true; } } - if (mult.getVariable2() instanceof Number) { - final Number numb = (Number) mult.getVariable2(); + if (mult.getParameter2() instanceof Number) { + final Number numb = (Number) mult.getParameter2(); if (numb.equals(new Number(root, -1))) { return true; } @@ -37,28 +37,27 @@ public class NumberRule6 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); Function a = null; boolean aFound = false; final Multiplication mult = (Multiplication) f; - if (aFound == false & mult.getVariable1() instanceof Number) { - final Number numb = (Number) mult.getVariable1(); + if (aFound == false & mult.getParameter1() instanceof Number) { + final Number numb = (Number) mult.getParameter1(); if (numb.equals(new Number(root, -1))) { - a = mult.getVariable2(); + a = mult.getParameter2(); aFound = true; } } - if (aFound == false && mult.getVariable2() instanceof Number) { - final Number numb = (Number) mult.getVariable2(); + if (aFound == false && mult.getParameter2() instanceof Number) { + final Number numb = (Number) mult.getParameter2(); if (numb.equals(new Number(root, -1))) { - a = mult.getVariable1(); + a = mult.getParameter1(); aFound = true; } } - final Negative minus = new Negative(root, null); - minus.setVariable(a); + final Negative minus = new Negative(root, a); result.add(minus); return result; diff --git a/src/org/warp/picalculator/math/rules/NumberRule7.java b/src/org/warp/picalculator/math/rules/NumberRule7.java index 301fe896..670a1d4e 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule7.java +++ b/src/org/warp/picalculator/math/rules/NumberRule7.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Sum; @@ -19,15 +19,13 @@ import org.warp.picalculator.math.functions.Sum; public class NumberRule7 { public static boolean compare(Sum f) { - return f.getVariable1().equals(f.getVariable2()); + return f.getParameter1().equals(f.getParameter2()); } public static ArrayList execute(Sum f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); - final Multiplication mult = new Multiplication(root, null, null); - mult.setVariable1(new Number(root, 2)); - mult.setVariable2(f.getVariable1()); + final Multiplication mult = new Multiplication(root, new Number(root, 2), f.getParameter1()); result.add(mult); return result; } diff --git a/src/org/warp/picalculator/math/rules/SyntaxRule1.java b/src/org/warp/picalculator/math/rules/SyntaxRule1.java index 16147f29..0766c77a 100644 --- a/src/org/warp/picalculator/math/rules/SyntaxRule1.java +++ b/src/org/warp/picalculator/math/rules/SyntaxRule1.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Sum; @@ -19,32 +19,30 @@ import org.warp.picalculator.math.functions.Sum; public class SyntaxRule1 { public static boolean compare(Function f) { - final FunctionTwoValues m = (FunctionTwoValues) f; - if (m instanceof Multiplication & m.getVariable1() instanceof Multiplication) { + final FunctionOperator m = (FunctionOperator) f; + if (m instanceof Multiplication & m.getParameter1() instanceof Multiplication) { return true; - } else if (m instanceof Sum & m.getVariable1() instanceof Sum) { + } else if (m instanceof Sum & m.getParameter1() instanceof Sum) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); - final FunctionTwoValues mOut = (FunctionTwoValues) f; - final Function a = ((FunctionTwoValues) mOut.getVariable1()).getVariable1(); - final Function b = ((FunctionTwoValues) mOut.getVariable1()).getVariable2(); - final Function c = mOut.getVariable2(); - FunctionTwoValues mIn; + FunctionOperator mOut = (FunctionOperator) f; + final Function a = ((FunctionOperator) mOut.getParameter1()).getParameter1(); + final Function b = ((FunctionOperator) mOut.getParameter1()).getParameter2(); + final Function c = mOut.getParameter2(); + FunctionOperator mIn; if (f instanceof Multiplication) { - mIn = new Multiplication(root, null, null); + mIn = new Multiplication(root, b, c); } else { - mIn = new Sum(root, null, null); + mIn = new Sum(root, b, c); } - mOut.setVariable1(a); - mIn.setVariable1(b); - mIn.setVariable2(c); - mOut.setVariable2(mIn); + mOut = mOut.setParameter1(a); + mOut = mOut.setParameter2(mIn); result.add(mOut); return result; } diff --git a/src/org/warp/picalculator/math/rules/SyntaxRule2.java b/src/org/warp/picalculator/math/rules/SyntaxRule2.java index 75e43289..d09896ca 100644 --- a/src/org/warp/picalculator/math/rules/SyntaxRule2.java +++ b/src/org/warp/picalculator/math/rules/SyntaxRule2.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Sum; /** @@ -18,12 +18,12 @@ import org.warp.picalculator.math.functions.Sum; public class SyntaxRule2 { public static boolean compare(Sum f) { - if (f.getVariable2() instanceof Sum) { + if (f.getParameter2() instanceof Sum) { return true; } - if (f.getVariable2() instanceof Expression) { - final Expression e = (Expression) f.getVariable2(); - if (e.getVariablesLength() == 1 && e.getVariable(0) instanceof Sum) { + if (f.getParameter2() instanceof Expression) { + final Expression e = (Expression) f.getParameter2(); + if (e.getParametersLength() == 1 && e.getParameter(0) instanceof Sum) { return true; } } @@ -31,22 +31,20 @@ public class SyntaxRule2 { } public static ArrayList execute(Sum f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); - final Function a = f.getVariable1(); + final Function a = f.getParameter1(); Function b, c; - if (f.getVariable2() instanceof Sum) { - b = ((Sum) f.getVariable2()).getVariable1(); - c = ((Sum) f.getVariable2()).getVariable2(); + if (f.getParameter2() instanceof Sum) { + b = ((Sum) f.getParameter2()).getParameter1(); + c = ((Sum) f.getParameter2()).getParameter2(); } else { - b = ((Sum) ((Expression) f.getVariable2()).getVariable(0)).getVariable1(); - c = ((Sum) ((Expression) f.getVariable2()).getVariable(0)).getVariable2(); + b = ((Sum) ((Expression) f.getParameter2()).getParameter(0)).getParameter1(); + c = ((Sum) ((Expression) f.getParameter2()).getParameter(0)).getParameter2(); } - final Sum mIn = new Sum(root, null, null); - f.setVariable1(mIn); - mIn.setVariable1(a); - mIn.setVariable2(b); - f.setVariable2(c); + final Sum mIn = new Sum(root, a, b); + f.setParameter1(mIn); + f.setParameter2(c); result.add(f); return result; } diff --git a/src/org/warp/picalculator/math/rules/UndefinedRule1.java b/src/org/warp/picalculator/math/rules/UndefinedRule1.java index b5cecfa4..094a4b4e 100644 --- a/src/org/warp/picalculator/math/rules/UndefinedRule1.java +++ b/src/org/warp/picalculator/math/rules/UndefinedRule1.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; import org.warp.picalculator.math.functions.Undefined; @@ -19,16 +19,16 @@ import org.warp.picalculator.math.functions.Undefined; public class UndefinedRule1 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final Power fnc = (Power) f; - if (fnc.getVariable1().equals(new Number(root, 0)) && fnc.getVariable2().equals(new Number(root, 0))) { + if (fnc.getParameter1().equals(new Number(root, 0)) && fnc.getParameter2().equals(new Number(root, 0))) { return true; } return false; } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); result.add(new Undefined(root)); return result; diff --git a/src/org/warp/picalculator/math/rules/UndefinedRule2.java b/src/org/warp/picalculator/math/rules/UndefinedRule2.java index 2e818b1c..ec964f10 100644 --- a/src/org/warp/picalculator/math/rules/UndefinedRule2.java +++ b/src/org/warp/picalculator/math/rules/UndefinedRule2.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Undefined; @@ -19,10 +19,10 @@ import org.warp.picalculator.math.functions.Undefined; public class UndefinedRule2 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final Division fnc = (Division) f; - if (fnc.getVariable2() instanceof Number) { - final Number numb = (Number) fnc.getVariable2(); + if (fnc.getParameter2() instanceof Number) { + final Number numb = (Number) fnc.getParameter2(); if (numb.equals(new Number(root, 0))) { return true; } @@ -31,7 +31,7 @@ public class UndefinedRule2 { } public static ArrayList execute(Function f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList result = new ArrayList<>(); result.add(new Undefined(root)); return result; diff --git a/src/org/warp/picalculator/math/rules/VariableRule1.java b/src/org/warp/picalculator/math/rules/VariableRule1.java index 61c4efd1..c93757e7 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule1.java +++ b/src/org/warp/picalculator/math/rules/VariableRule1.java @@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Subtraction; import org.warp.picalculator.math.functions.Sum; @@ -20,39 +20,34 @@ import org.warp.picalculator.math.functions.Sum; */ public class VariableRule1 { - public static boolean compare(FunctionTwoValues fnc) { - if (fnc.getVariable1() instanceof Multiplication & fnc.getVariable2() instanceof Multiplication) { - final Multiplication m1 = (Multiplication) fnc.getVariable1(); - final Multiplication m2 = (Multiplication) fnc.getVariable2(); - if (m1.getVariable2().equals(m2.getVariable2())) { + public static boolean compare(FunctionOperator fnc) { + if (fnc.getParameter1() instanceof Multiplication & fnc.getParameter2() instanceof Multiplication) { + final Multiplication m1 = (Multiplication) fnc.getParameter1(); + final Multiplication m2 = (Multiplication) fnc.getParameter2(); + if (m1.getParameter2().equals(m2.getParameter2())) { return true; } } return false; } - public static ArrayList execute(FunctionTwoValues fnc) throws Error { - final Calculator root = fnc.getRoot(); + public static ArrayList execute(FunctionOperator fnc) throws Error { + final MathContext root = fnc.getMathContext(); final ArrayList result = new ArrayList<>(); - final Multiplication m1 = (Multiplication) fnc.getVariable1(); - final Multiplication m2 = (Multiplication) fnc.getVariable2(); - final Function a = m1.getVariable1(); - final Function b = m2.getVariable1(); - final Function x = m1.getVariable2(); + final Multiplication m1 = (Multiplication) fnc.getParameter1(); + final Multiplication m2 = (Multiplication) fnc.getParameter2(); + final Function a = m1.getParameter1(); + final Function b = m2.getParameter1(); + final Function x = m1.getParameter2(); - final Multiplication retm = new Multiplication(root, null, null); - final Expression rete = new Expression(root); - FunctionTwoValues rets; + FunctionOperator rets; if (fnc instanceof Sum) { - rets = new Sum(root, null, null); + rets = new Sum(root, a, b); } else { - rets = new Subtraction(root, null, null); + rets = new Subtraction(root, a, b); } - rets.setVariable1(a); - rets.setVariable2(b); - rete.addFunctionToEnd(rets); - retm.setVariable1(rete); - retm.setVariable2(x); + final Expression rete = new Expression(root, rets); + final Multiplication retm = new Multiplication(root, rete, x); result.add(retm); return result; } diff --git a/src/org/warp/picalculator/math/rules/VariableRule2.java b/src/org/warp/picalculator/math/rules/VariableRule2.java index c3c5ed8d..2f9ed328 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule2.java +++ b/src/org/warp/picalculator/math/rules/VariableRule2.java @@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Subtraction; @@ -21,37 +21,32 @@ import org.warp.picalculator.math.functions.Sum; */ public class VariableRule2 { - public static boolean compare(FunctionTwoValues fnc) { - if (fnc.getVariable1() instanceof Multiplication) { - final Multiplication m1 = (Multiplication) fnc.getVariable1(); - if (m1.getVariable2().equals(fnc.getVariable2())) { + public static boolean compare(FunctionOperator fnc) { + if (fnc.getParameter1() instanceof Multiplication) { + final Multiplication m1 = (Multiplication) fnc.getParameter1(); + if (m1.getParameter2().equals(fnc.getParameter2())) { return true; } } return false; } - public static ArrayList execute(FunctionTwoValues fnc) throws Error { - final Calculator root = fnc.getRoot(); + public static ArrayList execute(FunctionOperator fnc) throws Error { + final MathContext root = fnc.getMathContext(); final ArrayList result = new ArrayList<>(); - final Multiplication m1 = (Multiplication) fnc.getVariable1(); - final Function a = m1.getVariable1(); - final Function x = fnc.getVariable2(); + final Multiplication m1 = (Multiplication) fnc.getParameter1(); + final Function a = m1.getParameter1(); + final Function x = fnc.getParameter2(); - final Multiplication retm = new Multiplication(root, null, null); - final Expression rete = new Expression(root); - FunctionTwoValues rets; + FunctionOperator rets; if (fnc instanceof Sum) { - rets = new Sum(root, null, null); + rets = new Sum(root, a, new Number(root, 1)); } else { - rets = new Subtraction(root, null, null); + rets = new Subtraction(root, a, new Number(root, 1)); } - rets.setVariable1(a); - rets.setVariable2(new Number(root, 1)); - rete.addFunctionToEnd(rets); - retm.setVariable1(rete); - retm.setVariable2(x); + final Expression rete = new Expression(root, rets); + final Multiplication retm = new Multiplication(root, rete, x); result.add(retm); return result; } diff --git a/src/org/warp/picalculator/math/rules/VariableRule3.java b/src/org/warp/picalculator/math/rules/VariableRule3.java index 08b84fd2..de5a8d2f 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule3.java +++ b/src/org/warp/picalculator/math/rules/VariableRule3.java @@ -3,10 +3,10 @@ package org.warp.picalculator.math.rules; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Subtraction; @@ -21,37 +21,32 @@ import org.warp.picalculator.math.functions.Sum; */ public class VariableRule3 { - public static boolean compare(FunctionTwoValues fnc) { - if (fnc.getVariable2() instanceof Multiplication) { - final Multiplication m2 = (Multiplication) fnc.getVariable2(); - if (m2.getVariable2().equals(fnc.getVariable1())) { + public static boolean compare(FunctionOperator fnc) { + if (fnc.getParameter2() instanceof Multiplication) { + final Multiplication m2 = (Multiplication) fnc.getParameter2(); + if (m2.getParameter2().equals(fnc.getParameter1())) { return true; } } return false; } - public static ArrayList execute(FunctionTwoValues fnc) throws Error { - final Calculator root = fnc.getRoot(); + public static ArrayList execute(FunctionOperator fnc) throws Error { + final MathContext root = fnc.getMathContext(); final ArrayList result = new ArrayList<>(); - final Multiplication m2 = (Multiplication) fnc.getVariable2(); - final Function a = m2.getVariable1(); - final Function x = fnc.getVariable1(); + final Multiplication m2 = (Multiplication) fnc.getParameter2(); + final Function a = m2.getParameter1(); + final Function x = fnc.getParameter1(); - final Multiplication retm = new Multiplication(root, null, null); - final Expression rete = new Expression(root); - FunctionTwoValues rets; + FunctionOperator rets; if (fnc instanceof Sum) { - rets = new Sum(root, null, null); + rets = new Sum(root, new Number(root, 1), a); } else { - rets = new Subtraction(root, null, null); + rets = new Subtraction(root, new Number(root, 1), a); } - rets.setVariable1(new Number(root, 1)); - rets.setVariable2(a); - rete.addFunctionToEnd(rets); - retm.setVariable1(rete); - retm.setVariable2(x); + final Expression rete = new Expression(root, rets); + final Multiplication retm = new Multiplication(root, rete, x); result.add(retm); return result; } diff --git a/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java b/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java index 73f079f7..577d22ee 100644 --- a/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java +++ b/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java @@ -3,9 +3,9 @@ package org.warp.picalculator.math.rules.methods; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Multiplication; -import org.warp.picalculator.math.Calculator; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Number; @@ -19,11 +19,11 @@ import org.warp.picalculator.math.functions.Number; public class DivisionRule1 { public static boolean compare(Division f) { - return f.getVariable1().isSolved() && f.getVariable2().isSolved() && !(f.getVariable1() instanceof Number && f.getVariable2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null; + return f.getParameter1().isSimplified() && f.getParameter2().isSimplified() && !(f.getParameter1() instanceof Number && f.getParameter2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null; } public static ArrayList execute(Division f) throws Error { - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); Function result; final ArrayList elements = getDivisionElements(f); final int[] workingElementCouple = getFirstWorkingDivisionCouple(elements); @@ -49,18 +49,18 @@ public class DivisionRule1 { private static ArrayList getDivisionElements(Division division) { final ArrayList elementsNumerator = new ArrayList<>(); - Function numMult = division.getVariable1(); + Function numMult = division.getParameter1(); while (numMult instanceof Multiplication) { - elementsNumerator.add(((Multiplication) numMult).getVariable1()); - numMult = ((Multiplication) numMult).getVariable2(); + elementsNumerator.add(((Multiplication) numMult).getParameter1()); + numMult = ((Multiplication) numMult).getParameter2(); } elementsNumerator.add(numMult); final ArrayList elementsDenominator = new ArrayList<>(); - Function denomMult = division.getVariable1(); + Function denomMult = division.getParameter1(); while (denomMult instanceof Multiplication) { - elementsDenominator.add(((Multiplication) denomMult).getVariable1()); - denomMult = ((Multiplication) denomMult).getVariable2(); + elementsDenominator.add(((Multiplication) denomMult).getParameter1()); + denomMult = ((Multiplication) denomMult).getParameter2(); } elementsDenominator.add(denomMult); @@ -81,7 +81,7 @@ public class DivisionRule1 { if (i != j) { Function testFunc; testFunc = new Multiplication(root, a, b); - if (!testFunc.isSolved()) { + if (!testFunc.isSimplified()) { return new int[] { i, j }; } } diff --git a/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java b/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java index 46f25a09..21d11cb8 100644 --- a/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java +++ b/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java @@ -3,8 +3,8 @@ package org.warp.picalculator.math.rules.methods; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Multiplication; import org.warp.picalculator.math.functions.Number; @@ -18,12 +18,12 @@ import org.warp.picalculator.math.functions.Number; public class MultiplicationMethod1 { public static boolean compare(Function f) { - return ((Multiplication) f).getVariable1().isSolved() && ((Multiplication) f).getVariable2().isSolved() && !(((Multiplication) f).getVariable1() instanceof Number && ((Multiplication) f).getVariable2() instanceof Number) && getFirstWorkingMultiplicationCouple(getMultiplicationElements(f)) != null; + return ((Multiplication) f).getParameter1().isSimplified() && ((Multiplication) f).getParameter2().isSimplified() && !(((Multiplication) f).getParameter1() instanceof Number && ((Multiplication) f).getParameter2() instanceof Number) && getFirstWorkingMultiplicationCouple(getMultiplicationElements(f)) != null; } public static ArrayList execute(Function f) throws Error { Function result; - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList elements = getMultiplicationElements(f); final int[] workingElementCouple = getFirstWorkingMultiplicationCouple(elements); final Function elem1 = elements.get(workingElementCouple[0]); @@ -49,8 +49,8 @@ public class MultiplicationMethod1 { private static ArrayList getMultiplicationElements(Function mult) { final ArrayList elements = new ArrayList<>(); while (mult instanceof Multiplication) { - elements.add(((Multiplication) mult).getVariable1()); - mult = ((Multiplication) mult).getVariable2(); + elements.add(((Multiplication) mult).getParameter1()); + mult = ((Multiplication) mult).getParameter2(); } elements.add(mult); return elements; @@ -66,7 +66,7 @@ public class MultiplicationMethod1 { if (elements.size() == 2) { return null; } - final Calculator root = elements.get(0).getRoot(); + final MathContext root = elements.get(0).getMathContext(); for (int i = 0; i < size; i++) { a = elements.get(i); for (int j = 0; j < size; j++) { @@ -74,7 +74,7 @@ public class MultiplicationMethod1 { if (i != j) { Function testFunc; testFunc = new Multiplication(root, a, b); - if (!testFunc.isSolved()) { + if (!testFunc.isSimplified()) { return new int[] { i, j }; } } diff --git a/src/org/warp/picalculator/math/rules/methods/SumMethod1.java b/src/org/warp/picalculator/math/rules/methods/SumMethod1.java index 4999ac61..042b719c 100644 --- a/src/org/warp/picalculator/math/rules/methods/SumMethod1.java +++ b/src/org/warp/picalculator/math/rules/methods/SumMethod1.java @@ -4,9 +4,9 @@ import java.math.BigDecimal; import java.util.ArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.math.Calculator; -import org.warp.picalculator.math.functions.Function; -import org.warp.picalculator.math.functions.FunctionTwoValues; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.functions.Negative; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Subtraction; @@ -22,13 +22,13 @@ import org.warp.picalculator.math.functions.Sum; public class SumMethod1 { public static boolean compare(Function f) { - final Calculator root = f.getRoot(); - return (f instanceof Sum || f instanceof Subtraction) && ((FunctionTwoValues) f).getVariable1().isSolved() && ((FunctionTwoValues) f).getVariable2().isSolved() && !(((FunctionTwoValues) f).getVariable1() instanceof Number && ((FunctionTwoValues) f).getVariable2() instanceof Number) && getFirstWorkingSumCouple(root, getSumElements(f)) != null; + final MathContext root = f.getMathContext(); + return (f instanceof Sum || f instanceof Subtraction) && ((FunctionOperator) f).getParameter1().isSimplified() && ((FunctionOperator) f).getParameter2().isSimplified() && !(((FunctionOperator) f).getParameter1() instanceof Number && ((FunctionOperator) f).getParameter2() instanceof Number) && getFirstWorkingSumCouple(root, getSumElements(f)) != null; } public static ArrayList execute(Function f) throws Error { Function result; - final Calculator root = f.getRoot(); + final MathContext root = f.getMathContext(); final ArrayList elements = getSumElements(f); final int[] workingElementCouple = getFirstWorkingSumCouple(root, elements); final Function elem1 = elements.get(workingElementCouple[0]); @@ -41,11 +41,11 @@ public class SumMethod1 { final Function a = prec; final Function b = elements.get(i); if (b instanceof Negative) { - prec = new Subtraction(root, a, ((Negative) b).getVariable()); - ((FunctionTwoValues) prec).getVariable2(); + prec = new Subtraction(root, a, ((Negative) b).getParameter()); + ((FunctionOperator) prec).getParameter2(); } else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) { prec = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1))); - ((FunctionTwoValues) prec).getVariable2(); + ((FunctionOperator) prec).getParameter2(); } else { prec = new Sum(root, a, b); } @@ -60,21 +60,21 @@ public class SumMethod1 { } private static ArrayList getSumElements(Function sum) { - final Calculator root = sum.getRoot(); + final MathContext root = sum.getMathContext(); final ArrayList elements = new ArrayList<>(); while (sum instanceof Sum || sum instanceof Subtraction) { if (sum instanceof Sum) { - elements.add(((FunctionTwoValues) sum).getVariable2()); + elements.add(((FunctionOperator) sum).getParameter2()); } else { - elements.add(new Negative(root, ((FunctionTwoValues) sum).getVariable2())); + elements.add(new Negative(root, ((FunctionOperator) sum).getParameter2())); } - sum = ((FunctionTwoValues) sum).getVariable1(); + sum = ((FunctionOperator) sum).getParameter1(); } elements.add(sum); return elements; } - private static int[] getFirstWorkingSumCouple(Calculator root, ArrayList elements) { + private static int[] getFirstWorkingSumCouple(MathContext root, ArrayList elements) { final int size = elements.size(); Function a; Function b; @@ -88,17 +88,17 @@ public class SumMethod1 { if (i != j) { Function testFunc; if (b instanceof Negative) { - testFunc = new Subtraction(root, a, ((Negative) b).getVariable()); + testFunc = new Subtraction(root, a, ((Negative) b).getParameter()); } else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) { testFunc = new Subtraction(root, a, ((Number) b).multiply(new Number(root, -1))); } else if (a instanceof Negative) { - testFunc = new Subtraction(root, b, ((Negative) a).getVariable()); + testFunc = new Subtraction(root, b, ((Negative) a).getParameter()); } else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) { testFunc = new Subtraction(root, b, ((Number) a).multiply(new Number(root, -1))); } else { testFunc = new Sum(root, a, b); } - if (!testFunc.isSolved()) { + if (!testFunc.isSimplified()) { return new int[] { i, j }; } } From baeb076b07ead4da35a32a582fa8defa9891c35e Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Mon, 20 Feb 2017 16:18:54 +0100 Subject: [PATCH 02/10] Updated images --- res/algebra.png | Bin 6916 -> 5728 bytes res/draft.png | Bin 0 -> 1974 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 res/draft.png diff --git a/res/algebra.png b/res/algebra.png index 302766161cea6958d63752b2c37c0960329d57d1..115e8d59fc0b67ff6492a3b4c577992bdade90e6 100644 GIT binary patch literal 5728 zcmbVQ2UL^Ux(%Y>NOJ@QL5d^21*wA4lp-}!6lneI*g1`twdJ_pv5Msw)}6Orx%aKCf93pVefyNX&-wO$&bvp3+Dw-?F984mCY^^G z#sC1#EcLOuc#c}Lv_lf2{?Xa$X=?yZ&wg3xym)HOFCGugy#WB`*0YDE6P9mJt)%zS zG0>!+ImgCwg;y8XBMSgrCFy9Wn+8mf@FA`@4$SE{llgIv9z$=v7At7eQ(Tk%X8zkv zA$VXo?TrMb4}ASbRkIQo_$}e0u7=9lk*4Lpoh#S}_1kPQf)TA{zG+zlj+4pxp8Sr;U zQ^Exj%MQ6=lZSR2!2_|480HIO)k!BERbav)vPv~@Guv&lOmlyBc6N_6IhVOXKpz&v zPNx+b$Yn`%Prdt6cz})Dc;&k3Qt!q7s?YZ}n`on=qWl{|LJs#xTM6lR{ny8jV-g_; zNc1ly*|(J&OD<~~v1$4jU1MjT4w#FsSv(>3x5om-#oJit4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5)UraE)M8>Tc*NMriBtu-c7wDQo8-79b>iBhdH#$Npr9pYZG?Wq> t*Yu?9(Pln3AT)!sod#b6$_R%fj*g$P`ewTMfBts?kXM?D74qgE{{vD)SAGBh diff --git a/res/draft.png b/res/draft.png new file mode 100644 index 0000000000000000000000000000000000000000..acc3edc6285c78d3a3e7d66811429423ca671702 GIT binary patch literal 1974 zcma)7dpHvcAKr?SThWorOd3K;(())G=00YXTW1w=S<=buj3T7twz0DwL2a7UPTjK8q-ED>y}g1>EQfZT-OcLfAh!L^NN6*bpnqkzh0>GMNo>OC^M zckfeA<|+}UDgS6>I^AikNk|*Lv6Xm1W3{{Qt@kH8q2EC*wJ_YJ8m?cVVYJT!zK`Yc zO;#7X&7!G3iP$3evGjK5GI&Pn&zLZG*lyo9XidX~;QwGHp2ai8XUTQv&U6f1P#lSC z4F@q9yh2W!aN*VK-Z_&9drViLRwu6UHvCNrzhg2cB~ZHnT<&g;1is1OAJEzgkJHr* znr|NFLESKiDI8ByT2OrhHMo+`H)D)V6@v4)2N!KexH25xu4T&>UDP0v16&G)X4Et! z5z~2?oa_$;RLT4$q=9Q2^^u&qqLPNF~inFBX3a)a&U3>$|~>n_ngm zSv-?2C&c~P>XhWtiBX=`$T@MCokAalTAHl+O*DE&l)O(-5syChd!O&|FJevZvuz!3wg0*)=|xu ziQEc%y4SGZBlJYu9$_XSwOj--`AX_vDQoP1@&wb27Hey%`}t$$9-d5&VeUCYx`tJ@ z5_>bzo$^-jJbCk#t&(#gq%40&%r&nEFoZ~UCZ1^nE0^ooO_JqEeK!o%UDSUsy|&7Q z$xB?dCDcGQawQ7gJ+!vrd{!%?iR;(uQOs%$^H7T-7qJ)+4^e|TvvFKNb1PsS{eMLM zm4KbSmG#;6A-L6JB7Jk_(u9CEpv0uyzX6Dk6Cc;{SM8#((I9(V!ne;RI+rw)K6Jva zbHlajQT=7cgi;P9i#VZ>xgSHU5va>XGN^a%AV5O3zebwpenBk<_Uw+s^SATyqpJ8- zrfPdH^dVU97l{%xlgwE^^{Iewc5o4oLWrohbPb+v^DqHMpn8?Dk2^3Dm_9Y3MdQm@)?~R<3`0Q@_umv@d!vW=rS}dSj%!*$1im9Dp{#bP?;y6`@MKd%JsHJ}!88*2J&K z!71-Uq*bF&>#a)0S2AYk39?0EmsT=(!adwCPrM-i&ce72JdqR8cGVB^%BoajG3ETQ zG(u&M;$(aZq}}=MQqB9wpm5043u`Cm(ZbTfjZNr{^Aq>JwV-wVzPzFje_ALa*uBo9 z`B){K8arW$f|S!eO}KeH(R6&_A*LpfU1sXiWA$Lr_!3y+r5qz3tiG6t5WNdX-n8%t zM^ygB+OpNjcqJ%@OP}bJ;K#Ssd+|Mdn>wCl*L`tVd0*Vg?roQ?08vnddG?$8-^HT$ znI&@zBFKEr0!BK@k+0&3-0aJTS^LTS*)Q#e(e;na zAkn$!_x;$_U4K<8LmD?Z$iiuAI%uWLQ54Mg!eF?^Ns=^{Af|2Jz_PWvj=dc}t z)vTD?LwE0#V$YOrylrHMo=%kuop>Pw$He){cn=Wy?07p2dWxK7qKWP$n1 z6Q086;e3|$go*S%y0`!nRe)3`vSQd$?T;jRHTK5eWmw-m{w13KVK-LGYOwB;(4UTXa2ZM*EX>-ClI?wp8jCjAC7n){t$ zMtyqI_fTI<6IoK6Ud%X2+8|u}S#SUAI;VYv9bl^XrvJ?k2ER$W765lbI@0W~CH)JC C!0GP* literal 0 HcmV?d00001 From 86438bf6188b4af7236c5f0367c8a223af498dd4 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Fri, 3 Mar 2017 23:06:43 +0100 Subject: [PATCH 03/10] Some other updates to the new internal structure --- .classpath | 5 + src/org/warp/picalculator/Error.java | 10 +- src/org/warp/picalculator/Errors.java | 2 +- src/org/warp/picalculator/TestGPU.java | 53 +++- src/org/warp/picalculator/Utils.java | 112 +++++-- .../warp/picalculator/gui/DisplayManager.java | 6 +- .../picalculator/gui/expression/Block.java | 47 +++ .../gui/expression/BlockChar.java | 41 +++ .../gui/expression/BlockContainer.java | 193 ++++++++++++ .../gui/expression/BlockDivision.java | 70 +++++ .../picalculator/gui/expression/Caret.java | 30 ++ .../gui/expression/CaretState.java | 7 + .../GraphicalElement.java | 8 +- .../gui/graphicengine/Renderer.java | 6 + .../gui/graphicengine/cpu/CPUEngine.java | 20 +- .../gui/graphicengine/cpu/CPUFont.java | 4 +- .../gui/graphicengine/cpu/CPUSkin.java | 2 +- .../gui/graphicengine/cpu/SwingWindow.java | 45 +-- .../graphicengine/gpu/DeallocationHelper.java | 10 +- .../gui/graphicengine/gpu/GPUFont.java | 10 +- .../gui/graphicengine/gpu/GPURenderer.java | 20 +- src/org/warp/picalculator/gui/math/Block.java | 11 - .../warp/picalculator/gui/math/Container.java | 112 ------- .../gui/screens/MathInputScreen.java | 24 +- .../picalculator/math/FunctionDynamic.java | 14 +- .../picalculator/math/FunctionOperator.java | 14 +- .../picalculator/math/FunctionSingle.java | 14 +- .../warp/picalculator/math/MathContext.java | 34 ++- .../math/MathematicalSymbols.java | 77 +++-- .../warp/picalculator/math/SolveMethod.java | 4 +- .../picalculator/math/functions/Division.java | 8 +- .../math/functions/EmptyNumber.java | 4 +- .../math/functions/Expression.java | 42 +-- .../picalculator/math/functions/Joke.java | 4 +- .../math/functions/Multiplication.java | 6 +- .../picalculator/math/functions/Negative.java | 62 +--- .../picalculator/math/functions/Number.java | 4 +- .../picalculator/math/functions/Power.java | 6 +- .../picalculator/math/functions/Root.java | 78 +---- .../math/functions/RootSquare.java | 67 +--- .../math/functions/Subtraction.java | 24 +- .../warp/picalculator/math/functions/Sum.java | 6 +- .../math/functions/SumSubtraction.java | 68 +---- .../math/functions/Undefined.java | 64 ++-- .../picalculator/math/functions/Variable.java | 4 +- .../math/functions/equations/Equation.java | 26 +- .../functions/equations/EquationsSystem.java | 72 +---- .../equations/EquationsSystemPart.java | 61 +--- .../functions/trigonometry/ArcCosine.java | 20 +- .../math/functions/trigonometry/ArcSine.java | 20 +- .../functions/trigonometry/ArcTangent.java | 20 +- .../math/functions/trigonometry/Cosine.java | 20 +- .../math/functions/trigonometry/Sine.java | 31 +- .../math/functions/trigonometry/Tangent.java | 22 +- .../picalculator/math/parser/InputParser.java | 289 ++++++++++++++++++ .../math/parser/features/FeatureChar.java | 13 + .../math/parser/features/FeatureDivision.java | 9 + .../parser/features/FeatureDoubleImpl.java | 33 ++ .../features/FeatureMultiplication.java | 9 + .../math/parser/features/FeatureNumber.java | 27 ++ .../parser/features/FeatureSingleImpl.java | 21 ++ .../math/parser/features/FeatureSum.java | 9 + .../parser/features/interfaces/Feature.java | 5 + .../features/interfaces/FeatureBasic.java | 4 + .../features/interfaces/FeatureDouble.java | 8 + .../features/interfaces/FeatureMultiple.java | 10 + .../features/interfaces/FeatureSingle.java | 6 + .../picalculator/math/rules/ExpandRule1.java | 6 +- .../picalculator/math/rules/ExpandRule5.java | 6 +- .../math/rules/ExponentRule1.java | 6 +- .../math/rules/ExponentRule15.java | 6 +- .../math/rules/ExponentRule16.java | 6 +- .../math/rules/ExponentRule17.java | 6 +- .../math/rules/ExponentRule2.java | 6 +- .../math/rules/ExponentRule3.java | 6 +- .../math/rules/ExponentRule4.java | 6 +- .../math/rules/ExponentRule9.java | 6 +- .../math/rules/FractionsRule1.java | 6 +- .../math/rules/FractionsRule11.java | 6 +- .../math/rules/FractionsRule12.java | 6 +- .../math/rules/FractionsRule14.java | 6 +- .../math/rules/FractionsRule2.java | 6 +- .../math/rules/FractionsRule3.java | 6 +- .../math/rules/FractionsRule4.java | 6 +- .../math/rules/FractionsRule5.java | 6 +- .../picalculator/math/rules/NumberRule1.java | 6 +- .../picalculator/math/rules/NumberRule2.java | 6 +- .../picalculator/math/rules/NumberRule3.java | 6 +- .../picalculator/math/rules/NumberRule4.java | 6 +- .../picalculator/math/rules/NumberRule5.java | 6 +- .../picalculator/math/rules/NumberRule6.java | 6 +- .../picalculator/math/rules/NumberRule7.java | 6 +- .../picalculator/math/rules/SyntaxRule1.java | 6 +- .../picalculator/math/rules/SyntaxRule2.java | 6 +- .../math/rules/UndefinedRule1.java | 6 +- .../math/rules/UndefinedRule2.java | 6 +- .../math/rules/VariableRule1.java | 6 +- .../math/rules/VariableRule2.java | 6 +- .../math/rules/VariableRule3.java | 6 +- .../math/rules/methods/DivisionRule1.java | 16 +- .../rules/methods/MultiplicationMethod1.java | 14 +- .../math/rules/methods/SumMethod1.java | 14 +- 102 files changed, 1467 insertions(+), 956 deletions(-) create mode 100644 src/org/warp/picalculator/gui/expression/Block.java create mode 100644 src/org/warp/picalculator/gui/expression/BlockChar.java create mode 100644 src/org/warp/picalculator/gui/expression/BlockContainer.java create mode 100644 src/org/warp/picalculator/gui/expression/BlockDivision.java create mode 100644 src/org/warp/picalculator/gui/expression/Caret.java create mode 100644 src/org/warp/picalculator/gui/expression/CaretState.java rename src/org/warp/picalculator/gui/{math => expression}/GraphicalElement.java (71%) delete mode 100644 src/org/warp/picalculator/gui/math/Block.java delete mode 100644 src/org/warp/picalculator/gui/math/Container.java create mode 100644 src/org/warp/picalculator/math/parser/InputParser.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureChar.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureDivision.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureMultiplication.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureNumber.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureSum.java create mode 100644 src/org/warp/picalculator/math/parser/features/interfaces/Feature.java create mode 100644 src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java create mode 100644 src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java create mode 100644 src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java create mode 100644 src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java diff --git a/.classpath b/.classpath index f382bba6..1ebddf1e 100644 --- a/.classpath +++ b/.classpath @@ -29,5 +29,10 @@ + + + + + diff --git a/src/org/warp/picalculator/Error.java b/src/org/warp/picalculator/Error.java index 6c9091cf..8ac6a768 100644 --- a/src/org/warp/picalculator/Error.java +++ b/src/org/warp/picalculator/Error.java @@ -7,8 +7,14 @@ public class Error extends java.lang.Throwable { */ private static final long serialVersionUID = -1014947815755694651L; - public Error(Errors ErrorID) { - id = ErrorID; + public Error(Errors errorID) { + super(errorID.toString()); + id = errorID; + } + + public Error(Errors errorID, String errorMessage) { + super(errorID.toString() + ": " + errorMessage); + id = errorID; } public Errors id = Errors.ERROR; diff --git a/src/org/warp/picalculator/Errors.java b/src/org/warp/picalculator/Errors.java index a15dec96..a3df6442 100644 --- a/src/org/warp/picalculator/Errors.java +++ b/src/org/warp/picalculator/Errors.java @@ -1,5 +1,5 @@ package org.warp.picalculator; public enum Errors { - ERROR, DIVISION_BY_ZERO, UNBALANCED_BRACKETS, NOT_IMPLEMENTED, NEGATIVE_PARAMETER, NUMBER_TOO_LARGE, NUMBER_TOO_SMALL, CONVERSION_ERROR, SYNTAX_ERROR, NOT_AN_EQUATION, TIMEOUT + ERROR, DIVISION_BY_ZERO, UNBALANCED_STACK, NOT_IMPLEMENTED, NEGATIVE_PARAMETER, NUMBER_TOO_LARGE, NUMBER_TOO_SMALL, CONVERSION_ERROR, SYNTAX_ERROR, NOT_AN_EQUATION, TIMEOUT, MISSING_ARGUMENTS } diff --git a/src/org/warp/picalculator/TestGPU.java b/src/org/warp/picalculator/TestGPU.java index 62b1f656..8ea9b711 100644 --- a/src/org/warp/picalculator/TestGPU.java +++ b/src/org/warp/picalculator/TestGPU.java @@ -3,25 +3,36 @@ package org.warp.picalculator; import java.io.IOException; import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.RenderingLoop; +import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.BlockDivision; +import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.expression.CaretState; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Skin; +import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine; import org.warp.picalculator.gui.graphicengine.gpu.GPURenderer; import org.warp.picalculator.gui.screens.KeyboardDebugScreen; import org.warp.picalculator.gui.screens.MarioScreen; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.MathematicalSymbols; +import org.warp.picalculator.math.functions.Expression; +import org.warp.picalculator.math.parser.InputParser; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; public class TestGPU { - public static final GPUEngine d = new GPUEngine(); + public static final GraphicEngine d = new GPUEngine(); - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, Error { Utils.debugOn = true; Utils.debugThirdScreen = false; d.create(); @@ -34,17 +45,40 @@ public class TestGPU { private BinaryFont exampleFont; private final Skin exampleSkin; - private final GPURenderer r; + private final Renderer r; private final GraphicEngine d; - - public Scene(GraphicEngine d) throws IOException { + + private final BlockContainer c; + + public Scene(GraphicEngine d) throws IOException, Error { this.d = d; - r = (GPURenderer) d.getRenderer(); + r = d.getRenderer(); exampleFont = d.loadFont("ex"); exampleSkin = d.loadSkin("skin.png"); + BlockContainer.initializeFonts(d.loadFont("ex"), d.loadFont("big")); + + + //New expression framework test + c = new BlockContainer(false, 0, 200); + BlockDivision bd = new BlockDivision(); + c.addBlock(bd); + bd.getUpperContainer().addBlock(new BlockChar('5')); + bd.getUpperContainer().addBlock(new BlockChar(MathematicalSymbols.MULTIPLICATION)); + bd.getUpperContainer().addBlock(new BlockChar('2')); + bd.getLowerContainer().addBlock(new BlockChar('2')); + bd.recomputeDimensions(); + c.addBlock(new BlockChar(MathematicalSymbols.MULTIPLICATION)); + c.addBlock(new BlockChar('2')); + c.addBlock(new BlockChar('2')); + c.addBlock(new BlockChar('b')); + c.recomputeDimensions(); + + Expression expr = InputParser.parseInput(new MathContext(), c); + System.out.println(expr.toString()); + d.start(this); // fonts = new RAWFont[1]; @@ -76,13 +110,16 @@ public class TestGPU { r.glFillRect(2, 2, 160, 160, 0, 0, 16, 16); exampleFont.use(d); r.glColor3f(1, 0, 0); - r.glDrawStringLeft(10, 170, "Prova! 123456789"); + r.glDrawStringLeft(10, 170, "Prova! 123456789 222"); //MSAA TEST r.glDrawStringLeft(10f, 190.5f, "Test MSAA"); exampleSkin.use(d); r.glColor3f(1.0f, 1.0f, 1.0f); r.glFillRect(162, 2.5f, 160, 160, 0, 0, 16, 16); + + //New expression framework test + c.draw(d, r, 10, 220, new Caret(CaretState.VISIBLE_ON, 10)); } } diff --git a/src/org/warp/picalculator/Utils.java b/src/org/warp/picalculator/Utils.java index 6ae106c7..ac026f5a 100644 --- a/src/org/warp/picalculator/Utils.java +++ b/src/org/warp/picalculator/Utils.java @@ -15,7 +15,7 @@ import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.nevec.rjm.BigDecimalMath; @@ -78,6 +78,17 @@ public class Utils { return contains; } + public static boolean isInArray(char ch, char[] a) { + boolean contains = false; + for (final char c : a) { + if (c == ch) { + contains = true; + break; + } + } + return contains; + } + private static final String[] regexNormalSymbols = new String[] { "\\", ".", "[", "]", "{", "}", "(", ")", "*", "+", "-", "?", "^", "$", "|" }; public static String ArrayToRegex(String[] array) { @@ -107,6 +118,33 @@ public class Utils { return regex; } + public static String ArrayToRegex(char[] array) { + String regex = null; + for (final char symbol : array) { + boolean contained = false; + for (final String smb : regexNormalSymbols) { + if ((smb).equals(symbol+"")) { + contained = true; + break; + } + } + if (contained) { + if (regex != null) { + regex += "|\\" + symbol; + } else { + regex = "\\" + symbol; + } + } else { + if (regex != null) { + regex += "|" + symbol; + } else { + regex = symbol+""; + } + } + } + return regex; + } + public static String[] concat(String[] a, String[] b) { final int aLen = a.length; final int bLen = b.length; @@ -116,6 +154,15 @@ public class Utils { return c; } + public static char[] concat(char[] a, char[] b) { + final int aLen = a.length; + final int bLen = b.length; + final char[] c = new char[aLen + bLen]; + System.arraycopy(a, 0, c, 0, aLen); + System.arraycopy(b, 0, c, aLen, bLen); + return c; + } + public static String[] add(String[] a, String b) { final int aLen = a.length; final String[] c = new String[aLen + 1]; @@ -124,7 +171,15 @@ public class Utils { return c; } - public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList fl) { + public static char[] add(char[] a, char b) { + final int aLen = a.length; + final char[] c = new char[aLen + 1]; + System.arraycopy(a, 0, c, 0, aLen); + c[aLen] = b; + return c; + } + + public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { if (fl.get(i) instanceof FunctionSingle) { @@ -143,7 +198,7 @@ public class Utils { return true; } - public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList fl) { + public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { if (fl.get(i) instanceof FunctionSingle) { @@ -162,7 +217,7 @@ public class Utils { return true; } - public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ArrayList fl) { + public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { if (fl.get(i) instanceof FunctionSingle) { @@ -181,7 +236,7 @@ public class Utils { return true; } - public static boolean areThereOnlySettedUpFunctionsAndSystems(ArrayList fl) { + public static boolean areThereOnlySettedUpFunctionsAndSystems(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { if (fl.get(i) instanceof FunctionSingle) { @@ -200,7 +255,7 @@ public class Utils { return true; } - public static boolean areThereOnlyEmptySNFunctions(ArrayList fl) { + public static boolean areThereOnlyEmptySNFunctions(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof FunctionSingle) { if (((FunctionSingle) fl.get(i)).getParameter() == null) { @@ -211,7 +266,7 @@ public class Utils { return false; } - public static boolean areThereOnlyEmptyNSNFunctions(ArrayList fl) { + public static boolean areThereOnlyEmptyNSNFunctions(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof FunctionOperator && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof Division)) { if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) { @@ -222,7 +277,7 @@ public class Utils { return false; } - public static boolean areThereEmptyMultiplications(ArrayList fl) { + public static boolean areThereEmptyMultiplications(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division) { if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) { @@ -233,7 +288,7 @@ public class Utils { return false; } - public static boolean areThereEmptySums(ArrayList fl) { + public static boolean areThereEmptySums(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction) { if (((FunctionOperator) fl.get(i)).getParameter1() == null && ((FunctionOperator) fl.get(i)).getParameter2() == null) { @@ -244,7 +299,7 @@ public class Utils { return false; } - public static boolean areThereEmptySystems(ArrayList fl) { + public static boolean areThereEmptySystems(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (fl.get(i) instanceof EquationsSystemPart) { if (((EquationsSystemPart) fl.get(i)).getParameter() == null) { @@ -255,7 +310,7 @@ public class Utils { return false; } - public static boolean areThereOtherSettedUpFunctions(ArrayList fl) { + public static boolean areThereOtherSettedUpFunctions(ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof FunctionSingle || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division)) { if (fl.get(i) instanceof FunctionSingle) { @@ -338,7 +393,7 @@ public class Utils { return BigDecimalMath.divideRound(new BigDecimal(r.numer()).setScale(Utils.scale, Utils.scaleMode), new BigDecimal(r.denom()).setScale(Utils.scale, Utils.scaleMode)); } - public static boolean equalsVariables(ArrayList variables, ArrayList variables2) { + public static boolean equalsVariables(ObjectArrayList variables, ObjectArrayList variables2) { if (variables.size() != variables2.size()) { return false; } else { @@ -351,21 +406,22 @@ public class Utils { } } + @Deprecated public static void writeSquareRoot(Function var, int x, int y, boolean small) { - var.setSmall(small); - final int w1 = var.getWidth(); - final int h1 = var.getHeight(); - final int wsegno = 5; - final int hsegno = h1 + 2; - - var.draw(x + wsegno, y + (hsegno - h1), null, null); - - DisplayManager.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3); - DisplayManager.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2); - DisplayManager.renderer.glDrawLine(x + 3, y + hsegno - 1, x + 3, y + hsegno - 1); - DisplayManager.renderer.glDrawLine(x + 3, y + (hsegno - 1) / 2 + 1, x + 3, y + hsegno - 1); - DisplayManager.renderer.glDrawLine(x + 4, y, x + 4, y + (hsegno - 1) / 2); - DisplayManager.renderer.glDrawLine(x + 4, y, x + 4 + 1 + w1 + 1, y); +// var.setSmall(small); +// final int w1 = var.getWidth(); +// final int h1 = var.getHeight(); +// final int wsegno = 5; +// final int hsegno = h1 + 2; +// +// var.draw(x + wsegno, y + (hsegno - h1), null, null); +// +// DisplayManager.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3); +// DisplayManager.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2); +// DisplayManager.renderer.glDrawLine(x + 3, y + hsegno - 1, x + 3, y + hsegno - 1); +// DisplayManager.renderer.glDrawLine(x + 3, y + (hsegno - 1) / 2 + 1, x + 3, y + hsegno - 1); +// DisplayManager.renderer.glDrawLine(x + 4, y, x + 4, y + (hsegno - 1) / 2); +// DisplayManager.renderer.glDrawLine(x + 4, y, x + 4 + 1 + w1 + 1, y); } public static final int getFontHeight() { @@ -482,7 +538,7 @@ public class Utils { } - public static Function[][] joinFunctionsResults(ArrayList> ln) { + public static Function[][] joinFunctionsResults(ObjectArrayList> ln) { final int[] sizes = new int[ln.size()]; for (int i = 0; i < ln.size(); i++) { sizes[i] = ln.get(i).size(); @@ -579,7 +635,7 @@ public class Utils { if (displayName.endsWith("MemorySize")) { mb = true; } - ArrayList arr = new ArrayList<>(); + ObjectArrayList arr = new ObjectArrayList<>(); arr.add("getFreePhysicalMemorySize"); arr.add("getProcessCpuLoad"); arr.add("getSystemCpuLoad"); diff --git a/src/org/warp/picalculator/gui/DisplayManager.java b/src/org/warp/picalculator/gui/DisplayManager.java index 6ca9cf38..8b91a077 100644 --- a/src/org/warp/picalculator/gui/DisplayManager.java +++ b/src/org/warp/picalculator/gui/DisplayManager.java @@ -5,7 +5,7 @@ import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Main; import org.warp.picalculator.Utils; @@ -413,7 +413,7 @@ public final class DisplayManager implements RenderingLoop { // if (displayName.endsWith("MemorySize")) { // mb = true; // } -// ArrayList arr = new ArrayList<>(); +// ObjectArrayList arr = new ObjectArrayList<>(); // arr.add("getFreePhysicalMemorySize"); // arr.add("getProcessCpuLoad"); // arr.add("getSystemCpuLoad"); @@ -449,7 +449,7 @@ public final class DisplayManager implements RenderingLoop { workThread.setName("Work thread"); workThread.start(); - engine.start(this); + engine.start(getDrawable()); engine.waitUntilExit(); } catch (final Exception ex) { diff --git a/src/org/warp/picalculator/gui/expression/Block.java b/src/org/warp/picalculator/gui/expression/Block.java new file mode 100644 index 00000000..85967e38 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/Block.java @@ -0,0 +1,47 @@ +package org.warp.picalculator.gui.expression; + +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +public abstract class Block implements GraphicalElement { + + protected boolean small; + protected int width; + protected int height; + protected int line; + + /** + * + * @param r Graphic Renderer class. + * @param x Position relative to the window. + * @param y Position relative to the window. + * @param small + */ + public abstract void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret); + + @Override + public abstract void recomputeDimensions(); + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public int getLine() { + return line; + } + + public boolean isSmall() { + return small; + } + + public abstract void setSmall(boolean small); + +} diff --git a/src/org/warp/picalculator/gui/expression/BlockChar.java b/src/org/warp/picalculator/gui/expression/BlockChar.java new file mode 100644 index 00000000..18c87c50 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockChar.java @@ -0,0 +1,41 @@ +package org.warp.picalculator.gui.expression; + +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; +import org.warp.picalculator.math.parser.features.FeatureChar; +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +public class BlockChar extends Block { + + private final char ch; + + public BlockChar(char ch) { + this.ch = ch; + recomputeDimensions(); + } + + @Override + public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { + BlockContainer.getDefaultFont(small).use(ge); + r.glColor(BlockContainer.getDefaultColor()); + r.glDrawCharLeft(x, y, ch); + } + + @Override + public void recomputeDimensions() { + width = BlockContainer.getDefaultCharWidth(small); + height = BlockContainer.getDefaultCharHeight(small); + line = height/2; + } + + @Override + public void setSmall(boolean small) { + this.small = small; + recomputeDimensions(); + } + + public char getChar() { + return ch; + } + +} diff --git a/src/org/warp/picalculator/gui/expression/BlockContainer.java b/src/org/warp/picalculator/gui/expression/BlockContainer.java new file mode 100644 index 00000000..51235657 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockContainer.java @@ -0,0 +1,193 @@ +package org.warp.picalculator.gui.expression; + +import java.io.IOException; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +import org.warp.picalculator.device.graphicengine.Display; +import org.warp.picalculator.gui.graphicengine.BinaryFont; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; +import org.warp.picalculator.gui.graphicengine.gpu.GPUFont; + +public class BlockContainer implements GraphicalElement { + + private final int minWidth; + private final int minHeight; + private final ObjectArrayList content; + private boolean small; + private int width; + private int height; + private int line; + + public BlockContainer() { + this(false, BlockContainer.getDefaultCharWidth(true), BlockContainer.getDefaultCharHeight(true)); + } + + public BlockContainer(boolean small) { + this(small, BlockContainer.getDefaultCharWidth(true), BlockContainer.getDefaultCharHeight(true)); + } + + public BlockContainer(boolean small, int minWidth, int minHeight) { + this(small, minWidth, minHeight, new ObjectArrayList<>()); + } + + public BlockContainer(boolean small, int minWidth, int minHeight, ObjectArrayList content) { + this.small = small; + this.minWidth = minWidth; + this.minHeight = minHeight; + for (Block b: content) { + b.setSmall(small); + } + this.content = content; + recomputeDimensions(); + } + + public void addBlock(Block b) { + b.setSmall(small); + content.add(b); + recomputeDimensions(); + } + + public void removeBlock(Block b) { + content.remove(b); + recomputeDimensions(); + } + + public void removeAt(int i) { + content.remove(i); + recomputeDimensions(); + } + + public Block getBlockAt(int i) { + return content.get(i); + } + + public void clear() { + content.clear(); + recomputeDimensions(); + } + + /** + * + * @param ge Graphic Engine class. + * @param r Graphic Renderer class of ge. + * @param x Position relative to the window. + * @param y Position relative to the window. + * @param caret Position of the caret. + */ + public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { + int paddingX = 0; + + if (caret.getRemaining() == 0) { + if (content.size() > 0) { + BlockContainer.drawCaret(ge, r, caret, x, y, content.get(0).getHeight()); + } else { + BlockContainer.drawCaret(ge, r, caret, x, y, height); + } + } + + for (Block b : content) { + caret.skip(1); + b.draw(ge, r, x+paddingX, y+line-b.getLine(), caret); + paddingX += b.getWidth(); + if (caret.getRemaining() == 0) BlockContainer.drawCaret(ge, r, caret, x + paddingX, y+line-b.getLine(), b.height); + } + caret.skip(1); + } + + @Override + public void recomputeDimensions() { + int l = 0; //Line + int w = 0; //Width + int h2 = 0; //Height under the line. h = h2 + l + int h = 0; //Height + + for (Block b : content) { + w += b.getWidth(); + final int bl = b.getLine(); + final int bh = b.getHeight(); + final int bh2 = bh - bl; + if (bl > l) { + l = bl; + } + if (bh2 > h2) { + h2 = bh2; + } + } + + h = h2 + l; + + line = l; + if (w > minWidth) { + width = w; + } else { + width = minWidth; + } + if (h > minHeight) { + height = h; + } else { + height = minHeight; + } + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public int getLine() { + return line; + } + + private static final BinaryFont[] defFonts = new BinaryFont[2]; + private static final int[] defFontSizes = new int[4]; + private static final int defColor = 0xFF000000; + + public static void initializeFonts(BinaryFont big, BinaryFont small) { + defFonts[0] = big; + defFonts[1] = small; + defFontSizes[0] = big.getCharacterWidth(); + defFontSizes[1] = big.getCharacterHeight(); + defFontSizes[2] = small.getCharacterWidth(); + defFontSizes[3] = small.getCharacterHeight(); + } + + public static BinaryFont getDefaultFont(boolean small) { + return defFonts[small?1:0]; + } + + + public static int getDefaultColor() { + return defColor; + } + + public static int getDefaultCharWidth(boolean b) { + return defFontSizes[b?2:0]; + } + + public static int getDefaultCharHeight(boolean b) { + return defFontSizes[b?3:1]; + } + + public static void drawCaret(GraphicEngine ge, Renderer r, Caret caret, int x, int y, int height) { + r.glColor(getDefaultColor()); + r.glDrawLine(x, y, x, y-1+height); + r.glDrawLine(x+1, y, x+1, y-1+height); + } + + public void setSmall(boolean small) { + this.small = small; + recomputeDimensions(); + } + + public ObjectArrayList getContent() { + return content.clone(); + } + +} \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/expression/BlockDivision.java b/src/org/warp/picalculator/gui/expression/BlockDivision.java new file mode 100644 index 00000000..c73805d5 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockDivision.java @@ -0,0 +1,70 @@ +package org.warp.picalculator.gui.expression; + +import org.warp.picalculator.Main; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +public class BlockDivision extends Block { + + private final BlockContainer containerUp; + private final BlockContainer containerDown; + + private int paddingLeftUpper; + private int paddingLeftLower; + private int h1; + + public BlockDivision() { + this.containerUp = new BlockContainer(false); + this.containerDown = new BlockContainer(false); + recomputeDimensions(); + } + + @Override + public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { + BlockContainer.getDefaultFont(small).use(ge); + r.glColor(BlockContainer.getDefaultColor()); + containerUp.draw(ge, r, x+1+paddingLeftUpper, y, caret); + r.glDrawLine(x, y+h1+1, x+width, y+h1+1); + containerDown.draw(ge, r, x+1+paddingLeftLower, y + h1+3, caret); + } + + @Override + public void recomputeDimensions() { + final int w1 = containerUp.getWidth(); + final int w2 = containerDown.getWidth(); + final int h1 = containerUp.getHeight(); + final int h2 = containerDown.getHeight(); + width = (w1>w2?w1:w2) + 2; + height = h1+3+h2; + line = h1+1; + this.h1 = h1; + if (w1 != w2) { + if (w1 > w2) { + paddingLeftUpper = 0; + paddingLeftLower = (w1 - w2) / 2; + } else { + paddingLeftUpper = (w2 - w1) / 2; + paddingLeftLower = 0; + } + } + } + + @Override + public void setSmall(boolean small) { + this.small = small; + this.containerUp.setSmall(small); + this.containerDown.setSmall(small); + recomputeDimensions(); + } + + public BlockContainer getUpperContainer() { + return containerUp; + } + + public BlockContainer getLowerContainer() { + return containerDown; + } +} diff --git a/src/org/warp/picalculator/gui/expression/Caret.java b/src/org/warp/picalculator/gui/expression/Caret.java new file mode 100644 index 00000000..5bbdca50 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/Caret.java @@ -0,0 +1,30 @@ +package org.warp.picalculator.gui.expression; + +public class Caret { + + private int pos; + private int remaining; + private CaretState state; + + public Caret(CaretState state, int pos) { + this.state = state; + this.pos = pos; + this.remaining = pos; + } + + public void skip(int i) { + remaining-=i; + } + + public int getPosition() { + return pos; + } + + public int getRemaining() { + return remaining; + } + + public CaretState getState() { + return state; + } +} diff --git a/src/org/warp/picalculator/gui/expression/CaretState.java b/src/org/warp/picalculator/gui/expression/CaretState.java new file mode 100644 index 00000000..a5d63be0 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/CaretState.java @@ -0,0 +1,7 @@ +package org.warp.picalculator.gui.expression; + +public enum CaretState { + VISIBLE_ON, + VISIBLE_OFF, + HIDDEN +} diff --git a/src/org/warp/picalculator/gui/math/GraphicalElement.java b/src/org/warp/picalculator/gui/expression/GraphicalElement.java similarity index 71% rename from src/org/warp/picalculator/gui/math/GraphicalElement.java rename to src/org/warp/picalculator/gui/expression/GraphicalElement.java index 6c5a152e..4d6ab338 100644 --- a/src/org/warp/picalculator/gui/math/GraphicalElement.java +++ b/src/org/warp/picalculator/gui/expression/GraphicalElement.java @@ -1,4 +1,4 @@ -package org.warp.picalculator.gui.math; +package org.warp.picalculator.gui.expression; public interface GraphicalElement { @@ -24,10 +24,4 @@ public interface GraphicalElement { * @return Position of the vertical alignment line of the element, relative to itself. */ public int getLine(); - - /** - * Used to compute the position of the caret. - * @return Length (in characters) of the element. - */ - public int getLength(); } diff --git a/src/org/warp/picalculator/gui/graphicengine/Renderer.java b/src/org/warp/picalculator/gui/graphicengine/Renderer.java index 027ed361..d3f1984c 100644 --- a/src/org/warp/picalculator/gui/graphicengine/Renderer.java +++ b/src/org/warp/picalculator/gui/graphicengine/Renderer.java @@ -29,6 +29,12 @@ public interface Renderer { public void glFillColor(float x, float y, float width, float height); + public void glDrawCharLeft(int x, int y, char ch); + + public void glDrawCharCenter(int x, int y, char ch); + + public void glDrawCharRight(int x, int y, char ch); + public void glDrawStringLeft(float x, float y, String text); public void glDrawStringCenter(float x, float y, String text); diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java index 5c4ce9cc..293a1fc2 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java @@ -45,10 +45,10 @@ public class CPUEngine implements GraphicEngine { g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB); INSTANCE.wasResized = false; } - + @Override public void create() { - INSTANCE = new SwingWindow(this, DisplayManager.getDrawable()); + INSTANCE = new SwingWindow(this); setResizable(Utils.debugOn & !Utils.debugThirdScreen); setDisplayMode(Main.screenSize[0], Main.screenSize[1]); INSTANCE.setVisible(true); @@ -86,6 +86,7 @@ public class CPUEngine implements GraphicEngine { @Override public void start(RenderingLoop d) { + INSTANCE.setRenderingLoop(d); Thread th = new Thread(() -> { try { double extratime = 0; @@ -409,6 +410,21 @@ public class CPUEngine implements GraphicEngine { currentSkin = null; } + @Override + public void glDrawCharLeft(int x, int y, char ch) { + glDrawStringLeft(x, y, ch+""); + } + + @Override + public void glDrawCharCenter(int x, int y, char ch) { + glDrawStringCenter(x, y, ch+""); + } + + @Override + public void glDrawCharRight(int x, int y, char ch) { + glDrawStringRight(x, y, ch+""); + } + } @Override diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java index 77510ccb..70bd632a 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUFont.java @@ -161,9 +161,9 @@ public class CPUFont implements BinaryFont { @Override public int getStringWidth(String text) { - final int w = (charW + 1) * text.length(); + final int w = (charW) * text.length(); if (text.length() > 0) { - return w - 1; + return w; } else { return 0; } diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java index ab6d24e2..3a5b5598 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java @@ -21,7 +21,7 @@ public class CPUSkin implements Skin { @Override public void load(String file) throws IOException { - final BufferedImage img = ImageIO.read(Main.instance.getClass().getResource("/"+file)); + final BufferedImage img = ImageIO.read(this.getClass().getResource("/"+file)); skinData = getMatrixOfImage(img); skinSize = new int[] { img.getWidth(), img.getHeight() }; } diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java b/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java index 126a56bd..ac29e302 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java @@ -24,12 +24,11 @@ import org.warp.picalculator.gui.graphicengine.RenderingLoop; public class SwingWindow extends JFrame { private static final long serialVersionUID = 2945898937634075491L; public CustomCanvas c; - private static RenderingLoop d; + private RenderingLoop renderingLoop; public boolean wasResized = false; private final CPUEngine display; - public SwingWindow(CPUEngine disp, RenderingLoop d) { - SwingWindow.d = d; + public SwingWindow(CPUEngine disp) { display = disp; c = new CustomCanvas(); c.setDoubleBuffered(false); @@ -222,8 +221,12 @@ public class SwingWindow extends JFrame { public int getHeight() { return c.getHeight(); } + + public void setRenderingLoop(RenderingLoop renderingLoop) { + this.renderingLoop = renderingLoop; + } -// private static ArrayList mediaValori = new ArrayList(); +// private static ObjectArrayList mediaValori = new ObjectArrayList(); public class CustomCanvas extends JPanel { @@ -235,22 +238,24 @@ public class SwingWindow extends JFrame { @Override public void paintComponent(Graphics g) { // long time1 = System.nanoTime(); - d.refresh(); - - final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData(); -// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length); - CPUEngine.canvas2d = a; - g.clearRect(0, 0, display.size[0], display.size[1]); - g.drawImage(display.g, 0, 0, null); -// long time2 = System.nanoTime(); -// double timeDelta = ((double)(time2-time1))/1000000000d; -// double mediaAttuale = timeDelta; -// mediaValori.add(mediaAttuale); -// double somma = 0; -// for (Double val : mediaValori) { -// somma+=val; -// } -// System.out.println(somma/((double)mediaValori.size())); + if (renderingLoop != null) { + renderingLoop.refresh(); + + final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData(); + // System.arraycopy(canvas2d, 0, a, 0, canvas2d.length); + CPUEngine.canvas2d = a; + g.clearRect(0, 0, display.size[0], display.size[1]); + g.drawImage(display.g, 0, 0, null); + // long time2 = System.nanoTime(); + // double timeDelta = ((double)(time2-time1))/1000000000d; + // double mediaAttuale = timeDelta; + // mediaValori.add(mediaAttuale); + // double somma = 0; + // for (Double val : mediaValori) { + // somma+=val; + // } + // System.out.println(somma/((double)mediaValori.size())); + } } } } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java b/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java index 232f29c4..80b53179 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java @@ -24,7 +24,7 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.LongBuffer; import java.nio.ShortBuffer; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -267,7 +267,7 @@ public class DeallocationHelper { */ public DeallocationHelper(final boolean ignoreClassesAndFieldsHints) { super(); - final List buffersToDelete = new ArrayList<>(); + final List buffersToDelete = new ObjectArrayList<>(); /** * builds the map used to determine the names of the fields containing * the direct byte buffers. The direct read only buffers and the sliced @@ -342,7 +342,7 @@ public class DeallocationHelper { } // checks if these classes are in the class library if (!attachmentOrByteBufferFieldNameMap.isEmpty()) { - final List classnamesToRemove = new ArrayList<>(); + final List classnamesToRemove = new ObjectArrayList<>(); for (final String classname : attachmentOrByteBufferFieldNameMap.keySet()) { try { Class.forName(classname); @@ -365,7 +365,7 @@ public class DeallocationHelper { final Class bufferClass = Class.forName(classname); Field bufferField = null; Class bufferIntermediaryClass = bufferClass; - final List> intermediaryClassWithoutBufferList = new ArrayList<>(); + final List> intermediaryClassWithoutBufferList = new ObjectArrayList<>(); while (bufferIntermediaryClass != null) { try { bufferField = bufferIntermediaryClass.getDeclaredField(fieldname); @@ -454,7 +454,7 @@ public class DeallocationHelper { final LongBuffer littleEndianReadWriteDirectLongBuffer = ByteBuffer.allocateDirect(1).order(ByteOrder.LITTLE_ENDIAN).asLongBuffer(); final ShortBuffer littleEndianReadOnlyDirectShortBuffer = ByteBuffer.allocateDirect(1).order(ByteOrder.LITTLE_ENDIAN).asReadOnlyBuffer().asShortBuffer(); final ShortBuffer littleEndianReadWriteDirectShortBuffer = ByteBuffer.allocateDirect(1).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer(); - final List buffers = new ArrayList<>(); + final List buffers = new ObjectArrayList<>(); buffers.add(slicedBigEndianReadOnlyDirectByteBuffer); buffers.add(slicedBigEndianReadWriteDirectByteBuffer); buffers.add(bigEndianReadOnlyDirectCharBuffer); diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java index 18733825..522192ba 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java @@ -50,10 +50,14 @@ public class GPUFont implements BinaryFont { final int[] indexes = new int[l]; final char[] chars = txt.toCharArray(); for (int i = 0; i < l; i++) { - indexes[i] = (chars[i] & 0xFFFF) - minCharIndex; + indexes[i] = getCharIndex(chars[i]); } return indexes; } + + public int getCharIndex(char ch) { + return (ch & 0xFFFF) - minCharIndex; + } private void genTexture(boolean[][] chars) { final double totalChars = maxCharIndex - minCharIndex; @@ -120,9 +124,9 @@ public class GPUFont implements BinaryFont { @Override public int getStringWidth(String text) { - final int w = (charW + 1) * text.length(); + final int w = (charW) * text.length(); if (text.length() > 0) { - return w - 1; + return w; } else { return 0; } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java index f388cf82..da347e7b 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java @@ -151,7 +151,7 @@ public class GPURenderer implements Renderer { for (int currentCharIndex = 0; currentCharIndex < txtLen; currentCharIndex++) { tableIndexX = txtArray[currentCharIndex] % currentFont.memoryWidthOfEachColumn; tableIndexY = (txtArray[currentCharIndex] - tableIndexX) / currentFont.memoryWidthOfEachColumn; - glFillRect(x + ((float)currentCharIndex) * ((float)(currentFont.charW + 1)), y, currentFont.charW, currentFont.charH, tableIndexX*currentFont.charW, tableIndexY*currentFont.charH, currentFont.charW, currentFont.charH); + glFillRect(x + ((float)currentCharIndex) * ((float)(currentFont.charW)), y, currentFont.charW, currentFont.charH, tableIndexX*currentFont.charW, tableIndexY*currentFont.charH, currentFont.charW, currentFont.charH); } } @@ -165,6 +165,24 @@ public class GPURenderer implements Renderer { glDrawStringLeft(x - currentFont.getStringWidth(text), y, text); } + @Override + public void glDrawCharLeft(int x, int y, char ch) { + int index = currentFont.getCharIndex(ch); + int tableIndexX = index % currentFont.memoryWidthOfEachColumn; + int tableIndexY = (index - tableIndexX) / currentFont.memoryWidthOfEachColumn; + glFillRect(x, y, currentFont.charW, currentFont.charH, tableIndexX*currentFont.charW, tableIndexY*currentFont.charH, currentFont.charW, currentFont.charH); + } + + @Override + public void glDrawCharCenter(int x, int y, char ch) { + glDrawCharLeft(x - (currentFont.charW / 2), y, ch); + } + + @Override + public void glDrawCharRight(int x, int y, char ch) { + glDrawCharLeft(x - currentFont.charW, y, ch); + } + @Override public BinaryFont getCurrentFont() { return currentFont; diff --git a/src/org/warp/picalculator/gui/math/Block.java b/src/org/warp/picalculator/gui/math/Block.java deleted file mode 100644 index c33f1316..00000000 --- a/src/org/warp/picalculator/gui/math/Block.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.warp.picalculator.gui.math; - -public abstract class Block { - /** - * - * @param x Position relative to the window. - * @param y Position relative to the window. - * @param c Parent container. - */ - public abstract void draw(int x, int y, Container c); -} diff --git a/src/org/warp/picalculator/gui/math/Container.java b/src/org/warp/picalculator/gui/math/Container.java deleted file mode 100644 index 4880de8d..00000000 --- a/src/org/warp/picalculator/gui/math/Container.java +++ /dev/null @@ -1,112 +0,0 @@ -package org.warp.picalculator.gui.math; - -import java.util.ArrayList; - -import org.warp.picalculator.device.graphicengine.Display; -import org.warp.picalculator.gui.graphicengine.GraphicEngine; -import org.warp.picalculator.gui.graphicengine.Renderer; - -public class Container implements GraphicalElement { - - private final int minWidth; - private final int minHeight; - private final ArrayList content; - private int width; - private int height; - private int line; - - public Container(int minWidth, int minHeight) { - this.minWidth = minWidth; - this.minHeight = minHeight; - this.content = new ArrayList<>(); - } - - public Container(int minWidth, int minHeight, ArrayList content) { - this.minWidth = minWidth; - this.minHeight = minHeight; - this.content = content; - } - - public void addBlock(Block b) { - content.add(b); - recomputeDimensions(); - } - - public void removeBlock(Block b) { - content.remove(b); - recomputeDimensions(); - } - - public void removeAt(int i) { - content.remove(i); - recomputeDimensions(); - } - - public Block getBlockAt(int i) { - return content.get(i); - } - - public void clear() { - content.clear(); - recomputeDimensions(); - } - - /** - * - * @param x Position relative to the window. - * @param y Position relative to the window. - * @param small size of the element. - * @param caretPos remaining positions of the caret. - * @return caretPos - currentElementLength - */ - public int draw(GraphicEngine g, int x, int y, boolean small, int caretPos) { - Renderer r = g.getRenderer(); - return caretPos; - - } - - @Override - public void recomputeDimensions() { - int w = 0; - int h = 0; - int l = 0; - - for (Block b : content) { - w += b.getWidth(); - } - - if (w > minWidth) { - width = w; - } else { - width = minWidth; - } - if (h > minHeight) { - height = h; - } else { - height = minHeight; - } - line = l; - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - - @Override - public int getLength() { - // TODO Auto-generated method stub - return 0; - } - -} \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/org/warp/picalculator/gui/screens/MathInputScreen.java index 6fe471a9..ba0b652a 100644 --- a/src/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -2,7 +2,7 @@ package org.warp.picalculator.gui.screens; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashSet; @@ -457,7 +457,7 @@ public class MathInputScreen extends Screen { newExpression = ""; firstStep = false; if (calc.f != null) { - calc.f = new ArrayList<>(); + calc.f = new ObjectArrayList<>(); } return true; } @@ -525,7 +525,7 @@ public class MathInputScreen extends Screen { } } - private ArrayList solveExpression(ArrayList f22) { + private ObjectArrayList solveExpression(ObjectArrayList f22) { try { try { return calc.solveExpression(f22); @@ -550,8 +550,8 @@ public class MathInputScreen extends Screen { try { try { showVariablesDialog(); - ArrayList results = new ArrayList<>(); - final ArrayList partialResults = new ArrayList<>(); + ObjectArrayList results = new ObjectArrayList<>(); + final ObjectArrayList partialResults = new ObjectArrayList<>(); for (final Function f : calc.f2) { if (f instanceof Equation) { DisplayManager.INSTANCE.setScreen(new SolveEquationScreen(this)); @@ -565,7 +565,7 @@ public class MathInputScreen extends Screen { partialResults.add(itm); } } - results = new ArrayList<>(partialResults); + results = new ObjectArrayList<>(partialResults); partialResults.clear(); } } @@ -582,7 +582,7 @@ public class MathInputScreen extends Screen { results.addAll(hs); calc.f2 = results; for (final Function rf : calc.f2) { - rf.recomputeDimensions(); + rf.recomputeDimensions(null); } } Utils.debug.println(calc.f2.toString()); @@ -612,7 +612,7 @@ public class MathInputScreen extends Screen { } } - final ArrayList results = solveExpression(calc.f); + final ObjectArrayList results = solveExpression(calc.f); if (results.size() == 0) { calc.resultsCount = 0; } else { @@ -625,7 +625,7 @@ public class MathInputScreen extends Screen { results.addAll(hs); calc.f2 = results; for (final Function rf : calc.f2) { - rf.recomputeDimensions(); + rf.recomputeDimensions(null); } } } catch (final Exception ex) { @@ -685,7 +685,7 @@ public class MathInputScreen extends Screen { public void showVariablesDialog(final Runnable runnable) { final Thread ct = new Thread(() -> { - final ArrayList knownVarsInFunctions = getKnownVariables(calc.f.toArray(new Function[calc.f.size()])); + final ObjectArrayList knownVarsInFunctions = getKnownVariables(calc.f.toArray(new Function[calc.f.size()])); for (final VariableValue f : calc.variablesValues) { if (knownVarsInFunctions.contains(f.v)) { knownVarsInFunctions.remove(f.v); @@ -727,8 +727,8 @@ public class MathInputScreen extends Screen { ct.start(); } - private ArrayList getKnownVariables(Function[] fncs) { - final ArrayList res = new ArrayList<>(); + private ObjectArrayList getKnownVariables(Function[] fncs) { + final ObjectArrayList res = new ObjectArrayList<>(); for (final Function f : fncs) { if (f instanceof FunctionOperator) { res.addAll(getKnownVariables(new Function[] { ((FunctionOperator) f).getParameter1(), ((FunctionOperator) f).getParameter2() })); diff --git a/src/org/warp/picalculator/math/FunctionDynamic.java b/src/org/warp/picalculator/math/FunctionDynamic.java index b4c8f51d..186ca418 100644 --- a/src/org/warp/picalculator/math/FunctionDynamic.java +++ b/src/org/warp/picalculator/math/FunctionDynamic.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.Arrays; import java.util.List; @@ -103,7 +103,7 @@ public abstract class FunctionDynamic implements Function { protected abstract boolean isSolvable(); @Override - public final ArrayList simplify() throws Error { + public final ObjectArrayList simplify() throws Error { boolean solved = true; Function[] fncs = getParameters(); for (Function f : fncs) { @@ -112,14 +112,14 @@ public abstract class FunctionDynamic implements Function { break; } } - ArrayList result = solved ? solve() : null; + ObjectArrayList result = solved ? solve() : null; if (result == null || result.isEmpty()) { - result = new ArrayList<>(); + result = new ObjectArrayList<>(); - final ArrayList> ln = new ArrayList<>(); + final ObjectArrayList> ln = new ObjectArrayList<>(); for (int i = 0; i < fncs.length; i++) { - ArrayList l = new ArrayList<>(); + ObjectArrayList l = new ObjectArrayList<>(); if (fncs[i].isSimplified()) { l.add(fncs[i]); } else { @@ -143,7 +143,7 @@ public abstract class FunctionDynamic implements Function { * @return The solved function. * @throws Error Errors during computation, like a/0 or similar. */ - protected abstract ArrayList solve() throws Error; + protected abstract ObjectArrayList solve() throws Error; @Override public MathContext getMathContext() { diff --git a/src/org/warp/picalculator/math/FunctionOperator.java b/src/org/warp/picalculator/math/FunctionOperator.java index aff12093..84368607 100644 --- a/src/org/warp/picalculator/math/FunctionOperator.java +++ b/src/org/warp/picalculator/math/FunctionOperator.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; @@ -114,15 +114,15 @@ public abstract class FunctionOperator implements Function { protected abstract boolean isSolvable(); @Override - public final ArrayList simplify() throws Error { + public final ObjectArrayList simplify() throws Error { final boolean solved = parameter1.isSimplified() & parameter2.isSimplified(); - ArrayList result = solved ? solve() : null;; + ObjectArrayList result = solved ? solve() : null;; if (result == null || result.isEmpty()) { - result = new ArrayList<>(); + result = new ObjectArrayList<>(); - final ArrayList l1 = new ArrayList<>(); - final ArrayList l2 = new ArrayList<>(); + final ObjectArrayList l1 = new ObjectArrayList<>(); + final ObjectArrayList l2 = new ObjectArrayList<>(); if (parameter1.isSimplified()) { l1.add(parameter1); } else { @@ -149,7 +149,7 @@ public abstract class FunctionOperator implements Function { * @return The solved function. * @throws Error Errors during computation, like a/0 or similar. */ - protected abstract ArrayList solve() throws Error; + protected abstract ObjectArrayList solve() throws Error; @Override public abstract FunctionOperator clone(); diff --git a/src/org/warp/picalculator/math/FunctionSingle.java b/src/org/warp/picalculator/math/FunctionSingle.java index e9ec6d52..0eb9678d 100644 --- a/src/org/warp/picalculator/math/FunctionSingle.java +++ b/src/org/warp/picalculator/math/FunctionSingle.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; @@ -26,7 +26,7 @@ public abstract class FunctionSingle implements Function { parameter = value; } - private final MathContext mathContext; + protected final MathContext mathContext; /** * Function parameter.
@@ -76,14 +76,14 @@ public abstract class FunctionSingle implements Function { } @Override - public final ArrayList simplify() throws Error { + public final ObjectArrayList simplify() throws Error { final boolean simplified = parameter.isSimplified(); - ArrayList result = simplified ? solve() : null; + ObjectArrayList result = simplified ? solve() : null; if (result == null || result.isEmpty()) { - result = new ArrayList<>(); + result = new ObjectArrayList<>(); - final ArrayList l1 = new ArrayList<>(); + final ObjectArrayList l1 = new ObjectArrayList<>(); if (parameter.isSimplified()) { l1.add(parameter); } else { @@ -104,7 +104,7 @@ public abstract class FunctionSingle implements Function { * @return The solved function. * @throws Error Errors during computation, like a/0 or similar. */ - protected abstract ArrayList solve() throws Error; + protected abstract ObjectArrayList solve() throws Error; @Override public boolean isSimplified() { diff --git a/src/org/warp/picalculator/math/MathContext.java b/src/org/warp/picalculator/math/MathContext.java index eb335446..b3644c7f 100644 --- a/src/org/warp/picalculator/math/MathContext.java +++ b/src/org/warp/picalculator/math/MathContext.java @@ -1,7 +1,6 @@ package org.warp.picalculator.math; import java.math.BigInteger; -import java.util.ArrayList; import java.util.List; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; @@ -12,19 +11,22 @@ import org.warp.picalculator.math.functions.Variable.VariableValue; import org.warp.picalculator.math.functions.equations.Equation; import org.warp.picalculator.math.functions.equations.EquationsSystem; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + + public class MathContext { public AngleMode angleMode = AngleMode.DEG; public boolean exactMode = false; - public ArrayList f; - public ArrayList f2; - public ArrayList variablesValues; + public ObjectArrayList f; + public ObjectArrayList f2; + public ObjectArrayList variablesValues; public int resultsCount; public MathContext() { - f = new ArrayList<>(); - f2 = new ArrayList<>(); - variablesValues = new ArrayList<>(); + f = new ObjectArrayList<>(); + f2 = new ObjectArrayList<>(); + variablesValues = new ObjectArrayList<>(); resultsCount = 0; } @@ -57,9 +59,9 @@ public class MathContext { } } - public ArrayList solveExpression(ArrayList input) throws Error { - ArrayList results = new ArrayList<>(); - final ArrayList partialResults = new ArrayList<>(); + public ObjectArrayList solveExpression(ObjectArrayList input) throws Error { + ObjectArrayList results = new ObjectArrayList<>(); + final ObjectArrayList partialResults = new ObjectArrayList<>(); for (final Function f : input) { if (f instanceof Equation) { throw new IllegalArgumentException("Not an expression!"); @@ -79,7 +81,7 @@ public class MathContext { partialResults.add(itm); } } - results = new ArrayList<>(partialResults); + results = new ObjectArrayList<>(partialResults); partialResults.clear(); } } @@ -93,15 +95,15 @@ public class MathContext { public void init() { if (f == null & f2 == null) { - f = new ArrayList<>(); - f2 = new ArrayList<>(); - variablesValues = new ArrayList<>(); + f = new ObjectArrayList<>(); + f2 = new ObjectArrayList<>(); + variablesValues = new ObjectArrayList<>(); resultsCount = 0; } } public void parseInputString(String eqn) throws Error { - final ArrayList fncs = new ArrayList<>(); + final ObjectArrayList fncs = new ObjectArrayList<>(); if (eqn.length() > 0) { try { fncs.add(parseString(eqn.replace("sqrt", MathematicalSymbols.SQUARE_ROOT).replace("^", MathematicalSymbols.POWER))); @@ -115,7 +117,7 @@ public class MathContext { /*public void solve(EquationScreen equationScreen, char letter) throws Error { if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) { EquationScreen es = (EquationScreen) Calculator.sessions[0]; - ArrayList f = es.f; + ObjectArrayList f = es.f; if (f instanceof Equation) { List results = ((Equation)f).solve(letter); Collections.reverse(results); diff --git a/src/org/warp/picalculator/math/MathematicalSymbols.java b/src/org/warp/picalculator/math/MathematicalSymbols.java index 1ff4e60a..61ead678 100644 --- a/src/org/warp/picalculator/math/MathematicalSymbols.java +++ b/src/org/warp/picalculator/math/MathematicalSymbols.java @@ -5,60 +5,53 @@ import static org.warp.picalculator.Utils.concat; import org.warp.picalculator.Utils; public class MathematicalSymbols { - public static final String SUM = "+"; - public static final String SUM_SUBTRACTION = "±"; - public static final String SUBTRACTION = "−"; - public static final String MINUS = "-"; - public static final String MULTIPLICATION = "*"; - public static final String DIVISION = "/"; - public static final String NTH_ROOT = "√"; - public static final String SQUARE_ROOT = "Ⓐ"; - public static final String PARENTHESIS_OPEN = "("; - public static final String PARENTHESIS_CLOSE = ")"; - public static final String POWER = "Ⓑ"; - public static final String EQUATION = "="; - public static final String SYSTEM = "{"; - public static final String SINE = "Ⓒ"; - public static final String COSINE = "Ⓓ"; - public static final String TANGENT = "Ⓔ"; - public static final String ARC_SINE = "Ⓕ"; - public static final String ARC_COSINE = "Ⓖ"; - public static final String ARC_TANGENT = "Ⓗ"; - public static final String PI = "π"; + public static final char SUM = '+'; + public static final char SUM_SUBTRACTION = '±'; + public static final char SUBTRACTION = '−'; + public static final char MINUS = '-'; + public static final char MULTIPLICATION = '*'; + public static final char DIVISION = '/'; + public static final char NTH_ROOT = '√'; + public static final char SQUARE_ROOT = 'Ⓐ'; + public static final char PARENTHESIS_OPEN = '('; + public static final char PARENTHESIS_CLOSE = ')'; + public static final char POWER = 'Ⓑ'; + public static final char EQUATION = '='; + public static final char SYSTEM = '{'; + public static final char SINE = 'Ⓒ'; + public static final char COSINE = 'Ⓓ'; + public static final char TANGENT = 'Ⓔ'; + public static final char ARC_SINE = 'Ⓕ'; + public static final char ARC_COSINE = 'Ⓖ'; + public static final char ARC_TANGENT = 'Ⓗ'; + public static final char PI = 'π'; - public static final String[] functions() { - return concat(functionsNSN(), functionsSN()); - } - public static final String[] functionsNSN() { - return new String[] { NTH_ROOT, POWER }; - } + public static final char[] functionsNSN = new char[] { NTH_ROOT, POWER }; - public static final String[] functionsSN() { - return new String[] { SQUARE_ROOT, MINUS, SINE, COSINE, TANGENT, ARC_SINE, ARC_COSINE, ARC_TANGENT }; - } + public static final char[] functionsSN = new char[] { SQUARE_ROOT, MINUS, SINE, COSINE, TANGENT, ARC_SINE, ARC_COSINE, ARC_TANGENT }; - public static final String[] signums(boolean withMultiplication) { - String[] ret = new String[] { SUM, SUM_SUBTRACTION, SUBTRACTION, DIVISION }; + public static final char[] functions = concat(functionsNSN, functionsSN); + + private static final char[] signumsWithoutMultiplication = new char[] { SUM, SUM_SUBTRACTION, SUBTRACTION, DIVISION }; + private static final char[] signumsWithMultiplication = Utils.add(signumsWithoutMultiplication, MULTIPLICATION); + + public static final char[] signums(boolean withMultiplication) { if (withMultiplication) { - ret = Utils.add(ret, MULTIPLICATION); + return signumsWithMultiplication; } - return ret; + return signumsWithoutMultiplication; } - public static final String[] parentheses() { - return new String[] { PARENTHESIS_OPEN, PARENTHESIS_CLOSE }; - } + public static final char[] parentheses = new char[] { PARENTHESIS_OPEN, PARENTHESIS_CLOSE }; - public static String[] variables() { - return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "ⓧ", "Ⓨ", "Z", PI }; - } + public static final char[] variables = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'ⓧ', 'Ⓨ', 'Z', PI }; - public static String[] genericSyntax() { - return new String[] { SYSTEM, EQUATION }; - } + public static final char[] genericSyntax = new char[] { SYSTEM, EQUATION }; public static String getGraphicRepresentation(String string) { return string.replace("Ⓑ", "^").replace("Ⓒ", "SIN").replace("Ⓓ", "COS").replace("Ⓔ", "TAN").replace("Ⓕ", "ASIN").replace("Ⓖ", "ACOS").replace("Ⓗ", "ATAN"); } + + public static final char[] numbers = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; } diff --git a/src/org/warp/picalculator/math/SolveMethod.java b/src/org/warp/picalculator/math/SolveMethod.java index a075b139..b79ec8ba 100644 --- a/src/org/warp/picalculator/math/SolveMethod.java +++ b/src/org/warp/picalculator/math/SolveMethod.java @@ -1,11 +1,11 @@ package org.warp.picalculator.math; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.math.functions.equations.Equation; public interface SolveMethod { public static final SolveMethod[] techniques = new SolveMethod[] {}; - public abstract ArrayList solve(Equation equation); + public abstract ObjectArrayList solve(Equation equation); } diff --git a/src/org/warp/picalculator/math/functions/Division.java b/src/org/warp/picalculator/math/functions/Division.java index 549f41ff..f0b44106 100644 --- a/src/org/warp/picalculator/math/functions/Division.java +++ b/src/org/warp/picalculator/math/functions/Division.java @@ -1,12 +1,12 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; +import org.warp.picalculator.gui.expression.GraphicalElement; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; -import org.warp.picalculator.gui.math.GraphicalElement; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; @@ -61,10 +61,10 @@ public class Division extends FunctionOperator { } @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { Function variable1 = getParameter1(); Function variable2 = getParameter2(); - ArrayList result = new ArrayList<>(); + ObjectArrayList result = new ObjectArrayList<>(); if (FractionsRule1.compare(this)) { result = FractionsRule1.execute(this); } else if (FractionsRule2.compare(this)) { diff --git a/src/org/warp/picalculator/math/functions/EmptyNumber.java b/src/org/warp/picalculator/math/functions/EmptyNumber.java index f9ab9ce7..805802bf 100644 --- a/src/org/warp/picalculator/math/functions/EmptyNumber.java +++ b/src/org/warp/picalculator/math/functions/EmptyNumber.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; @@ -20,7 +20,7 @@ public class EmptyNumber implements Function { @Override - public ArrayList simplify() throws Error { + public ObjectArrayList simplify() throws Error { // TODO Auto-generated method stub return null; } diff --git a/src/org/warp/picalculator/math/functions/Expression.java b/src/org/warp/picalculator/math/functions/Expression.java index b82fb8f7..6aecf16c 100644 --- a/src/org/warp/picalculator/math/functions/Expression.java +++ b/src/org/warp/picalculator/math/functions/Expression.java @@ -4,7 +4,7 @@ import static org.warp.picalculator.Utils.ArrayToRegex; import static org.warp.picalculator.Utils.concat; import java.math.BigDecimal; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -141,7 +141,7 @@ public class Expression extends FunctionDynamic { } // Rimuovi i + in eccesso - pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions()), "(")) + "]\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]+?[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions())) + "]|[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions())) + "]+?\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]"); + pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions), '(')) + "]\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions), new char[] { '(', ')' })) + "]+?[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions)) + "]|[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions)) + "]+?\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions), new char[] { '(', ')' })) + "]"); matcher = pattern.matcher(processExpression); symbolsChanged = false; while (matcher.find()) { @@ -152,14 +152,14 @@ public class Expression extends FunctionDynamic { } // Correggi i segni - in − - processExpression = processExpression.replace("-", MathematicalSymbols.SUBTRACTION); + processExpression = processExpression.replace('-', MathematicalSymbols.SUBTRACTION); // Correggi i segni − dopo di espressioni o funzioni SN in - - pattern = Pattern.compile("[" + Utils.ArrayToRegex(concat(concat(MathematicalSymbols.functions(), new String[] { MathematicalSymbols.PARENTHESIS_OPEN }), MathematicalSymbols.signums(true))) + "]" + MathematicalSymbols.SUBTRACTION); + pattern = Pattern.compile("[" + Utils.ArrayToRegex(concat(concat(MathematicalSymbols.functions, new char[] { MathematicalSymbols.PARENTHESIS_OPEN }), MathematicalSymbols.signums(true))) + "]" + MathematicalSymbols.SUBTRACTION); matcher = pattern.matcher(processExpression); while (matcher.find()) { symbolsChanged = true; - final String correzione = MathematicalSymbols.MINUS; + final char correzione = MathematicalSymbols.MINUS; processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + 2, processExpression.length()); matcher = pattern.matcher(processExpression); } @@ -196,11 +196,11 @@ public class Expression extends FunctionDynamic { String beforeexp = processExpression.substring(0, matcher.start(0)); final String newexp = matcher.group(0).substring(1, matcher.group(0).length() - 1); String afterexp = processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length()); - if (Pattern.compile("[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), "(")) + "]$").matcher(beforeexp).find()) { + if (Pattern.compile("[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions, concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax)), '(')) + "]$").matcher(beforeexp).find()) { // Se la stringa precedente finisce con un numero beforeexp += MathematicalSymbols.MULTIPLICATION; } - if (Pattern.compile("^[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), ")")) + "]").matcher(afterexp).find()) { + if (Pattern.compile("^[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions, concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax)), ')')) + "]").matcher(afterexp).find()) { // Se la stringa successiva inizia con un numero afterexp = MathematicalSymbols.MULTIPLICATION + afterexp; } @@ -222,10 +222,10 @@ public class Expression extends FunctionDynamic { Expression imputRawParenthesis = new Expression(root); imputRawParenthesis = (Expression) imputRawParenthesis.setParameters(new Function[] {}); String tmp = ""; - final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax()); + final char[] functions = concat(concat(concat(concat(MathematicalSymbols.functions, MathematicalSymbols.parentheses), MathematicalSymbols.signums(true)), MathematicalSymbols.variables), MathematicalSymbols.genericSyntax); for (int i = 0; i < processExpression.length(); i++) { // Per ogni carattere cerca se è un numero o una funzione: - final String charI = processExpression.charAt(i) + ""; + final char charI = processExpression.charAt(i); if (Utils.isInArray(charI, functions)) { // Finds the type of function fron the following list @@ -291,14 +291,14 @@ public class Expression extends FunctionDynamic { } else if (jumps > 0) { jumps -= 1; } else if (jumps < 0) { - throw new Error(Errors.UNBALANCED_BRACKETS); + throw new Error(Errors.UNBALANCED_STACK); } } else if ((processExpression.charAt(i2) + "").equals(MathematicalSymbols.PARENTHESIS_OPEN)) { jumps += 1; } } if (endIndex == -1 || endIndex < startIndex) { - throw new Error(Errors.UNBALANCED_BRACKETS); + throw new Error(Errors.UNBALANCED_STACK); } startIndex += 1; i = startIndex; @@ -311,11 +311,11 @@ public class Expression extends FunctionDynamic { f = new Expression(root, tmpExpr, debugSpaces, false); break; default: - if (Utils.isInArray(charI, MathematicalSymbols.variables())) { + if (Utils.isInArray(charI, MathematicalSymbols.variables)) { f = new Variable(root, charI, Variable.V_TYPE.UNKNOWN); } else { - if (charI == "(" || charI == ")") { - throw new Error(Errors.UNBALANCED_BRACKETS); + if (charI == '(' || charI == ')') { + throw new Error(Errors.UNBALANCED_STACK); } else { System.err.println("Unexpected character while parsing expression: " + charI); throw new Error(Errors.SYNTAX_ERROR); @@ -368,7 +368,7 @@ public class Expression extends FunctionDynamic { tmp = ""; } else { try { - if (charI.equals("-") == false && charI.equals(".") == false) { + if (charI != '-' && charI != '.') { new BigDecimal(tmp + charI); } // Se il carattere è un numero intero, un segno @@ -415,7 +415,7 @@ public class Expression extends FunctionDynamic { Utils.debug.println(debugSpaces + "•Pushing classes..."); final Function[] oldFunctionsArray = imputRawParenthesis.getParameters(); - final ArrayList oldFunctionsList = new ArrayList<>(); + final ObjectArrayList oldFunctionsList = new ObjectArrayList<>(); for (int i = 0; i < oldFunctionsArray.length; i++) { Function funzione = oldFunctionsArray[i]; if (funzione != null) { @@ -570,8 +570,8 @@ public class Expression extends FunctionDynamic { } @Override - public ArrayList solve() throws Error { - final ArrayList ret = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + final ObjectArrayList ret = new ObjectArrayList<>(); if (getParametersLength() == 1) { if (getParameter(0).isSimplified() || !parenthesisNeeded()) { ret.add(getParameter(0)); @@ -629,7 +629,11 @@ public class Expression extends FunctionDynamic { String s = "("; if (functions.length > 0) { for (Function f : functions) { - s+=f.toString()+","; + if (f == null) { + s+="[null],"; + } else { + s+=f.toString()+","; + } } s = s.substring(0, s.length()-1); } diff --git a/src/org/warp/picalculator/math/functions/Joke.java b/src/org/warp/picalculator/math/functions/Joke.java index 312125f3..b828b4be 100644 --- a/src/org/warp/picalculator/math/functions/Joke.java +++ b/src/org/warp/picalculator/math/functions/Joke.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; @@ -27,7 +27,7 @@ public class Joke implements Function { } @Override - public ArrayList simplify() throws Error { + public ObjectArrayList simplify() throws Error { return null; } diff --git a/src/org/warp/picalculator/math/functions/Multiplication.java b/src/org/warp/picalculator/math/functions/Multiplication.java index 8dffd225..283f89d6 100644 --- a/src/org/warp/picalculator/math/functions/Multiplication.java +++ b/src/org/warp/picalculator/math/functions/Multiplication.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -62,8 +62,8 @@ public class Multiplication extends FunctionOperator { } @Override - public ArrayList solve() throws Error { - ArrayList result = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + ObjectArrayList result = new ObjectArrayList<>(); if (SyntaxRule1.compare(this)) { result = SyntaxRule1.execute(this); } else if (NumberRule1.compare(this)) { diff --git a/src/org/warp/picalculator/math/functions/Negative.java b/src/org/warp/picalculator/math/functions/Negative.java index d4207281..0605820f 100644 --- a/src/org/warp/picalculator/math/functions/Negative.java +++ b/src/org/warp/picalculator/math/functions/Negative.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; @@ -20,29 +20,9 @@ public class Negative extends FunctionSingle { super(root, value); } - @Override - public Function NewInstance(MathContext root, Function value) { - return new Negative(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.MINUS; - } - - @Override - public void recomputeDimensions() { - variable.setSmall(small); - variable.recomputeDimensions(); - - height = getParameter().getHeight(); - width = Utils.getFont(small).getCharacterWidth() /* Width of - */ + getParameter().getWidth(); - line = getParameter().getLine(); - } - @Override protected boolean isSolvable() { - if (variable instanceof Number) { + if (parameter instanceof Number) { return true; } if (ExpandRule1.compare(this)) { @@ -55,16 +35,16 @@ public class Negative extends FunctionSingle { } @Override - public ArrayList solve() throws Error { - if (variable == null) { + public ObjectArrayList solve() throws Error { + if (parameter == null) { throw new Error(Errors.SYNTAX_ERROR); } - ArrayList result = new ArrayList<>(); + ObjectArrayList result = new ObjectArrayList<>(); if (ExpandRule1.compare(this)) { result = ExpandRule1.execute(this); } else if (ExpandRule5.compare(this)) { result = ExpandRule5.execute(this); - } else if (variable.isSimplified()) { + } else if (parameter.isSimplified()) { try { final Number var = (Number) getParameter(); result.add(var.multiply(new Number(mathContext, "-1"))); @@ -76,11 +56,11 @@ public class Negative extends FunctionSingle { throw new Error(Errors.NUMBER_TOO_SMALL); } } else { - final ArrayList l1 = new ArrayList<>(); - if (variable.isSimplified()) { - l1.add(variable); + final ObjectArrayList l1 = new ObjectArrayList<>(); + if (parameter.isSimplified()) { + l1.add(parameter); } else { - l1.addAll(variable.simplify()); + l1.addAll(parameter.simplify()); } for (final Function f : l1) { @@ -90,26 +70,16 @@ public class Negative extends FunctionSingle { return result; } - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - @Override public boolean equals(Object o) { if (o instanceof Negative) { - return ((Negative) o).variable.equals(variable); + return ((Negative) o).getParameter().equals(parameter); } return false; } + + @Override + public Negative clone() { + return new Negative(mathContext, parameter); + } } diff --git a/src/org/warp/picalculator/math/functions/Number.java b/src/org/warp/picalculator/math/functions/Number.java index f8bc20e3..2159920a 100644 --- a/src/org/warp/picalculator/math/functions/Number.java +++ b/src/org/warp/picalculator/math/functions/Number.java @@ -2,7 +2,7 @@ package org.warp.picalculator.math.functions; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.LinkedList; import java.util.List; @@ -121,7 +121,7 @@ public class Number implements Function { @Override public List simplify() throws Error { - final List result = new ArrayList<>(); + final List result = new ObjectArrayList<>(); if (root.exactMode) { Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces())); Number numb = new Number(root, term.multiply(divisor.term)); diff --git a/src/org/warp/picalculator/math/functions/Power.java b/src/org/warp/picalculator/math/functions/Power.java index 8a758107..b4b158ee 100644 --- a/src/org/warp/picalculator/math/functions/Power.java +++ b/src/org/warp/picalculator/math/functions/Power.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -55,8 +55,8 @@ public class Power extends FunctionOperator { } @Override - public ArrayList solve() throws Error { - final ArrayList result = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); if (UndefinedRule1.compare(this)) { result.addAll(UndefinedRule1.execute(this)); } else if (ExponentRule1.compare(this)) { diff --git a/src/org/warp/picalculator/math/functions/Root.java b/src/org/warp/picalculator/math/functions/Root.java index 57159435..6cafb7ed 100644 --- a/src/org/warp/picalculator/math/functions/Root.java +++ b/src/org/warp/picalculator/math/functions/Root.java @@ -2,7 +2,7 @@ package org.warp.picalculator.math.functions; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.gui.DisplayManager; @@ -17,29 +17,6 @@ public class Root extends FunctionOperator { super(root, value1, value2); } - @Override - protected Function NewInstance(MathContext root, Function value1, Function value2) { - return new Root(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.NTH_ROOT; - } - - @Override - public void generateGraphics() { - parameter1.setSmall(true); - parameter1.recomputeDimensions(); - - parameter2.setSmall(small); - parameter2.recomputeDimensions(); - - width = 1 + parameter1.getWidth() + 2 + parameter2.getWidth() + 2; - height = parameter1.getHeight() + parameter2.getHeight() - 2; - line = parameter1.getHeight() + parameter2.getLine() - 2; - } - @Override protected boolean isSolvable() { if (parameter1 instanceof Number & parameter2 instanceof Number) { @@ -65,8 +42,8 @@ public class Root extends FunctionOperator { } @Override - public ArrayList solve() throws Error { - final ArrayList result = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); if (mathContext.exactMode) { if (parameter1 instanceof Number && ((Number) parameter1).equals(new Number(mathContext, 2))) { result.add(new RootSquare(mathContext, parameter2)); @@ -83,52 +60,19 @@ public class Root extends FunctionOperator { } return result; } - - @Override - public void draw(int x, int y, boolean small, int caretPos) { -// glColor3f(0, 255, 0); -// glFillRect(x,y,width,height); -// glColor3f(0, 0, 0); - - final int w1 = getVariable2().getWidth(); - final int h1 = getVariable2().getHeight(); - final int w2 = getParameter1().getWidth(); - final int h2 = getParameter1().getHeight(); - final int height = getHeight(); - final int hh = (int) Math.ceil((double) h1 / 2); - - getParameter1().draw(x + 1, y, null, null); - getVariable2().draw(x + 1 + w2 + 2, y + h2 - 2, null, null); - - DisplayManager.renderer.glDrawLine(x + 1 + w2 - 2, y + height - 2, x + 1 + w2 - 2, y + height - 2); - DisplayManager.renderer.glDrawLine(x + 1 + w2 - 1, y + height - 1, x + 1 + w2 - 1, y + height - 1); - DisplayManager.renderer.glDrawLine(x + 1 + w2 - 0, y + height - 0, x + 1 + w2 - 0, y + height - 0); - DisplayManager.renderer.glDrawLine(x + 1 + w2, y + height - 1 - hh, x + 1 + w2, y + height - 1); - DisplayManager.renderer.glDrawLine(x + 1 + w2 + 1, y + height - 2 - h1, x + 1 + w2 + 1, y + height - 1 - hh - 1); - DisplayManager.renderer.glDrawLine(x + 1 + w2 + 1, y + height - h1 - 2, x + 1 + w2 + 2 + w1 + 1, y + height - h1 - 2); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - + @Override public boolean equals(Object o) { if (o instanceof Root) { final FunctionOperator f = (FunctionOperator) o; - return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2); + return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2()); } return false; } + + @Override + public Root clone() { + return new Root(mathContext, parameter1, parameter2); + } + } diff --git a/src/org/warp/picalculator/math/functions/RootSquare.java b/src/org/warp/picalculator/math/functions/RootSquare.java index 1896fe50..aadc44b5 100644 --- a/src/org/warp/picalculator/math/functions/RootSquare.java +++ b/src/org/warp/picalculator/math/functions/RootSquare.java @@ -1,7 +1,7 @@ package org.warp.picalculator.math.functions; import java.math.BigInteger; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; @@ -16,38 +16,18 @@ public class RootSquare extends FunctionSingle { super(root, value); } - @Override - public Function NewInstance(MathContext root, Function value) { - return new RootSquare(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.SQUARE_ROOT; - } - - @Override - public void recomputeDimensions() { - variable.setSmall(small); - variable.recomputeDimensions(); - - height = getParameter().getHeight() + 2; - width = 1 + 4 + getParameter().getWidth() + 1; - line = getParameter().getLine() + 2; - } - @Override protected boolean isSolvable() { - if (variable instanceof Number) { + if (parameter instanceof Number) { if (mathContext.exactMode == false) { return true; } try { Number exponent = new Number(mathContext, BigInteger.ONE); exponent = exponent.divide(new Number(mathContext, 2)); - final Number resultVal = ((Number) variable).pow(exponent); + final Number resultVal = ((Number) parameter).pow(exponent); final Number originalVariable = resultVal.pow(new Number(mathContext, 2)); - if (originalVariable.equals(variable)) { + if (originalVariable.equals(parameter)) { return true; } } catch (Exception | Error ex) { @@ -58,50 +38,31 @@ public class RootSquare extends FunctionSingle { } @Override - public ArrayList solve() throws Error { - final ArrayList result = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); if (mathContext.exactMode) { Number exponent = new Number(mathContext, BigInteger.ONE); exponent = exponent.divide(new Number(mathContext, 2)); - result.add(((Number) variable).pow(exponent)); + result.add(((Number) parameter).pow(exponent)); } else { final Number exp = new Number(mathContext, 2); - final Number numb = (Number) variable; + final Number numb = (Number) parameter; result.add(numb.pow(new Number(mathContext, 1).divide(exp))); } return result; } - @Override - public int draw(int x, int y, boolean small, int caretPos) { -// glColor3f(0, 255, 0); -// glFillRect(x,y,width,height); -// glColor3f(0, 0, 0); - - Utils.writeSquareRoot(getParameter(), x, y, small); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - @Override public boolean equals(Object o) { if (o instanceof RootSquare) { - return ((RootSquare) o).variable.equals(variable); + return ((RootSquare) o).getParameter().equals(parameter); } return false; } + + @Override + public RootSquare clone() { + return new RootSquare(mathContext, parameter); + } } diff --git a/src/org/warp/picalculator/math/functions/Subtraction.java b/src/org/warp/picalculator/math/functions/Subtraction.java index 6ec25c9e..d5e08774 100644 --- a/src/org/warp/picalculator/math/functions/Subtraction.java +++ b/src/org/warp/picalculator/math/functions/Subtraction.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -22,16 +22,6 @@ public class Subtraction extends FunctionOperator { super(root, value1, value2); } - @Override - protected Function NewInstance(MathContext root, Function value1, Function value2) { - return new Subtraction(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.SUBTRACTION; - } - @Override protected boolean isSolvable() { if (parameter1 instanceof Number & parameter2 instanceof Number) { @@ -65,8 +55,8 @@ public class Subtraction extends FunctionOperator { } @Override - public ArrayList solve() throws Error { - ArrayList result = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + ObjectArrayList result = new ObjectArrayList<>(); if (VariableRule1.compare(this)) { result = VariableRule1.execute(this); } else if (VariableRule2.compare(this)) { @@ -93,8 +83,14 @@ public class Subtraction extends FunctionOperator { public boolean equals(Object o) { if (o instanceof Subtraction) { final FunctionOperator f = (FunctionOperator) o; - return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2); + return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2()); } return false; } + + @Override + public Subtraction clone() { + return new Subtraction(mathContext, parameter1, parameter2); + } + } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/Sum.java b/src/org/warp/picalculator/math/functions/Sum.java index 525cd99b..749e2d9e 100644 --- a/src/org/warp/picalculator/math/functions/Sum.java +++ b/src/org/warp/picalculator/math/functions/Sum.java @@ -1,7 +1,7 @@ package org.warp.picalculator.math.functions; import java.math.BigDecimal; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; @@ -59,11 +59,11 @@ public class Sum extends FunctionOperator { } @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { if (parameter1 == null || parameter2 == null) { throw new Error(Errors.SYNTAX_ERROR); } - ArrayList result = new ArrayList<>(); + ObjectArrayList result = new ObjectArrayList<>(); if (SyntaxRule2.compare(this)) { result = SyntaxRule2.execute(this); } else if (VariableRule1.compare(this)) { diff --git a/src/org/warp/picalculator/math/functions/SumSubtraction.java b/src/org/warp/picalculator/math/functions/SumSubtraction.java index dd017aa2..ab3d171b 100644 --- a/src/org/warp/picalculator/math/functions/SumSubtraction.java +++ b/src/org/warp/picalculator/math/functions/SumSubtraction.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; @@ -22,16 +22,6 @@ public class SumSubtraction extends FunctionOperator { super(root, value1, value2); } - @Override - protected Function NewInstance(MathContext root, Function value1, Function value2) { - return new SumSubtraction(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.SUM_SUBTRACTION; - } - @Override protected boolean isSolvable() { if (parameter1 instanceof Number & parameter2 instanceof Number) { @@ -53,11 +43,11 @@ public class SumSubtraction extends FunctionOperator { } @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { if (parameter1 == null || parameter2 == null) { throw new Error(Errors.SYNTAX_ERROR); } - ArrayList result = new ArrayList<>(); + ObjectArrayList result = new ObjectArrayList<>(); if (NumberRule3.compare(this)) { result = NumberRule3.execute(this); } else if (ExpandRule1.compare(this)) { @@ -73,56 +63,18 @@ public class SumSubtraction extends FunctionOperator { return result; } - @Override - public void generateGraphics() { - parameter1.setSmall(small); - parameter1.recomputeDimensions(); - - parameter2.setSmall(small); - parameter2.recomputeDimensions(); - - width = calcWidth(); - height = calcHeight(); - line = calcLine(); - } - - @Override - public void draw(int x, int y, boolean small, int caretPos) { -// glColor3f(127, 127-50+new Random().nextInt(50), 255); -// glFillRect(x,y,width,height); -// glColor3f(0, 0, 0); - - final int ln = getLine(); - int dx = 0; - parameter1.draw(dx + x, ln - parameter1.getLine() + y, null, null); - dx += parameter1.getWidth(); - Utils.getFont(small).use(DisplayManager.engine); - dx += 1; - DisplayManager.renderer.glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol()); - dx += Utils.getFont(small).getStringWidth(getSymbol()); - parameter2.draw(dx + x, ln - parameter2.getLine() + y, null, null); - } - - @Override - public int getWidth() { - return width; - } - - @Override - protected int calcWidth() { - int dx = 0; - dx += parameter1.getWidth(); - dx += 1; - dx += Utils.getFont(small).getStringWidth(getSymbol()); - return dx += parameter2.getWidth(); - } - @Override public boolean equals(Object o) { if (o instanceof SumSubtraction) { final FunctionOperator f = (FunctionOperator) o; - return parameter1.equals(f.parameter1) && parameter2.equals(f.parameter2); + return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2()); } return false; } + + @Override + public SumSubtraction clone() { + return new SumSubtraction(mathContext, parameter1, parameter2); + } + } diff --git a/src/org/warp/picalculator/math/functions/Undefined.java b/src/org/warp/picalculator/math/functions/Undefined.java index 93e5741f..e68d742f 100644 --- a/src/org/warp/picalculator/math/functions/Undefined.java +++ b/src/org/warp/picalculator/math/functions/Undefined.java @@ -16,63 +16,22 @@ public class Undefined implements Function { public Undefined(MathContext root) { this.root = root; } - + @Override - public String getSymbol() { - return "undefined"; - } - - @Override - public List solveOneStep() throws Error { + public List simplify() throws Error { return null; } @Override - public boolean isSolved() { + public boolean isSimplified() { return true; } - private int width, height, line; - private boolean small; - @Override - public void generateGraphics() { - width = Utils.getFont(small).getStringWidth("UNDEFINED"); - height = Utils.getFontHeight(small); - line = height / 2; - } - - @Override - public void draw(int x, int y) { - Utils.getFont(small).use(DisplayManager.engine); - DisplayManager.renderer.glDrawStringLeft(x, y, "UNDEFINED"); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; - } - - @Override - public MathContext getRoot() { + public MathContext getMathContext() { return root; } - @Override - public void setSmall(boolean small) { - this.small = small; - } - @Override public boolean equals(Object o) { if (o instanceof Undefined) { @@ -81,4 +40,19 @@ public class Undefined implements Function { return false; } + @Override + public Undefined clone() { + return new Undefined(root); + } + + @Override + public Function setParameter(int index, Function var) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + + @Override + public Function getParameter(int index) throws IndexOutOfBoundsException { + throw new IndexOutOfBoundsException(); + } + } diff --git a/src/org/warp/picalculator/math/functions/Variable.java b/src/org/warp/picalculator/math/functions/Variable.java index 8d346eb6..665e0098 100644 --- a/src/org/warp/picalculator/math/functions/Variable.java +++ b/src/org/warp/picalculator/math/functions/Variable.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; @@ -65,7 +65,7 @@ public class Variable implements Function { @Override public List simplify() throws Error { - final List result = new ArrayList<>(); + final List result = new ObjectArrayList<>(); result.add(this); return result; } diff --git a/src/org/warp/picalculator/math/functions/equations/Equation.java b/src/org/warp/picalculator/math/functions/equations/Equation.java index 10e0bc6f..b213b8c3 100644 --- a/src/org/warp/picalculator/math/functions/equations/Equation.java +++ b/src/org/warp/picalculator/math/functions/equations/Equation.java @@ -1,7 +1,7 @@ package org.warp.picalculator.math.functions.equations; import java.math.BigDecimal; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -23,17 +23,7 @@ public class Equation extends FunctionOperator { public Equation(MathContext root, Function value1, Function value2) { super(root, value1, value2); } - - @Override - protected Function NewInstance(MathContext root, Function value1, Function value2) { - return new Equation(root, value1, value2); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.EQUATION; - } - + @Override protected boolean isSolvable() { if (parameter1 instanceof Number & parameter2 instanceof Number) { @@ -43,11 +33,11 @@ public class Equation extends FunctionOperator { } @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { if (parameter1 == null || parameter2 == null) { throw new Error(Errors.SYNTAX_ERROR); } - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); if (parameter1.isSimplified() & parameter2.isSimplified()) { if (((Number) parameter2).getTerm().compareTo(new BigDecimal(0)) == 0) { result.add(this); @@ -63,18 +53,18 @@ public class Equation extends FunctionOperator { public List solve(char variableCharacter) { @SuppressWarnings("unused") - final ArrayList e; + final ObjectArrayList e; //TODO: WORK IN PROGRESS. //TODO: Finire. Fare in modo che risolva i passaggi fino a che non ce ne sono più return null; } //WORK IN PROGRESS - public ArrayList solveStep(char charIncognita) { - ArrayList result = new ArrayList<>(); + public ObjectArrayList solveStep(char charIncognita) { + ObjectArrayList result = new ObjectArrayList<>(); result.add(clone()); for (final SolveMethod t : SolveMethod.techniques) { - final ArrayList newResults = new ArrayList<>(); + final ObjectArrayList newResults = new ObjectArrayList<>(); final int sz = result.size(); for (int n = 0; n < sz; n++) { newResults.addAll(t.solve(result.get(n))); diff --git a/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java b/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java index af33e4ac..2cb972d9 100644 --- a/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java +++ b/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.equations; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; @@ -26,11 +26,6 @@ public class EquationsSystem extends FunctionDynamic { super(root, value); } - @Override - public String getSymbol() { - return null; - } - @Override protected boolean isSolvable() { if (functions.length >= 1) { @@ -40,8 +35,8 @@ public class EquationsSystem extends FunctionDynamic { } @Override - public List solveOneStep() throws Error { - final List ret = new ArrayList<>(); + public ObjectArrayList solve() throws Error { + final ObjectArrayList ret = new ObjectArrayList<>(); if (functions.length == 1) { if (functions[0].isSimplified()) { ret.add(functions[0]); @@ -71,63 +66,8 @@ public class EquationsSystem extends FunctionDynamic { } @Override - public void generateGraphics() { - for (final Function f : functions) { - f.setSmall(false); - f.recomputeDimensions(); - } - - width = 0; - for (final Function f : functions) { - if (f.getWidth() > width) { - width = f.getWidth(); - } - } - width += 5; - - height = 3; - for (final Function f : functions) { - height += f.getHeight() + spacing; - } - height = height - spacing + 2; - - line = height / 2; - } - - @Override - public void draw(int x, int y) { - - final int h = getHeight() - 1; - final int marginTop = 3; - final int marginBottom = (h - 3 - 2) / 2 + marginTop; - final int spazioSopra = h - marginBottom; - int dy = marginTop; - for (final Function f : functions) { - f.draw(x + 5, y + dy, null, null); - dy += f.getHeight() + spacing; - } - - 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); - } - - @Override - public int getWidth() { - return width; - } - - @Override - public int getHeight() { - return height; - } - - @Override - public int getLine() { - return line; + public EquationsSystem clone() { + return new EquationsSystem(root, functions); } + } diff --git a/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java b/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java index 649bbc12..e69a1cb5 100644 --- a/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java +++ b/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.equations; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; @@ -17,58 +17,7 @@ public class EquationsSystemPart extends FunctionSingle { } @Override - protected Function NewInstance(MathContext root, Function value) { - return new EquationsSystemPart(root, (Equation) value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.SYSTEM; - } - - @Override - public void recomputeDimensions() { - variable.setSmall(false); - variable.recomputeDimensions(); - - width = 5 + getParameter().getWidth(); - height = 3 + getParameter().getHeight() + 2; - line = 3 + getParameter().getLine(); - } - - @Override - public int draw(int x, int y, boolean small, int caretPos) { - final int h = getHeight() - 1; - final int paddingTop = 3; - final int spazioSotto = (h - 3 - 2) / 2 + paddingTop; - final int spazioSopra = h - spazioSotto; - variable.draw(x + 5, y + paddingTop, null, null); - DisplayManager.renderer.glDrawLine(x + 2, y + 0, x + 3, y + 0); - DisplayManager.renderer.glDrawLine(x + 1, y + 1, x + 1, y + spazioSotto / 2); - DisplayManager.renderer.glDrawLine(x + 2, y + spazioSotto / 2 + 1, x + 2, y + spazioSotto - 1); - DisplayManager.renderer.glDrawLine(x + 0, y + spazioSotto, x + 1, y + spazioSotto); - DisplayManager.renderer.glDrawLine(x + 2, y + spazioSotto + 1, x + 2, y + spazioSotto + spazioSopra / 2 - 1); - DisplayManager.renderer.glDrawLine(x + 1, y + spazioSotto + spazioSopra / 2, x + 1, y + h - 1); - DisplayManager.renderer.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; - } - - @Override - protected ArrayList solve() throws Error { + protected ObjectArrayList solve() throws Error { // TODO Auto-generated method stub return null; } @@ -84,4 +33,10 @@ public class EquationsSystemPart extends FunctionSingle { // TODO Auto-generated method stub return false; } + + @Override + public EquationsSystemPart clone() { + return new EquationsSystemPart(mathContext, (Equation) parameter); + } + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java index c984e039..5f0f0eb3 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.trigonometry; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -15,17 +15,7 @@ public class ArcCosine extends FunctionSingle { } @Override - public Function NewInstance(MathContext root, Function value) { - return new ArcCosine(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.getGraphicRepresentation(MathematicalSymbols.ARC_COSINE); - } - - @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { // TODO Auto-generated method stub return null; } @@ -42,4 +32,10 @@ public class ArcCosine extends FunctionSingle { return false; } + @Override + public FunctionSingle clone() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java index 45a7d66e..99d1dea4 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.trigonometry; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -15,17 +15,7 @@ public class ArcSine extends FunctionSingle { } @Override - public Function NewInstance(MathContext root, Function value) { - return new ArcSine(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.getGraphicRepresentation(MathematicalSymbols.ARC_SINE); - } - - @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { // TODO Auto-generated method stub return null; } @@ -42,4 +32,10 @@ public class ArcSine extends FunctionSingle { return false; } + @Override + public FunctionSingle clone() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java index bb9fb487..e7ba0e9f 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.trigonometry; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -15,17 +15,7 @@ public class ArcTangent extends FunctionSingle { } @Override - public Function NewInstance(MathContext root, Function value) { - return new ArcTangent(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.getGraphicRepresentation(MathematicalSymbols.ARC_TANGENT); - } - - @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { // TODO Auto-generated method stub return null; } @@ -42,4 +32,10 @@ public class ArcTangent extends FunctionSingle { return false; } + @Override + public FunctionSingle clone() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java b/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java index 21a5cbd5..26a2c2d2 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.trigonometry; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -15,17 +15,7 @@ public class Cosine extends FunctionSingle { } @Override - public Function NewInstance(MathContext root, Function value) { - return new Cosine(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.getGraphicRepresentation(MathematicalSymbols.COSINE); - } - - @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { // TODO Auto-generated method stub return null; } @@ -42,4 +32,10 @@ public class Cosine extends FunctionSingle { return false; } + @Override + public FunctionSingle clone() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Sine.java b/src/org/warp/picalculator/math/functions/trigonometry/Sine.java index 0ba6dc02..1b677ab5 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Sine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Sine.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.trigonometry; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.nevec.rjm.BigDecimalMath; import org.warp.picalculator.Error; @@ -16,20 +16,10 @@ public class Sine extends FunctionSingle { public Sine(MathContext root, Function value) { super(root, value); } - - @Override - public Function NewInstance(MathContext root, Function value) { - return new Sine(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.getGraphicRepresentation(MathematicalSymbols.SINE); - } - + @Override protected boolean isSolvable() { - if (variable instanceof Number) { + if (parameter instanceof Number) { if (mathContext.exactMode == false) { return true; } @@ -41,11 +31,11 @@ public class Sine extends FunctionSingle { } @Override - public ArrayList solve() throws Error { - final ArrayList results = new ArrayList<>(); - if (variable instanceof Number) { + public ObjectArrayList solve() throws Error { + final ObjectArrayList results = new ObjectArrayList<>(); + if (parameter instanceof Number) { if (mathContext.exactMode == false) { - results.add(new Number(mathContext, BigDecimalMath.sin(((Number) variable).getTerm()))); + results.add(new Number(mathContext, BigDecimalMath.sin(((Number) parameter).getTerm()))); } } return results; @@ -55,11 +45,16 @@ public class Sine extends FunctionSingle { public boolean equals(Object o) { if (o instanceof Sine) { final FunctionSingle f = (FunctionSingle) o; - if (variable.equals(f.getParameter())) { + if (parameter.equals(f.getParameter())) { return true; } } return false; } + @Override + public Sine clone() { + return new Sine(mathContext, parameter); + } + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java b/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java index 6e029ceb..00dc62f9 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.functions.trigonometry; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -13,19 +13,9 @@ public class Tangent extends FunctionSingle { public Tangent(MathContext root, Function value) { super(root, value); } - + @Override - public Function NewInstance(MathContext root, Function value) { - return new Tangent(root, value); - } - - @Override - public String getSymbol() { - return MathematicalSymbols.getGraphicRepresentation(MathematicalSymbols.TANGENT); - } - - @Override - public ArrayList solve() throws Error { + public ObjectArrayList solve() throws Error { // TODO Auto-generated method stub return null; } @@ -42,4 +32,10 @@ public class Tangent extends FunctionSingle { return false; } + @Override + public FunctionSingle clone() { + // TODO Auto-generated method stub + return null; + } + } diff --git a/src/org/warp/picalculator/math/parser/InputParser.java b/src/org/warp/picalculator/math/parser/InputParser.java new file mode 100644 index 00000000..b536e865 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/InputParser.java @@ -0,0 +1,289 @@ +package org.warp.picalculator.math.parser; + +import org.warp.picalculator.Error; +import org.warp.picalculator.Errors; +import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.BlockDivision; +import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionSingle; +import org.warp.picalculator.math.MathContext; +import org.warp.picalculator.math.MathematicalSymbols; +import org.warp.picalculator.math.functions.Number; +import org.warp.picalculator.math.functions.Subtraction; +import org.warp.picalculator.math.functions.Sum; +import org.warp.picalculator.math.functions.SumSubtraction; +import org.warp.picalculator.math.functions.Division; +import org.warp.picalculator.math.functions.Expression; +import org.warp.picalculator.math.functions.Multiplication; +import org.warp.picalculator.math.parser.features.FeatureChar; +import org.warp.picalculator.math.parser.features.FeatureDivision; +import org.warp.picalculator.math.parser.features.FeatureMultiplication; +import org.warp.picalculator.math.parser.features.FeatureNumber; +import org.warp.picalculator.math.parser.features.FeatureSum; +import org.warp.picalculator.math.parser.features.interfaces.Feature; +import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble; + +import com.sun.org.apache.xpath.internal.functions.Function2Args; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import it.unimi.dsi.fastutil.objects.ObjectListIterator; + +public class InputParser { + public static Expression parseInput(MathContext context, BlockContainer root) throws Error { + Expression result; + + Function resultFunction = parseContainer(context, root); + + result = new Expression(context, resultFunction); + return result; + } + + private static Function parseContainer(final MathContext context, final BlockContainer container) throws Error { + final ObjectArrayList blocks = container.getContent(); + final ObjectArrayList blockFeatures = new ObjectArrayList<>(); + + for (final Block block : blocks) { + Feature blockFeature = parseBlock(context, block); + blockFeatures.add(blockFeature); + } + + Function result = joinFeatures(context, blockFeatures); + return result; + } + + private static Feature parseBlock(final MathContext context, final Block block) throws Error { + + Feature result; + + if (block instanceof BlockChar) { + result = new FeatureChar(((BlockChar) block).getChar()); + } else if (block instanceof BlockDivision) { + BlockDivision bd = (BlockDivision) block; + Function upper = parseContainer(context, bd.getUpperContainer()); + Function lower = parseContainer(context, bd.getLowerContainer()); + result = new FeatureDivision(upper, lower); + } else { + throw new Error(Errors.SYNTAX_ERROR); + } + + return result; + } + + private static Function joinFeatures(final MathContext context, ObjectArrayList features) throws Error { + + features = fixFeatures(context, features); + + ObjectArrayList process = makeFunctions(context, features); + + fixStack(context, process); + + if (process.size() > 1) { + throw new Error(Errors.UNBALANCED_STACK, "The stack is unbalanced. Not all the functions are nested correctly"); + } + + return process.get(0); + } + + private static void fixStack(MathContext context, ObjectArrayList process) throws Error { + + //Phase 1 + ObjectListIterator stackIterator = process.listIterator(process.size()); + Function lastElement = null; + while (stackIterator.hasPrevious()) { + Function f = stackIterator.previous(); + + if (f instanceof FunctionSingle) { + if (((FunctionSingle) f).getParameter() == null) { + if (lastElement == null) { + throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + } else { + ((FunctionSingle) f).setParameter(lastElement); + process.remove(stackIterator.nextIndex()); + } + } + } + lastElement = f; + } + + //Phase 2 + stackIterator = process.iterator(); + while (stackIterator.hasNext()) { + Function f = stackIterator.next(); + + if (f instanceof Multiplication || f instanceof Division) { + + } + } + + //Phase 3 + stackIterator = process.iterator(); + while (stackIterator.hasNext()) { + Function f = stackIterator.next(); + + if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) { + + } + } + + //Phase 4 + stackIterator = process.iterator(); + while (stackIterator.hasNext()) { + Function f = stackIterator.next(); + + if (f instanceof Function2Args) { + + } + } + } + + private static ObjectArrayList makeFunctions(MathContext context, ObjectArrayList features) throws Error { + ObjectArrayList process = new ObjectArrayList<>(); + + for (Feature f : features) { + if (f instanceof FeatureDivision) { + process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); + } else if (f instanceof FeatureMultiplication) { + process.add(new Multiplication(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); + } else if (f instanceof FeatureNumber) { + process.add(new Number(context, ((FeatureNumber) f).getNumberString())); + } else if (f instanceof FeatureChar) { + //All the char features must have been changed already before + throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName().toString() + "\" can't be converted into a Function!"); + } else { + throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName().toString() + "\" can't be converted into a Function!"); + } + } + return process; + } + + private static ObjectArrayList fixFeatures(final MathContext context, ObjectArrayList features) throws Error { + + features = fixMinuses(context, features); + + features = makeNumbers(context, features); + + features = convertFunctionChars(context, features); + + return features; + } + + /** + * Create function features from char features + * @param context + * @param features + * @return + */ + private static ObjectArrayList convertFunctionChars(MathContext context, ObjectArrayList features) throws Error { + ObjectArrayList process = new ObjectArrayList<>(); + + for (Feature f : features) { + if (f instanceof FeatureChar) { + final char featureChar = ((FeatureChar) f).ch; + Feature result = null; + switch (featureChar) { + case MathematicalSymbols.SUM: + result = new FeatureSum(null, null); + break; + case MathematicalSymbols.MULTIPLICATION: + result = new FeatureMultiplication(null, null); + break; + } + + if (result == null) { + throw new Error(Errors.SYNTAX_ERROR, "Char " + featureChar + " isn't a known feature"); + } + + process.add(result); + } else { + process.add(f); + } + } + + return process; + } + + /** + * Make numbers [-][1][2][+][-][3] => [-12] + * @param context + * @param features + * @return + */ + private static ObjectArrayList makeNumbers(MathContext context, ObjectArrayList features) { + ObjectArrayList process = new ObjectArrayList<>(); + + FeatureNumber numberBuffer = null; + for (Feature f : features) { + if (f instanceof FeatureChar) { + final FeatureChar bcf = (FeatureChar) f; + final char[] numbers = MathematicalSymbols.numbers; + boolean isNumber = false; + for (char n : numbers) { + if (bcf.ch == n) { + isNumber = true; + break; + } + } + if (bcf.ch == '-') { + isNumber = true; + } + if (isNumber) { + if (numberBuffer == null) { + numberBuffer = new FeatureNumber(bcf.ch); + process.add(numberBuffer); + } else { + numberBuffer.append(bcf.ch); + } + } else { + if (numberBuffer != null) { + numberBuffer = null; + } + process.add(f); + } + } else { + process.add(f); + } + } + + return process; + } + + /** + * Fix minuses [-][1][2][+][-][3][-][2] => [-][12][+][-][3][—][2] + * @param context + * @param features + * @return + * @throws Error + */ + private static ObjectArrayList fixMinuses(final MathContext context, ObjectArrayList features) throws Error { + ObjectArrayList process = new ObjectArrayList<>(); + Feature lastFeature = null; + for (Feature f : features) { + if (f instanceof FeatureChar && ((FeatureChar)f).ch == MathematicalSymbols.SUBTRACTION) { + boolean isNegativeOfNumber = false; + if (lastFeature == null) { + isNegativeOfNumber = true; + } else if (lastFeature instanceof FeatureChar) { + FeatureChar lcf = (FeatureChar) lastFeature; + final char[] operators = MathematicalSymbols.functionsNSN; + for (char operator : operators) { + if (lcf.ch == operator) { + isNegativeOfNumber = true; + break; + } + } + } + if (isNegativeOfNumber) { + process.add(new FeatureChar(MathematicalSymbols.MINUS)); + } else { + process.add(new FeatureChar(MathematicalSymbols.SUBTRACTION)); + } + } else { + process.add(f); + } + lastFeature = f; + } + return process; + } +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureChar.java b/src/org/warp/picalculator/math/parser/features/FeatureChar.java new file mode 100644 index 00000000..3797e3c8 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureChar.java @@ -0,0 +1,13 @@ +package org.warp.picalculator.math.parser.features; + +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +public class FeatureChar implements Feature { + + public final char ch; + + public FeatureChar(char ch) { + this.ch = ch; + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureDivision.java b/src/org/warp/picalculator/math/parser/features/FeatureDivision.java new file mode 100644 index 00000000..4ae989f7 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureDivision.java @@ -0,0 +1,9 @@ +package org.warp.picalculator.math.parser.features; + +public class FeatureDivision extends FeatureDoubleImpl { + + public FeatureDivision(Object child1, Object child2) { + super(child1, child2); + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java b/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java new file mode 100644 index 00000000..86afd892 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java @@ -0,0 +1,33 @@ +package org.warp.picalculator.math.parser.features; + +import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble; + +public abstract class FeatureDoubleImpl implements FeatureDouble { + private Object child_1; + private Object child_2; + + public FeatureDoubleImpl(Object child1, Object child2) { + child_1 = child1; + child_2 = child2; + } + + @Override + public Object getChild1() { + return child_1; + } + + @Override + public void setChild1(Object obj) { + child_1 = obj; + } + + @Override + public Object getChild2() { + return child_2; + } + + @Override + public void setChild2(Object obj) { + child_2 = obj; + } +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureMultiplication.java b/src/org/warp/picalculator/math/parser/features/FeatureMultiplication.java new file mode 100644 index 00000000..cd6d22e6 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureMultiplication.java @@ -0,0 +1,9 @@ +package org.warp.picalculator.math.parser.features; + +public class FeatureMultiplication extends FeatureDoubleImpl { + + public FeatureMultiplication(Object child1, Object child2) { + super(child1, child2); + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureNumber.java b/src/org/warp/picalculator/math/parser/features/FeatureNumber.java new file mode 100644 index 00000000..4e8be142 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureNumber.java @@ -0,0 +1,27 @@ +package org.warp.picalculator.math.parser.features; + +import org.warp.picalculator.math.parser.features.interfaces.FeatureBasic; + +public class FeatureNumber implements FeatureBasic { + private String numberString; + + public FeatureNumber(char c){ + numberString = c+""; + } + + public FeatureNumber(String s) { + numberString = s; + } + + public FeatureNumber() { + numberString = ""; + } + + public String getNumberString() { + return numberString; + } + + public void append(char ch) { + numberString+=ch; + } +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java b/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java new file mode 100644 index 00000000..e3ea1312 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java @@ -0,0 +1,21 @@ +package org.warp.picalculator.math.parser.features; + +import org.warp.picalculator.math.parser.features.interfaces.FeatureSingle; + +public abstract class FeatureSingleImpl implements FeatureSingle { + private Object child; + + public FeatureSingleImpl(Object child) { + this.child = child; + } + + @Override + public Object getChild() { + return child; + } + + @Override + public void setChild(Object obj) { + child = obj; + } +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureSum.java b/src/org/warp/picalculator/math/parser/features/FeatureSum.java new file mode 100644 index 00000000..d5817080 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureSum.java @@ -0,0 +1,9 @@ +package org.warp.picalculator.math.parser.features; + +public class FeatureSum extends FeatureDoubleImpl { + + public FeatureSum(Object child1, Object child2) { + super(child1, child2); + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java b/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java new file mode 100644 index 00000000..fa361356 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java @@ -0,0 +1,5 @@ +package org.warp.picalculator.math.parser.features.interfaces; + +public abstract interface Feature { + +} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java new file mode 100644 index 00000000..cc19c77e --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java @@ -0,0 +1,4 @@ +package org.warp.picalculator.math.parser.features.interfaces; + +public interface FeatureBasic extends Feature { +} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java new file mode 100644 index 00000000..2c871f4e --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java @@ -0,0 +1,8 @@ +package org.warp.picalculator.math.parser.features.interfaces; + +public interface FeatureDouble extends Feature { + public Object getChild1(); + public void setChild1(Object obj); + public Object getChild2(); + public void setChild2(Object obj); +} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java new file mode 100644 index 00000000..71f47049 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java @@ -0,0 +1,10 @@ +package org.warp.picalculator.math.parser.features.interfaces; + +public interface FeatureMultiple extends Feature { + public Object[] getChildren(); + public Object getChild(int index); + public int getChildCount(); + public void setChild(int index, Object obj); + public void setChildren(Object[] objs); + public void addChild(Object obj); +} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java new file mode 100644 index 00000000..6c5e46b7 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java @@ -0,0 +1,6 @@ +package org.warp.picalculator.math.parser.features.interfaces; + +public interface FeatureSingle extends Feature { + public Object getChild(); + public void setChild(Object obj); +} diff --git a/src/org/warp/picalculator/math/rules/ExpandRule1.java b/src/org/warp/picalculator/math/rules/ExpandRule1.java index 852c9610..67aae966 100644 --- a/src/org/warp/picalculator/math/rules/ExpandRule1.java +++ b/src/org/warp/picalculator/math/rules/ExpandRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -55,8 +55,8 @@ public class ExpandRule1 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final MathContext root = f.getMathContext(); Expression expr = null; diff --git a/src/org/warp/picalculator/math/rules/ExpandRule5.java b/src/org/warp/picalculator/math/rules/ExpandRule5.java index 81e402f6..45492269 100644 --- a/src/org/warp/picalculator/math/rules/ExpandRule5.java +++ b/src/org/warp/picalculator/math/rules/ExpandRule5.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -34,8 +34,8 @@ public class ExpandRule5 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final Function a = null; if (f instanceof Negative) { diff --git a/src/org/warp/picalculator/math/rules/ExponentRule1.java b/src/org/warp/picalculator/math/rules/ExponentRule1.java index 7b06b7e8..b0ee7216 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule1.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -26,9 +26,9 @@ public class ExponentRule1 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Number(root, 1)); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule15.java b/src/org/warp/picalculator/math/rules/ExponentRule15.java index dabe4789..c03b6492 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule15.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule15.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -27,9 +27,9 @@ public class ExponentRule15 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication fnc = (Multiplication) f; final Function a = fnc.getParameter1(); final Expression expr = new Expression(root, a); diff --git a/src/org/warp/picalculator/math/rules/ExponentRule16.java b/src/org/warp/picalculator/math/rules/ExponentRule16.java index aac92f59..a71405ae 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule16.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule16.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -32,9 +32,9 @@ public class ExponentRule16 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication fnc = (Multiplication) f; if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) { result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Expression(root, ((Power)fnc.getParameter2()).getParameter2())))); diff --git a/src/org/warp/picalculator/math/rules/ExponentRule17.java b/src/org/warp/picalculator/math/rules/ExponentRule17.java index bfc98a27..34d3981e 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule17.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule17.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -30,9 +30,9 @@ public class ExponentRule17 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication fnc = (Multiplication) f; final Function a = fnc.getParameter1(); final Expression expr = new Expression(root, a); diff --git a/src/org/warp/picalculator/math/rules/ExponentRule2.java b/src/org/warp/picalculator/math/rules/ExponentRule2.java index 0e0c9709..92aae1ce 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule2.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule2.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -24,8 +24,8 @@ public class ExponentRule2 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); result.add(((Power) f).getParameter1()); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule3.java b/src/org/warp/picalculator/math/rules/ExponentRule3.java index 7f7e9999..be61a545 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule3.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule3.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -24,8 +24,8 @@ public class ExponentRule3 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Number(f.getMathContext(), 1)); return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule4.java b/src/org/warp/picalculator/math/rules/ExponentRule4.java index bf9756da..82f13f8a 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule4.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule4.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -27,9 +27,9 @@ public class ExponentRule4 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Power fnc = (Power) f; final Expression expr = (Expression) fnc.getParameter1(); final Multiplication mult = (Multiplication) expr.getParameter(0); diff --git a/src/org/warp/picalculator/math/rules/ExponentRule9.java b/src/org/warp/picalculator/math/rules/ExponentRule9.java index 12ab6957..188fa867 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule9.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule9.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -27,9 +27,9 @@ public class ExponentRule9 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Power powC = (Power) f; final Power powB = (Power) powC.getParameter1(); final Power p = new Power(root, powB.getParameter1(), new Multiplication(root, new Expression(root, powB.getParameter2()), new Expression(root, powC.getParameter2()))); diff --git a/src/org/warp/picalculator/math/rules/FractionsRule1.java b/src/org/warp/picalculator/math/rules/FractionsRule1.java index d635a7fc..f594da57 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule1.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -35,8 +35,8 @@ public class FractionsRule1 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Number(f.getMathContext(), 0)); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule11.java b/src/org/warp/picalculator/math/rules/FractionsRule11.java index 0e380a3d..5c888d62 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule11.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule11.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -32,8 +32,8 @@ public class FractionsRule11 { return new Multiplication(fnc.getMathContext(), a, c).isSimplified() == false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final Division fnc = (Division) f; Function a; Function b; diff --git a/src/org/warp/picalculator/math/rules/FractionsRule12.java b/src/org/warp/picalculator/math/rules/FractionsRule12.java index 91db82da..0b5a2792 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule12.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule12.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -30,8 +30,8 @@ public class FractionsRule12 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final Division fnc = (Division) f; Function a; Function b; diff --git a/src/org/warp/picalculator/math/rules/FractionsRule14.java b/src/org/warp/picalculator/math/rules/FractionsRule14.java index 86132e59..40ac75e1 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule14.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule14.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -47,8 +47,8 @@ public class FractionsRule14 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication fnc = (Multiplication) f; Function a; Function b; diff --git a/src/org/warp/picalculator/math/rules/FractionsRule2.java b/src/org/warp/picalculator/math/rules/FractionsRule2.java index d4e2b95e..97c4336f 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule2.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule2.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -27,8 +27,8 @@ public class FractionsRule2 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final Division fnc = (Division) f; result.add(fnc.getParameter1()); return result; diff --git a/src/org/warp/picalculator/math/rules/FractionsRule3.java b/src/org/warp/picalculator/math/rules/FractionsRule3.java index 22b6b5d2..5ab080c8 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule3.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule3.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -24,8 +24,8 @@ public class FractionsRule3 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Number(f.getMathContext(), 1)); return result; } diff --git a/src/org/warp/picalculator/math/rules/FractionsRule4.java b/src/org/warp/picalculator/math/rules/FractionsRule4.java index a5e37fdb..153f3b43 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule4.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule4.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.Function; @@ -28,8 +28,8 @@ public class FractionsRule4 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); final Power fnc = (Power) f; final Function a = ((Division) fnc.getParameter1()).getParameter1(); final Function b = ((Division) fnc.getParameter1()).getParameter2(); diff --git a/src/org/warp/picalculator/math/rules/FractionsRule5.java b/src/org/warp/picalculator/math/rules/FractionsRule5.java index b6992173..66384e90 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule5.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule5.java @@ -1,7 +1,7 @@ package org.warp.picalculator.math.rules; import java.math.BigDecimal; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -30,9 +30,9 @@ public class FractionsRule5 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Power fnc = (Power) f; final Function a = ((Division) fnc.getParameter1()).getParameter1(); final Function b = ((Division) fnc.getParameter1()).getParameter2(); diff --git a/src/org/warp/picalculator/math/rules/NumberRule1.java b/src/org/warp/picalculator/math/rules/NumberRule1.java index cb8832ff..3cfd9545 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule1.java +++ b/src/org/warp/picalculator/math/rules/NumberRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -35,8 +35,8 @@ public class NumberRule1 { return false; } - public static ArrayList execute(Function f) throws Error { - final ArrayList result = new ArrayList<>(); + public static ObjectArrayList execute(Function f) throws Error { + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Number(f.getMathContext(), "0")); return result; } diff --git a/src/org/warp/picalculator/math/rules/NumberRule2.java b/src/org/warp/picalculator/math/rules/NumberRule2.java index 5259c96d..22ba9aab 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule2.java +++ b/src/org/warp/picalculator/math/rules/NumberRule2.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -35,9 +35,9 @@ public class NumberRule2 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); Function a = null; boolean aFound = false; final Multiplication mult = (Multiplication) f; diff --git a/src/org/warp/picalculator/math/rules/NumberRule3.java b/src/org/warp/picalculator/math/rules/NumberRule3.java index 519999cf..6cef02a0 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule3.java +++ b/src/org/warp/picalculator/math/rules/NumberRule3.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -46,9 +46,9 @@ public class NumberRule3 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); if (f instanceof SumSubtraction) { final Multiplication mul = new Multiplication(root, new Number(root, 2), f); result.add(mul); diff --git a/src/org/warp/picalculator/math/rules/NumberRule4.java b/src/org/warp/picalculator/math/rules/NumberRule4.java index 18ea5f37..f71ef091 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule4.java +++ b/src/org/warp/picalculator/math/rules/NumberRule4.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -25,9 +25,9 @@ public class NumberRule4 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final SumSubtraction ss = (SumSubtraction) f; result.add(new Sum(root, ss.getParameter1(), ss.getParameter2())); result.add(new Subtraction(root, ss.getParameter1(), ss.getParameter2())); diff --git a/src/org/warp/picalculator/math/rules/NumberRule5.java b/src/org/warp/picalculator/math/rules/NumberRule5.java index 448e8d49..08b90768 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule5.java +++ b/src/org/warp/picalculator/math/rules/NumberRule5.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -31,9 +31,9 @@ public class NumberRule5 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final FunctionOperator fnc = (FunctionOperator) f; Function a = fnc.getParameter1(); if (a.equals(new Number(root, 0))) { diff --git a/src/org/warp/picalculator/math/rules/NumberRule6.java b/src/org/warp/picalculator/math/rules/NumberRule6.java index 13fdf5a6..52c90e40 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule6.java +++ b/src/org/warp/picalculator/math/rules/NumberRule6.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -36,9 +36,9 @@ public class NumberRule6 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); Function a = null; boolean aFound = false; final Multiplication mult = (Multiplication) f; diff --git a/src/org/warp/picalculator/math/rules/NumberRule7.java b/src/org/warp/picalculator/math/rules/NumberRule7.java index 670a1d4e..a7855991 100644 --- a/src/org/warp/picalculator/math/rules/NumberRule7.java +++ b/src/org/warp/picalculator/math/rules/NumberRule7.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -22,9 +22,9 @@ public class NumberRule7 { return f.getParameter1().equals(f.getParameter2()); } - public static ArrayList execute(Sum f) throws Error { + public static ObjectArrayList execute(Sum f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication mult = new Multiplication(root, new Number(root, 2), f.getParameter1()); result.add(mult); return result; diff --git a/src/org/warp/picalculator/math/rules/SyntaxRule1.java b/src/org/warp/picalculator/math/rules/SyntaxRule1.java index 0766c77a..e592f55b 100644 --- a/src/org/warp/picalculator/math/rules/SyntaxRule1.java +++ b/src/org/warp/picalculator/math/rules/SyntaxRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -28,9 +28,9 @@ public class SyntaxRule1 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); FunctionOperator mOut = (FunctionOperator) f; final Function a = ((FunctionOperator) mOut.getParameter1()).getParameter1(); final Function b = ((FunctionOperator) mOut.getParameter1()).getParameter2(); diff --git a/src/org/warp/picalculator/math/rules/SyntaxRule2.java b/src/org/warp/picalculator/math/rules/SyntaxRule2.java index d09896ca..64950df7 100644 --- a/src/org/warp/picalculator/math/rules/SyntaxRule2.java +++ b/src/org/warp/picalculator/math/rules/SyntaxRule2.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -30,9 +30,9 @@ public class SyntaxRule2 { return false; } - public static ArrayList execute(Sum f) throws Error { + public static ObjectArrayList execute(Sum f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Function a = f.getParameter1(); Function b, c; if (f.getParameter2() instanceof Sum) { diff --git a/src/org/warp/picalculator/math/rules/UndefinedRule1.java b/src/org/warp/picalculator/math/rules/UndefinedRule1.java index 094a4b4e..e5bceb24 100644 --- a/src/org/warp/picalculator/math/rules/UndefinedRule1.java +++ b/src/org/warp/picalculator/math/rules/UndefinedRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -27,9 +27,9 @@ public class UndefinedRule1 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Undefined(root)); return result; } diff --git a/src/org/warp/picalculator/math/rules/UndefinedRule2.java b/src/org/warp/picalculator/math/rules/UndefinedRule2.java index ec964f10..4094c543 100644 --- a/src/org/warp/picalculator/math/rules/UndefinedRule2.java +++ b/src/org/warp/picalculator/math/rules/UndefinedRule2.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -30,9 +30,9 @@ public class UndefinedRule2 { return false; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { final MathContext root = f.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); result.add(new Undefined(root)); return result; } diff --git a/src/org/warp/picalculator/math/rules/VariableRule1.java b/src/org/warp/picalculator/math/rules/VariableRule1.java index c93757e7..7360f2c3 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule1.java +++ b/src/org/warp/picalculator/math/rules/VariableRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -31,9 +31,9 @@ public class VariableRule1 { return false; } - public static ArrayList execute(FunctionOperator fnc) throws Error { + public static ObjectArrayList execute(FunctionOperator fnc) throws Error { final MathContext root = fnc.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication m1 = (Multiplication) fnc.getParameter1(); final Multiplication m2 = (Multiplication) fnc.getParameter2(); final Function a = m1.getParameter1(); diff --git a/src/org/warp/picalculator/math/rules/VariableRule2.java b/src/org/warp/picalculator/math/rules/VariableRule2.java index 2f9ed328..f22123a6 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule2.java +++ b/src/org/warp/picalculator/math/rules/VariableRule2.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -31,9 +31,9 @@ public class VariableRule2 { return false; } - public static ArrayList execute(FunctionOperator fnc) throws Error { + public static ObjectArrayList execute(FunctionOperator fnc) throws Error { final MathContext root = fnc.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication m1 = (Multiplication) fnc.getParameter1(); final Function a = m1.getParameter1(); final Function x = fnc.getParameter2(); diff --git a/src/org/warp/picalculator/math/rules/VariableRule3.java b/src/org/warp/picalculator/math/rules/VariableRule3.java index de5a8d2f..cd3cc36f 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule3.java +++ b/src/org/warp/picalculator/math/rules/VariableRule3.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -31,9 +31,9 @@ public class VariableRule3 { return false; } - public static ArrayList execute(FunctionOperator fnc) throws Error { + public static ObjectArrayList execute(FunctionOperator fnc) throws Error { final MathContext root = fnc.getMathContext(); - final ArrayList result = new ArrayList<>(); + final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication m2 = (Multiplication) fnc.getParameter2(); final Function a = m2.getParameter1(); final Function x = fnc.getParameter1(); diff --git a/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java b/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java index 577d22ee..f538d8c4 100644 --- a/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java +++ b/src/org/warp/picalculator/math/rules/methods/DivisionRule1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules.methods; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.functions.Multiplication; @@ -22,10 +22,10 @@ public class DivisionRule1 { return f.getParameter1().isSimplified() && f.getParameter2().isSimplified() && !(f.getParameter1() instanceof Number && f.getParameter2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null; } - public static ArrayList execute(Division f) throws Error { + public static ObjectArrayList execute(Division f) throws Error { final MathContext root = f.getMathContext(); Function result; - final ArrayList elements = getDivisionElements(f); + final ObjectArrayList elements = getDivisionElements(f); final int[] workingElementCouple = getFirstWorkingDivisionCouple(elements); final Function elem1 = elements.get(workingElementCouple[0]); final Function elem2 = elements.get(workingElementCouple[1]); @@ -42,13 +42,13 @@ public class DivisionRule1 { result = prec; - final ArrayList results = new ArrayList<>(); + final ObjectArrayList results = new ObjectArrayList<>(); results.add(result); return results; } - private static ArrayList getDivisionElements(Division division) { - final ArrayList elementsNumerator = new ArrayList<>(); + private static ObjectArrayList getDivisionElements(Division division) { + final ObjectArrayList elementsNumerator = new ObjectArrayList<>(); Function numMult = division.getParameter1(); while (numMult instanceof Multiplication) { elementsNumerator.add(((Multiplication) numMult).getParameter1()); @@ -56,7 +56,7 @@ public class DivisionRule1 { } elementsNumerator.add(numMult); - final ArrayList elementsDenominator = new ArrayList<>(); + final ObjectArrayList elementsDenominator = new ObjectArrayList<>(); Function denomMult = division.getParameter1(); while (denomMult instanceof Multiplication) { elementsDenominator.add(((Multiplication) denomMult).getParameter1()); @@ -67,7 +67,7 @@ public class DivisionRule1 { return elements; } - private static int[] getFirstWorkingDivisionCouple(ArrayList elements) { + private static int[] getFirstWorkingDivisionCouple(ObjectArrayList elements) { final int size = elements.size(); Function a; Function b; diff --git a/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java b/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java index 21d11cb8..39d1796f 100644 --- a/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java +++ b/src/org/warp/picalculator/math/rules/methods/MultiplicationMethod1.java @@ -1,6 +1,6 @@ package org.warp.picalculator.math.rules.methods; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -21,10 +21,10 @@ public class MultiplicationMethod1 { return ((Multiplication) f).getParameter1().isSimplified() && ((Multiplication) f).getParameter2().isSimplified() && !(((Multiplication) f).getParameter1() instanceof Number && ((Multiplication) f).getParameter2() instanceof Number) && getFirstWorkingMultiplicationCouple(getMultiplicationElements(f)) != null; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { Function result; final MathContext root = f.getMathContext(); - final ArrayList elements = getMultiplicationElements(f); + final ObjectArrayList elements = getMultiplicationElements(f); final int[] workingElementCouple = getFirstWorkingMultiplicationCouple(elements); final Function elem1 = elements.get(workingElementCouple[0]); final Function elem2 = elements.get(workingElementCouple[1]); @@ -41,13 +41,13 @@ public class MultiplicationMethod1 { result = prec; - final ArrayList results = new ArrayList<>(); + final ObjectArrayList results = new ObjectArrayList<>(); results.add(result); return results; } - private static ArrayList getMultiplicationElements(Function mult) { - final ArrayList elements = new ArrayList<>(); + private static ObjectArrayList getMultiplicationElements(Function mult) { + final ObjectArrayList elements = new ObjectArrayList<>(); while (mult instanceof Multiplication) { elements.add(((Multiplication) mult).getParameter1()); mult = ((Multiplication) mult).getParameter2(); @@ -56,7 +56,7 @@ public class MultiplicationMethod1 { return elements; } - private static int[] getFirstWorkingMultiplicationCouple(ArrayList elements) { + private static int[] getFirstWorkingMultiplicationCouple(ObjectArrayList elements) { final int size = elements.size(); Function a; Function b; diff --git a/src/org/warp/picalculator/math/rules/methods/SumMethod1.java b/src/org/warp/picalculator/math/rules/methods/SumMethod1.java index 042b719c..8d362101 100644 --- a/src/org/warp/picalculator/math/rules/methods/SumMethod1.java +++ b/src/org/warp/picalculator/math/rules/methods/SumMethod1.java @@ -1,7 +1,7 @@ package org.warp.picalculator.math.rules.methods; import java.math.BigDecimal; -import java.util.ArrayList; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; @@ -26,10 +26,10 @@ public class SumMethod1 { return (f instanceof Sum || f instanceof Subtraction) && ((FunctionOperator) f).getParameter1().isSimplified() && ((FunctionOperator) f).getParameter2().isSimplified() && !(((FunctionOperator) f).getParameter1() instanceof Number && ((FunctionOperator) f).getParameter2() instanceof Number) && getFirstWorkingSumCouple(root, getSumElements(f)) != null; } - public static ArrayList execute(Function f) throws Error { + public static ObjectArrayList execute(Function f) throws Error { Function result; final MathContext root = f.getMathContext(); - final ArrayList elements = getSumElements(f); + final ObjectArrayList elements = getSumElements(f); final int[] workingElementCouple = getFirstWorkingSumCouple(root, elements); final Function elem1 = elements.get(workingElementCouple[0]); final Function elem2 = elements.get(workingElementCouple[1]); @@ -54,14 +54,14 @@ public class SumMethod1 { result = prec; - final ArrayList results = new ArrayList<>(); + final ObjectArrayList results = new ObjectArrayList<>(); results.add(result); return results; } - private static ArrayList getSumElements(Function sum) { + private static ObjectArrayList getSumElements(Function sum) { final MathContext root = sum.getMathContext(); - final ArrayList elements = new ArrayList<>(); + final ObjectArrayList elements = new ObjectArrayList<>(); while (sum instanceof Sum || sum instanceof Subtraction) { if (sum instanceof Sum) { elements.add(((FunctionOperator) sum).getParameter2()); @@ -74,7 +74,7 @@ public class SumMethod1 { return elements; } - private static int[] getFirstWorkingSumCouple(MathContext root, ArrayList elements) { + private static int[] getFirstWorkingSumCouple(MathContext root, ObjectArrayList elements) { final int size = elements.size(); Function a; Function b; From b86228a8d3150a7772bcc5d1e015c7c6e8201d60 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Sun, 26 Mar 2017 22:44:09 +0200 Subject: [PATCH 04/10] Refining the new internal structure. Now it works. --- res/font_ex.rft | Bin 1667 -> 1667 bytes src/org/warp/picalculator/TestGPU.java | 34 +- .../warp/picalculator/device/PIDisplay.java | 10 - .../warp/picalculator/gui/DisplayManager.java | 2 +- .../picalculator/gui/expression/Block.java | 7 +- .../gui/expression/BlockChar.java | 19 +- .../gui/expression/BlockContainer.java | 135 ++++- .../gui/expression/BlockDivision.java | 36 +- .../gui/expression/BlockSquareRoot.java | 87 ++++ .../picalculator/gui/expression/Caret.java | 24 +- .../containers/InlineInputContainer.java | 12 + .../expression/containers/InputContainer.java | 136 +++++ .../containers/NormalInputContainer.java | 35 ++ .../containers/NormalOutputContainer.java | 5 + .../containers/OutputContainer.java | 71 +++ .../expression/containers/OutputLayout.java | 5 + .../gui/expression/layouts/InputLayout.java | 7 + .../gui/graphicengine/cpu/CPUEngine.java | 12 +- .../gui/graphicengine/gpu/GPUEngine.java | 2 +- .../gui/graphicengine/gpu/GPURenderer.java | 13 +- .../gui/graphicengine/gpu/NEWTWindow.java | 9 +- .../gui/screens/MathInputScreen.java | 488 ++++++------------ .../warp/picalculator/math/MathContext.java | 12 - .../math/MathematicalSymbols.java | 3 +- .../picalculator/math/functions/Division.java | 5 + .../math/functions/Multiplication.java | 6 +- .../{InputParser.java => MathParser.java} | 45 +- 27 files changed, 797 insertions(+), 423 deletions(-) create mode 100644 src/org/warp/picalculator/gui/expression/BlockSquareRoot.java create mode 100644 src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java create mode 100644 src/org/warp/picalculator/gui/expression/containers/InputContainer.java create mode 100644 src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java create mode 100644 src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java create mode 100644 src/org/warp/picalculator/gui/expression/containers/OutputContainer.java create mode 100644 src/org/warp/picalculator/gui/expression/containers/OutputLayout.java create mode 100644 src/org/warp/picalculator/gui/expression/layouts/InputLayout.java rename src/org/warp/picalculator/math/parser/{InputParser.java => MathParser.java} (85%) diff --git a/res/font_ex.rft b/res/font_ex.rft index 1f79a6e9117c1f5c530d5dfa5120f10a0dfd0c58..18475d17b8a623898f8be31c5a89b29160dce17a 100644 GIT binary patch delta 182 zcmZqXZRXvuin(5%CyBE;;f5J+bHWK_i5dn&9)5-c20YAA;tzw7JWm>LGsA&|0s{#i z@xT8WjO}I8c$gWR4@fXG+%T8;!(hV9cwmE$Fv}r>p85j^4CEM0?ax1AXt0+^0U85V zVJ6>G#@moD12ib%hB43<^ZNT=SlNJjIQWOERU GArkPu5U|eT$MuLr*zrlcwaYLTr4+ax9=Ej5wHO`hqiT{la2{sI-_4AJ~GSnHI02%{U zVP-G!Mw;QC1<;^_8`6NbnE&7Zf{O=es^$R$uw4umU~7{3+l-+~EWrXm - * This is a Java port of https:/ - * /github - * .com/nothings/stb/blob/master/tests/oversample/main.c. - *

- */ public final class PIDisplay { public static PIDisplay INSTANCE; private static float brightness; diff --git a/src/org/warp/picalculator/gui/DisplayManager.java b/src/org/warp/picalculator/gui/DisplayManager.java index 8b91a077..cd1be4ef 100644 --- a/src/org/warp/picalculator/gui/DisplayManager.java +++ b/src/org/warp/picalculator/gui/DisplayManager.java @@ -356,7 +356,7 @@ public final class DisplayManager implements RenderingLoop { Main.screenSize[1] = engine.getHeight(); } }; - + public void loop() { try { load_skin(); diff --git a/src/org/warp/picalculator/gui/expression/Block.java b/src/org/warp/picalculator/gui/expression/Block.java index 85967e38..b1d2ffb8 100644 --- a/src/org/warp/picalculator/gui/expression/Block.java +++ b/src/org/warp/picalculator/gui/expression/Block.java @@ -5,7 +5,7 @@ import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.math.parser.features.interfaces.Feature; public abstract class Block implements GraphicalElement { - + protected boolean small; protected int width; protected int height; @@ -20,6 +20,10 @@ public abstract class Block implements GraphicalElement { */ public abstract void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret); + public abstract boolean putBlock(Caret caret, Block newBlock); + + public abstract boolean delBlock(Caret caret); + @Override public abstract void recomputeDimensions(); @@ -44,4 +48,5 @@ public abstract class Block implements GraphicalElement { public abstract void setSmall(boolean small); + public abstract int getClassID(); } diff --git a/src/org/warp/picalculator/gui/expression/BlockChar.java b/src/org/warp/picalculator/gui/expression/BlockChar.java index 18c87c50..04f3e6a0 100644 --- a/src/org/warp/picalculator/gui/expression/BlockChar.java +++ b/src/org/warp/picalculator/gui/expression/BlockChar.java @@ -6,7 +6,9 @@ import org.warp.picalculator.math.parser.features.FeatureChar; import org.warp.picalculator.math.parser.features.interfaces.Feature; public class BlockChar extends Block { - + + public static final int CLASS_ID = 0x00000001; + private final char ch; public BlockChar(char ch) { @@ -21,6 +23,16 @@ public class BlockChar extends Block { r.glDrawCharLeft(x, y, ch); } + @Override + public boolean putBlock(Caret caret, Block newBlock) { + return false; + } + + @Override + public boolean delBlock(Caret caret) { + return false; + } + @Override public void recomputeDimensions() { width = BlockContainer.getDefaultCharWidth(small); @@ -38,4 +50,9 @@ public class BlockChar extends Block { return ch; } + @Override + public int getClassID() { + return CLASS_ID; + } + } diff --git a/src/org/warp/picalculator/gui/expression/BlockContainer.java b/src/org/warp/picalculator/gui/expression/BlockContainer.java index 51235657..332975c5 100644 --- a/src/org/warp/picalculator/gui/expression/BlockContainer.java +++ b/src/org/warp/picalculator/gui/expression/BlockContainer.java @@ -11,6 +11,8 @@ import org.warp.picalculator.gui.graphicengine.gpu.GPUFont; public class BlockContainer implements GraphicalElement { + private static boolean initialized = false; + private final int minWidth; private final int minHeight; private final ObjectArrayList content; @@ -18,32 +20,54 @@ public class BlockContainer implements GraphicalElement { private int width; private int height; private int line; + public final boolean withBorder; public BlockContainer() { - this(false, BlockContainer.getDefaultCharWidth(true), BlockContainer.getDefaultCharHeight(true)); + this(false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true); } public BlockContainer(boolean small) { - this(small, BlockContainer.getDefaultCharWidth(true), BlockContainer.getDefaultCharHeight(true)); + this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), true); } - public BlockContainer(boolean small, int minWidth, int minHeight) { - this(small, minWidth, minHeight, new ObjectArrayList<>()); + public BlockContainer(boolean small, boolean withBorder) { + this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), withBorder); } - public BlockContainer(boolean small, int minWidth, int minHeight, ObjectArrayList content) { + public BlockContainer(boolean small, int minWidth, int minHeight, boolean withBorder) { + this(small, minWidth, minHeight, new ObjectArrayList<>(), withBorder); + } + + public BlockContainer(boolean small, int minWidth, int minHeight, ObjectArrayList content, boolean withBorder) { this.small = small; this.minWidth = minWidth; this.minHeight = minHeight; + this.withBorder = withBorder; for (Block b: content) { - b.setSmall(small); + if (b.isSmall() != small) { + b.setSmall(small); + } } this.content = content; recomputeDimensions(); } + + public void addBlock(int position, Block b) { + if (b.isSmall() != small) { + b.setSmall(small); + } + if (position >= content.size()) { + content.add(b); + } else { + content.add(position, b); + } + recomputeDimensions(); + } - public void addBlock(Block b) { - b.setSmall(small); + public void appendBlock(Block b) { + if (b.isSmall() != small) { + b.setSmall(small); + } content.add(b); recomputeDimensions(); } @@ -76,25 +100,81 @@ public class BlockContainer implements GraphicalElement { * @param caret Position of the caret. */ public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { - int paddingX = 0; + int paddingX = 1; if (caret.getRemaining() == 0) { if (content.size() > 0) { - BlockContainer.drawCaret(ge, r, caret, x, y, content.get(0).getHeight()); + BlockContainer.drawCaret(ge, r, caret, x, y+line-content.get(0).line, content.get(0).height); } else { BlockContainer.drawCaret(ge, r, caret, x, y, height); } } - for (Block b : content) { - caret.skip(1); - b.draw(ge, r, x+paddingX, y+line-b.getLine(), caret); - paddingX += b.getWidth(); - if (caret.getRemaining() == 0) BlockContainer.drawCaret(ge, r, caret, x + paddingX, y+line-b.getLine(), b.height); + if (withBorder && content.size() == 0) { + r.glDrawLine(x+paddingX, y, x+paddingX+width-1, y); + r.glDrawLine(x+paddingX, y, x+paddingX, y+height-1); + r.glDrawLine(x+paddingX+width-1, y, x+paddingX+width-1, y+height-1); + r.glDrawLine(x+paddingX, y+height-1, x+paddingX+width-1, y+height-1); + } else { + for (Block b : content) { + caret.skip(1); + b.draw(ge, r, x+paddingX, y+line-b.line, caret); + paddingX += b.getWidth(); + if (caret.getRemaining() == 0) BlockContainer.drawCaret(ge, r, caret, x + paddingX, y+line-b.line, b.height); + paddingX += 1; + } } caret.skip(1); } + public boolean putBlock(Caret caret, Block newBlock) { + boolean added = false; + + if (caret.getRemaining() == 0) { + this.addBlock(0, newBlock); + added = true; + } + + int pos = 0; + for (Block b : content) { + caret.skip(1); + pos++; + added = added|b.putBlock(caret, newBlock); + if (caret.getRemaining() == 0) { + this.addBlock(pos, newBlock); + added = true; + } + } + caret.skip(1); + if (added) { + recomputeDimensions(); + } + return added; + } + + public boolean delBlock(Caret caret) { + boolean removed = false; + + int pos = 0; + for (Block b : content) { + caret.skip(1); + pos++; + int deltaCaret = caret.getRemaining(); + removed = removed|b.delBlock(caret); + if (caret.getRemaining() == 0 || (removed == false && deltaCaret >= 0 && caret.getRemaining() < 0)) { + this.removeAt(pos-1); + caret.setPosition(caret.getPosition()-deltaCaret); + removed = true; + } + } + caret.skip(1); + if (removed) { + recomputeDimensions(); + } + return removed; + } + + @Override public void recomputeDimensions() { int l = 0; //Line @@ -103,7 +183,7 @@ public class BlockContainer implements GraphicalElement { int h = 0; //Height for (Block b : content) { - w += b.getWidth(); + w += b.getWidth() + 1; final int bl = b.getLine(); final int bh = b.getHeight(); final int bh2 = bh - bl; @@ -115,6 +195,10 @@ public class BlockContainer implements GraphicalElement { } } + if (content.size() > 0) { + w -= 1; + } + h = h2 + l; line = l; @@ -127,6 +211,7 @@ public class BlockContainer implements GraphicalElement { height = h; } else { height = minHeight; + line = height/2; } } @@ -156,29 +241,35 @@ public class BlockContainer implements GraphicalElement { defFontSizes[1] = big.getCharacterHeight(); defFontSizes[2] = small.getCharacterWidth(); defFontSizes[3] = small.getCharacterHeight(); + initialized = true; } public static BinaryFont getDefaultFont(boolean small) { + checkInitialized(); return defFonts[small?1:0]; } - public static int getDefaultColor() { return defColor; } public static int getDefaultCharWidth(boolean b) { + checkInitialized(); return defFontSizes[b?2:0]; } public static int getDefaultCharHeight(boolean b) { + checkInitialized(); return defFontSizes[b?3:1]; } public static void drawCaret(GraphicEngine ge, Renderer r, Caret caret, int x, int y, int height) { - r.glColor(getDefaultColor()); - r.glDrawLine(x, y, x, y-1+height); - r.glDrawLine(x+1, y, x+1, y-1+height); + if (caret.getState() == CaretState.VISIBLE_ON) { + r.glColor(getDefaultColor()); + r.glDrawLine(x, y, x, y-1+height); + r.glDrawLine(x+1, y, x+1, y-1+height); + r.glDrawLine(x+2, y, x+2, y-1+height); + } } public void setSmall(boolean small) { @@ -190,4 +281,8 @@ public class BlockContainer implements GraphicalElement { return content.clone(); } + private static void checkInitialized() { + if (!initialized) throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!"); + } + } \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/expression/BlockDivision.java b/src/org/warp/picalculator/gui/expression/BlockDivision.java index c73805d5..a2c3870c 100644 --- a/src/org/warp/picalculator/gui/expression/BlockDivision.java +++ b/src/org/warp/picalculator/gui/expression/BlockDivision.java @@ -8,6 +8,8 @@ import org.warp.picalculator.math.parser.features.interfaces.Feature; import it.unimi.dsi.fastutil.objects.ObjectArrayList; public class BlockDivision extends Block { + + public static final int CLASS_ID = 0x00000002; private final BlockContainer containerUp; private final BlockContainer containerDown; @@ -27,17 +29,39 @@ public class BlockDivision extends Block { BlockContainer.getDefaultFont(small).use(ge); r.glColor(BlockContainer.getDefaultColor()); containerUp.draw(ge, r, x+1+paddingLeftUpper, y, caret); - r.glDrawLine(x, y+h1+1, x+width, y+h1+1); + r.glDrawLine(x, y+h1+1, x+width-1, y+h1+1); containerDown.draw(ge, r, x+1+paddingLeftLower, y + h1+3, caret); } + @Override + public boolean putBlock(Caret caret, Block newBlock) { + boolean added = false; + added = added|containerUp.putBlock(caret, newBlock); + added = added|containerDown.putBlock(caret, newBlock); + if (added) { + recomputeDimensions(); + } + return added; + } + + @Override + public boolean delBlock(Caret caret) { + boolean removed = false; + removed = removed|containerUp.delBlock(caret); + removed = removed|containerDown.delBlock(caret); + if (removed) { + recomputeDimensions(); + } + return removed; + } + @Override public void recomputeDimensions() { final int w1 = containerUp.getWidth(); final int w2 = containerDown.getWidth(); final int h1 = containerUp.getHeight(); final int h2 = containerDown.getHeight(); - width = (w1>w2?w1:w2) + 2; + width = (w1>w2?w1:w2) + 4; height = h1+3+h2; line = h1+1; this.h1 = h1; @@ -49,6 +73,9 @@ public class BlockDivision extends Block { paddingLeftUpper = (w2 - w1) / 2; paddingLeftLower = 0; } + } else { + paddingLeftUpper = 0; + paddingLeftLower = 0; } } @@ -67,4 +94,9 @@ public class BlockDivision extends Block { public BlockContainer getLowerContainer() { return containerDown; } + + @Override + public int getClassID() { + return CLASS_ID; + } } diff --git a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java b/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java new file mode 100644 index 00000000..74dd0581 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java @@ -0,0 +1,87 @@ +package org.warp.picalculator.gui.expression; + +import org.warp.picalculator.Main; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +public class BlockSquareRoot extends Block { + + public static final int CLASS_ID = 0x00000002; + + private final BlockContainer containerNumber; + + private int h1; + + public BlockSquareRoot() { + this.containerNumber = new BlockContainer(false); + recomputeDimensions(); + } + + @Override + public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { + BlockContainer.getDefaultFont(small).use(ge); + r.glColor(BlockContainer.getDefaultColor()); + r.glDrawLine(x, y+height-10+1, x, y+height-10+2); // / + r.glDrawLine(x+1, y+height-10, x+1, y+height-10+1); // / + r.glDrawLine(x+2, y+height-10+2, x+2, y+height-10+6); // \ + r.glDrawLine(x+3, y+height-10+7, x+3, y+height-10+9); // \ + r.glDrawLine(x+5, y+height-h1-1-2, x+width-1, y+height-h1-1-2); // ---- + r.glDrawLine(x+5, y+height-h1-1-2, x+5, y+height-(h1-2)/3f*2f-1); // | + r.glDrawLine(x+4, y+height-(h1-2)/3f*2f-1, x+4, y+height-(h1-2)/3f-1); // | + r.glDrawLine(x+3, y+height-(h1-2)/3f-1, x+3, y+height-1); // | + containerNumber.draw(ge, r, x+7, y+3, caret); + } + + @Override + public boolean putBlock(Caret caret, Block newBlock) { + boolean added = false; + added = added|containerNumber.putBlock(caret, newBlock); + if (added) { + recomputeDimensions(); + } + return added; + } + + @Override + public boolean delBlock(Caret caret) { + boolean removed = false; + removed = removed|containerNumber.delBlock(caret); + if (removed) { + recomputeDimensions(); + } + return removed; + } + + @Override + public void recomputeDimensions() { + final int w1 = containerNumber.getWidth(); + h1 = containerNumber.getHeight(); + final int l1 = containerNumber.getLine(); + width = 8+w1+2; + height = 3+h1; + line = 3+l1; + if (height < 9) { + height = 9; + line+=(9-(3+h1)); + } + } + + @Override + public void setSmall(boolean small) { + this.small = small; + this.containerNumber.setSmall(small); + recomputeDimensions(); + } + + public BlockContainer getNumberContainer() { + return containerNumber; + } + + @Override + public int getClassID() { + return CLASS_ID; + } +} diff --git a/src/org/warp/picalculator/gui/expression/Caret.java b/src/org/warp/picalculator/gui/expression/Caret.java index 5bbdca50..736e5c89 100644 --- a/src/org/warp/picalculator/gui/expression/Caret.java +++ b/src/org/warp/picalculator/gui/expression/Caret.java @@ -5,7 +5,7 @@ public class Caret { private int pos; private int remaining; private CaretState state; - + public Caret(CaretState state, int pos) { this.state = state; this.pos = pos; @@ -27,4 +27,26 @@ public class Caret { public CaretState getState() { return state; } + + public void flipState() { + if (this.state == CaretState.VISIBLE_ON) { + this.state = CaretState.VISIBLE_OFF; + } else if (this.state == CaretState.VISIBLE_OFF) { + this.state = CaretState.VISIBLE_ON; + } + } + + public void turnOn() { + if (this.state == CaretState.VISIBLE_OFF) { + this.state = CaretState.VISIBLE_ON; + } + } + + public void setPosition(int i) { + this.pos = i; + } + + public void resetRemaining() { + remaining = pos; + } } diff --git a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java new file mode 100644 index 00000000..d55f3b10 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java @@ -0,0 +1,12 @@ +package org.warp.picalculator.gui.expression.containers; + +import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.math.MathematicalSymbols; + +public class InlineInputContainer extends InputContainer { + @Override + public Block parseChar(char c) { + return new BlockChar(MathematicalSymbols.DIVISION); + } +} diff --git a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java new file mode 100644 index 00000000..8a23aeb0 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java @@ -0,0 +1,136 @@ +package org.warp.picalculator.gui.expression.containers; + +import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.expression.CaretState; +import org.warp.picalculator.gui.expression.GraphicalElement; +import org.warp.picalculator.gui.expression.layouts.InputLayout; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; + +public abstract class InputContainer implements GraphicalElement, InputLayout { + public final BlockContainer root; + private Caret caret; + private static final float CARET_DURATION = 0.5f; + private float caretTime; + + public InputContainer() { + caret = new Caret(CaretState.VISIBLE_ON, 0); + root = new BlockContainer(false, false); + } + + public InputContainer(boolean small) { + caret = new Caret(CaretState.VISIBLE_ON, 0); + root = new BlockContainer(small, false); + } + + public InputContainer(boolean small, int minWidth, int minHeight) { + caret = new Caret(CaretState.VISIBLE_ON, 0); + root = new BlockContainer(small, false); + } + + public void typeChar(char c) { + Block b = parseChar(c); + if (b != null) { + caret.resetRemaining(); + if (root.putBlock(caret, b)) { + caret.setPosition(caret.getPosition()+1); + root.recomputeDimensions(); + } + } + caretTime = 0; + caret.turnOn(); + } + + public void typeChar(String c) { + typeChar(c.charAt(0)); + } + + public void del() { + caret.resetRemaining(); + if (root.delBlock(caret)) { + root.recomputeDimensions(); + } + if (caret.getPosition() > 0) { + caret.setPosition(caret.getPosition()-1); + } + caret.turnOn(); + caretTime = 0; + } + + public void moveLeft() { + if (caret.getPosition() > 0) { + caret.setPosition(caret.getPosition()-1); + } + caret.turnOn(); + caretTime = 0; + } + + public void moveRight() { + caret.setPosition(caret.getPosition()+1); + caret.turnOn(); + caretTime = 0; + } + + @Override + public void recomputeDimensions() { + root.recomputeDimensions(); + } + + @Override + public int getWidth() { + return root.getWidth(); + } + + @Override + public int getHeight() { + return root.getHeight(); + } + + @Override + public int getLine() { + return root.getLine(); + } + + /** + * + * @param delta Time, in seconds + * @return true if something changed + */ + public boolean beforeRender(float delta) { + boolean somethingChanged = false; + caretTime += delta; + if (caretTime >= CARET_DURATION) { + while (caretTime >= CARET_DURATION) { + caretTime -= CARET_DURATION; + caret.flipState(); + somethingChanged = true; + } + } + return somethingChanged; + } + + /** + * + * @param ge Graphic Engine class. + * @param r Graphic Renderer class of ge. + * @param x Position relative to the window. + * @param y Position relative to the window. + */ + public void draw(GraphicEngine ge, Renderer r, int x, int y) { + caret.resetRemaining(); + root.draw(ge, r, x, y, caret); + + int remaining = caret.getRemaining(); + if (remaining >= 0) { + caret.setPosition(caret.getPosition()-remaining-1); + } + } + + public void clear() { + caret = new Caret(CaretState.VISIBLE_ON, 0); + root.clear(); + recomputeDimensions(); + } +} diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java new file mode 100644 index 00000000..a2ae198a --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java @@ -0,0 +1,35 @@ +package org.warp.picalculator.gui.expression.containers; + +import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.gui.expression.BlockDivision; +import org.warp.picalculator.gui.expression.BlockSquareRoot; +import org.warp.picalculator.math.MathematicalSymbols; + +public class NormalInputContainer extends InputContainer { + @Override + public Block parseChar(char c) { + switch(c) { + case MathematicalSymbols.DIVISION: + return new BlockDivision(); + case MathematicalSymbols.SQUARE_ROOT: + return new BlockSquareRoot(); + case MathematicalSymbols.MULTIPLICATION: + case MathematicalSymbols.SUM: + case MathematicalSymbols.SUBTRACTION: + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return new BlockChar(c); + default: + return new BlockChar(c); + } + } +} diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java new file mode 100644 index 00000000..081f2f46 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java @@ -0,0 +1,5 @@ +package org.warp.picalculator.gui.expression.containers; + +public class NormalOutputContainer extends OutputContainer { + +} diff --git a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java new file mode 100644 index 00000000..221ea519 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java @@ -0,0 +1,71 @@ +package org.warp.picalculator.gui.expression.containers; + +import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.expression.CaretState; +import org.warp.picalculator.gui.expression.GraphicalElement; +import org.warp.picalculator.gui.expression.layouts.InputLayout; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; + +public abstract class OutputContainer implements GraphicalElement, OutputLayout { + public final BlockContainer root; + private final Caret caret = new Caret(CaretState.HIDDEN, 0); + + public OutputContainer() { + root = new BlockContainer(); + } + + public OutputContainer(boolean small) { + root = new BlockContainer(small); + } + + public OutputContainer(boolean small, int minWidth, int minHeight) { + root = new BlockContainer(small); + } + + @Override + public void recomputeDimensions() { + root.recomputeDimensions(); + } + + @Override + public int getWidth() { + return root.getWidth(); + } + + @Override + public int getHeight() { + return root.getHeight(); + } + + @Override + public int getLine() { + return root.getLine(); + } + + /** + * + * @param delta Time, in seconds + */ + public void beforeRender(double delta) { + + } + + /** + * + * @param ge Graphic Engine class. + * @param r Graphic Renderer class of ge. + * @param x Position relative to the window. + * @param y Position relative to the window. + */ + public void draw(GraphicEngine ge, Renderer r, int x, int y) { + root.draw(ge, r, x, y, caret); + } + + public void clear() { + root.clear(); + recomputeDimensions(); + } +} diff --git a/src/org/warp/picalculator/gui/expression/containers/OutputLayout.java b/src/org/warp/picalculator/gui/expression/containers/OutputLayout.java new file mode 100644 index 00000000..fbb9d375 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/containers/OutputLayout.java @@ -0,0 +1,5 @@ +package org.warp.picalculator.gui.expression.containers; + +public interface OutputLayout { + +} diff --git a/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java b/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java new file mode 100644 index 00000000..04550bbe --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java @@ -0,0 +1,7 @@ +package org.warp.picalculator.gui.expression.layouts; + +import org.warp.picalculator.gui.expression.Block; + +public interface InputLayout { + public Block parseChar(char c); +} diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java index 293a1fc2..7f9f1f56 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java @@ -269,17 +269,23 @@ public class CPUEngine implements GraphicEngine { } if (iy0 == iy1) { for (int x = 0; x <= ix1 - ix0; x++) { - canvas2d[ix0 + x + iy0 * size[0]] = color; + if ((ix0+x < size[0]) & (iy0 < size[1])) { + canvas2d[ix0 + x + iy0 * size[0]] = color; + } } } else if (ix0 == ix1) { for (int y = 0; y <= iy1 - iy0; y++) { - canvas2d[ix0 + (iy0 + y) * size[0]] = color; + if ((ix0 < size[0]) & (iy0+y < size[1])) { + canvas2d[ix0 + (iy0 + y) * size[0]] = color; + } } } else { final int m = (iy1 - iy0) / (ix1 - ix0); for (int texx = 0; texx <= ix1 - ix0; texx++) { if (ix0 + texx < size[0] && iy0 + (m * texx) < size[1]) { - canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]] = color; + if ((ix0 + texx < size[0]) & ((iy0 + (m * texx)) < size[1])) { + canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]] = color; + } } } } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java index cb71e2a4..276687f6 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java @@ -49,7 +49,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi public void setDisplayMode(int ww, int wh) { this.size[0] = ww; this.size[1] = wh; - wnd.window.setSize(ww, wh); + wnd.window.setSize(Utils.debugOn?ww*2:ww, Utils.debugOn?wh*2:wh); } @Override diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java index da347e7b..2f5e23dc 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java @@ -24,7 +24,7 @@ import com.jogamp.opengl.util.texture.TextureIO; public class GPURenderer implements Renderer { - public GL2ES1 gl; + public static GL2ES1 gl; private final DeallocationHelper deallocationHelper = new DeallocationHelper(); FloatBuffer fbVertices; @@ -192,10 +192,10 @@ public class GPURenderer implements Renderer { final FileInputStream f = new FileInputStream("test.png"); final TextureData tx_dat = TextureIO.newTextureData(gl.getGLProfile(), f, false, TextureIO.PNG); final Texture tex = new Texture(gl, tx_dat); - tex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); + tex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); tex.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); - tex.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); - tex.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); +// tex.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); +// tex.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); return tex; } @@ -208,7 +208,10 @@ public class GPURenderer implements Renderer { final ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(img, "png", os); final InputStream fis = new ByteArrayInputStream(os.toByteArray()); - return TextureIO.newTexture(fis, false, TextureIO.PNG); + Texture tex = TextureIO.newTexture(fis, false, TextureIO.PNG); + tex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); + tex.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); + return tex; } @Override diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java b/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java index 56d22152..663a6efc 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java @@ -54,6 +54,7 @@ import java.awt.event.ComponentListener; import java.nio.ByteBuffer; import java.util.Collection; +import org.warp.picalculator.Utils; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; @@ -278,7 +279,7 @@ class NEWTWindow implements GLEventListener { //Transparency gl.glEnable(GL2ES1.GL_BLEND); gl.glBlendFunc(GL2ES1.GL_SRC_ALPHA, GL2ES1.GL_ONE_MINUS_SRC_ALPHA); - gl.glShadeModel(GL2ES1.GL_SMOOTH); + gl.glShadeModel(GL2ES1.GL_FLAT); try { renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t; @@ -295,8 +296,8 @@ class NEWTWindow implements GLEventListener { @Override public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { - disp.size[0] = width; - disp.size[1] = height; + disp.size[0] = Utils.debugOn?width/2:width; + disp.size[1] = Utils.debugOn?height/2:height; final GL2ES1 gl = glad.getGL().getGL2ES1(); float max_wh, min_wh; if (width == 0) { @@ -318,7 +319,7 @@ class NEWTWindow implements GLEventListener { gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); - gl.glOrtho(0.0, width, height, 0.0, -1, 1); + gl.glOrtho(0.0, Utils.debugOn?width/2:width, Utils.debugOn?height/2:height, 0.0, -1, 1); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); diff --git a/src/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/org/warp/picalculator/gui/screens/MathInputScreen.java index ba0b652a..995950ea 100644 --- a/src/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -1,5 +1,6 @@ package org.warp.picalculator.gui.screens; +import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -16,6 +17,11 @@ import org.warp.picalculator.Utils; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; +import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.containers.InputContainer; +import org.warp.picalculator.gui.expression.containers.NormalInputContainer; +import org.warp.picalculator.gui.expression.containers.NormalOutputContainer; +import org.warp.picalculator.gui.expression.containers.OutputContainer; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.math.AngleMode; @@ -32,114 +38,50 @@ import org.warp.picalculator.math.functions.Number; public class MathInputScreen extends Screen { - public volatile String currentExpression = ""; - public volatile String newExpression = ""; - public volatile int caretPos = 0; - public volatile boolean showCaret = true; - public volatile float showCaretDelta = 0f; public MathContext calc; - public boolean autoscroll; - public int scrollX = 0; + public InputContainer userInput; + public OutputContainer result; public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto boolean mustRefresh = true; - boolean firstStep = true; public MathInputScreen() { super(); canBeInHistory = true; - - calc = new MathContext(); } @Override public void created() throws InterruptedException { - + calc = new MathContext(); + + try { + BlockContainer.initializeFonts(DisplayManager.engine.loadFont("ex"), DisplayManager.engine.loadFont("big")); + } catch (IOException e) { + e.printStackTrace(); + System.exit(1); + } + + userInput = new NormalInputContainer(); + result = new NormalOutputContainer(); + + calc.init(); } @Override public void init() throws InterruptedException { /* Fine caricamento */ - - // Parentesi f = new - // Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)=19XZ"); - // PARENTESI CON CALCOLI - // Funzione f = new Sottrazione(new Somma(new Parentesi("Ⓐ9/2+Ⓐ7/2", - // "").calcola(), new Termine("3.5")), new - // Parentesi("3*2√14","").calcola()); - // PARENTESI CON DUE NUMERI FRAZIONALI COMPLETI CON INCOGNITE: - // Funzione f = new - // Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)", ""); - // PARENTESI CON DUE NUMERI FRAZIONALI DISALLINEATI GRAFICAMENTE: - // Funzione f = new Parentesi("((5^2-1)/2)/5-5/(5/2)=2", ""); - // TERMINE DI PROVA COMPLETO: - // Funzione f = new Termine(new NumeroAvanzato(new Rational(3, 2), - // new Rational(7, 1), new Incognite(new Incognita('X', - // Rational.ONE)), new Incognite(new Incognita('Y', Rational.ONE)), - // new Incognite(new Incognita('z', Rational.ONE)))); - // PARENTESI REALISTICA CON INCOGNITE: - // Funzione f = new Equazione(new - // Parentesi("X^2+(MX-M+4)^2-4X-4(MX-M+4)^2+7", ""), new - // Termine("0")); - // POTENZA: - // Funzione f = new Parentesi("(MX-M+4)^2", ""); - // NUMERO SEMPLICE LUNGO: - // Funzione f = new Parentesi("-1219999799999996934.42229", ""); - // : - // Funzione f = new Parentesi("5Y+XY=2", "") - -// calcola("((5^2+3√(100/0.1))+Ⓐ(7)+9/15*2√(26/2))/21"); - calc.init(); -// interpreta("{(5X*(15X/3X))+(25X/(5X*(15X/3X)))=15{X=5"); //TODO RIMUOVERE - - // long start = System.nanoTime(); - // Termine result = - // Calculator.calcolarisultato("((5Ⓑ2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21"); - // long end = System.nanoTime(); - // long timeElapsed = end-start; - // System.out.println("RESULT: " + result); - // System.out.println("DECIMAl RESULT: " + - // result.getTerm().toBigDecimal()); - // System.out.println("Time elapsed: " + (double) timeElapsed / - // 1000000 + " milliseconds\n"); - // - // - // start = System.nanoTime(); - // RisultatoEquazione eresult = - // Calculator.calcolaequazione("((5Ⓑ2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21=(175*(2√7)+3*(2√13))/105"); - // end = System.nanoTime(); - // timeElapsed = end-start; - // System.out.println("Is an equation: " + eresult.isAnEquation); - // System.out.println("L-R: " + eresult.LR); - // System.out.println("Time elapsed: " + (double) timeElapsed / - // 1000000 + " milliseconds\n"); } - - public void interpreta(boolean temporary) throws Error { - final String eqn = newExpression; - if (!temporary) { - currentExpression = eqn; - } - - calc.parseInputString(eqn); - } - + @Override public void beforeRender(float dt) { - showCaretDelta += dt; - if (showCaretDelta >= 0.5f) { - mustRefresh = true; - showCaret = !showCaret; - showCaretDelta = 0f; - } - if (caretPos > newExpression.length()) { - caretPos = newExpression.length(); - } if (DisplayManager.error == null) { DisplayManager.renderer.glClearColor(0xFFc5c2af); } else { DisplayManager.renderer.glClearColor(0xFFDC3C32); } + if (userInput.beforeRender(dt)) { + mustRefresh = true; + } } private static final BinaryFont fontBig = Utils.getFont(false); @@ -165,71 +107,11 @@ public class MathInputScreen extends Screen { final int textColor = 0xFF000000; final int padding = 4; DisplayManager.renderer.glColor(textColor); - final int caretRealPos = MathematicalSymbols.getGraphicRepresentation(newExpression.substring(0, caretPos)).length() * (fontBig.getCharacterWidth() + 1); - final String inputTextWithoutCaret = MathematicalSymbols.getGraphicRepresentation(newExpression); - final boolean tooLongI = padding + fontBig.getStringWidth(newExpression) + padding >= Main.screenSize[0]; - int scrollI = 0; - if (tooLongI) { - scrollI = -scrollX; - if (-scrollI >= Main.screenSize[0]) { - scrollI += Main.screenSize[0]; - } else { - scrollI = 0; - } - } - DisplayManager.renderer.glDrawStringLeft(padding + scrollI, padding + 20, inputTextWithoutCaret); - if (showCaret) { - DisplayManager.renderer.glDrawStringLeft(padding + scrollI + caretRealPos, padding + 20, "|"); - } - if (tooLongI) { - DisplayManager.renderer.glColor(DisplayManager.renderer.glGetClearColor()); - DisplayManager.renderer.glFillColor(Main.screenSize[0] - 16 - 2, padding + 20, fontBig.getCharacterHeight(), Main.screenSize[0]); - DisplayManager.renderer.glColor(textColor); - DisplayManager.drawSkinPart(Main.screenSize[0] - 16, padding + 20 + fontBig.getCharacterHeight() / 2 - 16 / 2, 304, 0, 304 + 16, 16); - } - if (calc.f != null) { - int topSpacing = 0; - final Iterator iter = calc.f.iterator(); - while (iter.hasNext()) { - final Function fnc = iter.next(); - try { - final boolean tooLong = padding + fnc.getWidth() + padding >= Main.screenSize[0]; - int scrollA = 0; - if (tooLong) { - scrollA = -scrollX; - if (-scrollA >= Main.screenSize[0]) { - scrollA += Main.screenSize[0]; - } else { - scrollA = 0; - } - } - final int y = padding + 20 + padding + fontBig.getCharacterHeight() + 1 + topSpacing; - fnc.draw(padding + scrollA, y, null, null); - if (tooLong) { - DisplayManager.renderer.glColor(DisplayManager.renderer.glGetClearColor()); - DisplayManager.renderer.glFillColor(Main.screenSize[0] - 16 - 2, y, fnc.getHeight(), Main.screenSize[0]); - DisplayManager.renderer.glColor(textColor); - DisplayManager.drawSkinPart(Main.screenSize[0] - 16, y + fnc.getHeight() / 2 - 16 / 2, 304, 0, 304 + 16, 16); - } - } catch (final NullPointerException e) { - iter.remove(); - } - topSpacing += fnc.getHeight() + 2; - } - } - if (calc.f2 != null) { - int bottomSpacing = 0; - for (final Function f : calc.f2) { - bottomSpacing += f.getHeight() + 2; - f.draw(DisplayManager.engine.getWidth() - 2 - f.getWidth(), DisplayManager.engine.getHeight() - bottomSpacing, null, null); - } - if (calc.resultsCount > 1 && calc.resultsCount != calc.f2.size()) { - final String resultsCountText = calc.resultsCount + " total results".toUpperCase(); - DisplayManager.renderer.glColor(0xFF9AAEA0); - Utils.getFont(true).use(DisplayManager.engine); - bottomSpacing += fontBig.getCharacterHeight() + 2; - DisplayManager.renderer.glDrawStringRight(DisplayManager.engine.getWidth() - 2, DisplayManager.engine.getHeight() - bottomSpacing, resultsCountText); - } + + userInput.draw(DisplayManager.engine, DisplayManager.renderer, padding, padding + 20); + + if (!result.root.getContent().isEmpty()) { + result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - 2, DisplayManager.engine.getHeight() - 2); } } @@ -247,141 +129,142 @@ public class MathInputScreen extends Screen { public boolean keyPressed(Key k) { switch (k) { case STEP: - if (newExpression.length() > 0) { - if (firstStep) { - try { - try { - interpreta(true); - showVariablesDialog(() -> { - currentExpression = newExpression; - calc.f2 = calc.f; - firstStep = false; - step(); - }); - } catch (final Exception ex) { - if (Utils.debugOn) { - ex.printStackTrace(); - } - throw new Error(Errors.SYNTAX_ERROR); - } - } catch (final Error e) { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n"); - DisplayManager.error = e.id.toString(); - System.err.println(e.id); - } - } else { - step(); - } - } - return true; +// if (newExpression.length() > 0) { +// if (firstStep) { +// try { +// try { +// interpreta(true); +// showVariablesDialog(() -> { +// currentExpression = newExpression; +// calc.f2 = calc.f; +// firstStep = false; +// step(); +// }); +// } catch (final Exception ex) { +// if (Utils.debugOn) { +// ex.printStackTrace(); +// } +// throw new Error(Errors.SYNTAX_ERROR); +// } +// } catch (final Error e) { +// final StringWriter sw = new StringWriter(); +// final PrintWriter pw = new PrintWriter(sw); +// e.printStackTrace(pw); +// d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n"); +// DisplayManager.error = e.id.toString(); +// System.err.println(e.id); +// } +// } else { +// step(); +// } +// } +// return true; case SIMPLIFY: - if (DisplayManager.error != null) { - Utils.debug.println("Resetting after error..."); - DisplayManager.error = null; - currentExpression = null; - calc.f = null; - calc.f2 = null; - calc.resultsCount = 0; - return true; - } else { - try { - try { - if (!firstStep) { - step(); - } else { - if (newExpression != currentExpression && newExpression.length() > 0) { - changeEquationScreen(); - interpreta(true); - showVariablesDialog(() -> { - currentExpression = newExpression; - simplify(); - }); - } - } - } catch (final Exception ex) { - if (Utils.debugOn) { - ex.printStackTrace(); - } - throw new Error(Errors.SYNTAX_ERROR); - } - } catch (final Error e) { - final StringWriter sw = new StringWriter(); - final PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n"); - DisplayManager.error = e.id.toString(); - System.err.println(e.id); - } - return true; - } +// if (DisplayManager.error != null) { +// Utils.debug.println("Resetting after error..."); +// DisplayManager.error = null; +// currentExpression = null; +// calc.f = null; +// calc.f2 = null; +// calc.resultsCount = 0; +// return true; +// } else { +// try { +// try { +// if (!firstStep) { +// step(); +// } else { +// if (newExpression != currentExpression && newExpression.length() > 0) { +// changeEquationScreen(); +// interpreta(true); +// showVariablesDialog(() -> { +// currentExpression = newExpression; +// simplify(); +// }); +// } +// } +// } catch (final Exception ex) { +// if (Utils.debugOn) { +// ex.printStackTrace(); +// } +// throw new Error(Errors.SYNTAX_ERROR); +// } +// } catch (final Error e) { +// final StringWriter sw = new StringWriter(); +// final PrintWriter pw = new PrintWriter(sw); +// e.printStackTrace(pw); +// d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n"); +// DisplayManager.error = e.id.toString(); +// System.err.println(e.id); +// } +// return true; +// } + return true; case NUM0: - typeChar("0"); + typeChar('0'); return true; case NUM1: - typeChar("1"); + typeChar('1'); return true; case NUM2: - typeChar("2"); + typeChar('2'); return true; case NUM3: - typeChar("3"); + typeChar('3'); return true; case NUM4: - typeChar("4"); + typeChar('4'); return true; case NUM5: - typeChar("5"); + typeChar('5'); return true; case NUM6: - typeChar("6"); + typeChar('6'); return true; case NUM7: - typeChar("7"); + typeChar('7'); return true; case NUM8: - typeChar("8"); + typeChar('8'); return true; case NUM9: - typeChar("9"); + typeChar('9'); return true; case PLUS: - typeChar("+"); + typeChar('+'); return true; case MINUS: - typeChar("-"); + typeChar('-'); return true; case PLUS_MINUS: - typeChar("±"); + typeChar('±'); return true; case MULTIPLY: - typeChar("*"); + typeChar('*'); return true; case DIVIDE: - typeChar("/"); + typeChar('/'); return true; case PARENTHESIS_OPEN: - typeChar("("); + typeChar('('); return true; case PARENTHESIS_CLOSE: - typeChar(")"); + typeChar(')'); return true; case DOT: - typeChar("."); + typeChar('.'); return true; case EQUAL: - typeChar("="); + typeChar('='); return true; case SQRT: - typeChar("Ⓐ"); + typeChar('Ⓐ'); return true; case ROOT: - typeChar("√"); + typeChar('√'); return true; case POWER_OF_2: - typeChar(MathematicalSymbols.POWER + "2"); + typeChar(MathematicalSymbols.POWER_OF_TWO); return true; case POWER_OF_x: typeChar(MathematicalSymbols.POWER); @@ -390,10 +273,10 @@ public class MathInputScreen extends Screen { typeChar(MathematicalSymbols.PI); return true; case LETTER_X: - typeChar(MathematicalSymbols.variables()[23]); + typeChar(MathematicalSymbols.variables[23]); return true; case LETTER_Y: - typeChar(MathematicalSymbols.variables()[24]); + typeChar(MathematicalSymbols.variables[24]); return true; case SINE: typeChar(MathematicalSymbols.SINE); @@ -414,84 +297,56 @@ public class MathInputScreen extends Screen { typeChar(MathematicalSymbols.ARC_TANGENT); return true; case DELETE: - if (newExpression.length() > 0) { - if (caretPos > 0) { - caretPos -= 1; - newExpression = newExpression.substring(0, caretPos) + newExpression.substring(caretPos + 1, newExpression.length()); - } else { - newExpression = newExpression.substring(1); - } - try { - interpreta(true); - } catch (final Error e) {} - } - firstStep = true; + userInput.del(); + mustRefresh = true; return true; case LEFT: - if (caretPos > 0) { - caretPos -= 1; - } else { - caretPos = newExpression.length(); - } - scrollX = fontBig.getStringWidth(newExpression.substring(0, caretPos) + "|||"); - showCaret = true; - showCaretDelta = 0L; + userInput.moveLeft(); + mustRefresh = true; return true; case RIGHT: - if (caretPos < newExpression.length()) { - caretPos += 1; - } else { - caretPos = 0; - } - scrollX = fontBig.getStringWidth(newExpression.substring(0, caretPos) + "|||"); - showCaret = true; - showCaretDelta = 0L; + userInput.moveRight(); + mustRefresh = true; return true; case RESET: + userInput.clear(); + result.clear(); if (DisplayManager.error != null) { Utils.debug.println("Resetting after error..."); DisplayManager.error = null; - return true; - } else { - caretPos = 0; - newExpression = ""; - firstStep = false; - if (calc.f != null) { - calc.f = new ObjectArrayList<>(); - } - return true; } + return true; case SURD_MODE: - calc.exactMode = !calc.exactMode; - if (calc.exactMode == false) { - calc.f2 = solveExpression(calc.f2); - } else { - currentExpression = ""; - Keyboard.keyPressed(Key.SIMPLIFY); - } +// calc.exactMode = !calc.exactMode; +// if (calc.exactMode == false) { +// calc.f2 = solveExpression(calc.f2); +// } else { +// currentExpression = ""; +// Keyboard.keyPressed(Key.SIMPLIFY); +// } return true; case debug1: DisplayManager.INSTANCE.setScreen(new EmptyScreen()); return true; case HISTORY_BACK: - if (DisplayManager.INSTANCE.canGoBack()) { - if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.sessions[DisplayManager.currentSession + 1] instanceof MathInputScreen) { - newExpression = currentExpression; - try { - interpreta(true); - } catch (final Error e) {} - } - } +// if (DisplayManager.INSTANCE.canGoBack()) { +// if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.sessions[DisplayManager.currentSession + 1] instanceof MathInputScreen) { +// newExpression = currentExpression; +// try { +// interpreta(true); +// } catch (final Error e) {} +// } +// } return false; case HISTORY_FORWARD: - if (DisplayManager.INSTANCE.canGoForward()) { - if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.sessions[DisplayManager.currentSession - 1] instanceof MathInputScreen) { - newExpression = currentExpression; - try { - interpreta(true); - } catch (final Error e) {} - } - } +// if (DisplayManager.INSTANCE.canGoForward()) { +// if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.sessions[DisplayManager.currentSession - 1] instanceof MathInputScreen) { +// newExpression = currentExpression; +// try { +// interpreta(true); +// } catch (final Error e) {} +// } +// } return false; case debug_DEG: if (calc.angleMode.equals(AngleMode.DEG) == false) { @@ -660,20 +515,11 @@ public class MathInputScreen extends Screen { } } - public void typeChar(String chr) { - final int len = chr.length(); - newExpression = newExpression.substring(0, caretPos) + chr + newExpression.substring(caretPos, newExpression.length()); - caretPos += len; - scrollX = fontBig.getStringWidth(newExpression.substring(0, caretPos) + "|||"); - showCaret = true; - showCaretDelta = 0L; - firstStep = true; - try { - interpreta(true); - } catch (final Error e) {} -// f.clear(); //TODO: I removed this line to prevent input blanking when pressing EQUALS button and cloning this screen, but I must see why I created this part of code. + public void typeChar(char chr) { + userInput.typeChar(chr); + mustRefresh = true; } - + @Override public boolean keyReleased(Key k) { return false; @@ -751,21 +597,11 @@ public class MathInputScreen extends Screen { public MathInputScreen clone() { final MathInputScreen es = this; final MathInputScreen es2 = new MathInputScreen(); - es2.scrollX = es.scrollX; - es2.newExpression = es.newExpression; - es2.currentExpression = es.currentExpression; - es2.showCaret = es.showCaret; - es2.showCaretDelta = es.showCaretDelta; - es2.caretPos = es.caretPos; -// es2.calc.f = Utils.cloner.deepClone(es.calc.f); -// es2.calc.f2 = Utils.cloner.deepClone(es.calc.f2); -// es2.calc.resultsCount = es.calc.resultsCount; - es2.autoscroll = es.autoscroll; es2.errorLevel = es.errorLevel; es2.mustRefresh = es.mustRefresh; - es2.firstStep = es.firstStep; -// es2.calc.variablesValues = Utils.cloner.deepClone(es.calc.variablesValues); es2.calc = Utils.cloner.deepClone(es.calc); + es2.userInput = Utils.cloner.deepClone(es.userInput); + es2.result = Utils.cloner.deepClone(es.result); return es2; } diff --git a/src/org/warp/picalculator/math/MathContext.java b/src/org/warp/picalculator/math/MathContext.java index b3644c7f..ac8da5e2 100644 --- a/src/org/warp/picalculator/math/MathContext.java +++ b/src/org/warp/picalculator/math/MathContext.java @@ -102,18 +102,6 @@ public class MathContext { } } - public void parseInputString(String eqn) throws Error { - final ObjectArrayList fncs = new ObjectArrayList<>(); - if (eqn.length() > 0) { - try { - fncs.add(parseString(eqn.replace("sqrt", MathematicalSymbols.SQUARE_ROOT).replace("^", MathematicalSymbols.POWER))); - } catch (final Exception ex) { - - } - } - f = fncs; - } - /*public void solve(EquationScreen equationScreen, char letter) throws Error { if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) { EquationScreen es = (EquationScreen) Calculator.sessions[0]; diff --git a/src/org/warp/picalculator/math/MathematicalSymbols.java b/src/org/warp/picalculator/math/MathematicalSymbols.java index 61ead678..21c768fb 100644 --- a/src/org/warp/picalculator/math/MathematicalSymbols.java +++ b/src/org/warp/picalculator/math/MathematicalSymbols.java @@ -16,6 +16,7 @@ public class MathematicalSymbols { public static final char PARENTHESIS_OPEN = '('; public static final char PARENTHESIS_CLOSE = ')'; public static final char POWER = 'Ⓑ'; + public static final char POWER_OF_TWO = 'Ⓘ'; public static final char EQUATION = '='; public static final char SYSTEM = '{'; public static final char SINE = 'Ⓒ'; @@ -29,7 +30,7 @@ public class MathematicalSymbols { public static final char[] functionsNSN = new char[] { NTH_ROOT, POWER }; - public static final char[] functionsSN = new char[] { SQUARE_ROOT, MINUS, SINE, COSINE, TANGENT, ARC_SINE, ARC_COSINE, ARC_TANGENT }; + public static final char[] functionsSN = new char[] { SQUARE_ROOT, POWER_OF_TWO, MINUS, SINE, COSINE, TANGENT, ARC_SINE, ARC_COSINE, ARC_TANGENT }; public static final char[] functions = concat(functionsNSN, functionsSN); diff --git a/src/org/warp/picalculator/math/functions/Division.java b/src/org/warp/picalculator/math/functions/Division.java index f0b44106..2458c3d8 100644 --- a/src/org/warp/picalculator/math/functions/Division.java +++ b/src/org/warp/picalculator/math/functions/Division.java @@ -96,4 +96,9 @@ public class Division extends FunctionOperator { public FunctionOperator clone() { return new Division(this.getMathContext(), this.getParameter1(), this.getParameter2()); } + + @Override + public String toString() { + return "("+this.getParameter1()+")/("+this.getParameter2()+")"; + } } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/Multiplication.java b/src/org/warp/picalculator/math/functions/Multiplication.java index 283f89d6..fc572f2b 100644 --- a/src/org/warp/picalculator/math/functions/Multiplication.java +++ b/src/org/warp/picalculator/math/functions/Multiplication.java @@ -106,10 +106,6 @@ public class Multiplication extends FunctionOperator { @Override public String toString() { - if (parameter1 != null && parameter2 != null) { - return parameter1.toString()+"*"+parameter2.toString(); - } else { - return super.toString(); - } + return "("+parameter1.toString()+")*("+parameter2.toString()+")"; } } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/parser/InputParser.java b/src/org/warp/picalculator/math/parser/MathParser.java similarity index 85% rename from src/org/warp/picalculator/math/parser/InputParser.java rename to src/org/warp/picalculator/math/parser/MathParser.java index b536e865..3a25e814 100644 --- a/src/org/warp/picalculator/math/parser/InputParser.java +++ b/src/org/warp/picalculator/math/parser/MathParser.java @@ -7,6 +7,7 @@ import org.warp.picalculator.gui.expression.BlockChar; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.BlockDivision; import org.warp.picalculator.math.Function; +import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.MathematicalSymbols; @@ -30,7 +31,7 @@ import com.sun.org.apache.xpath.internal.functions.Function2Args; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectListIterator; -public class InputParser { +public class MathParser { public static Expression parseInput(MathContext context, BlockContainer root) throws Error { Expression result; @@ -57,15 +58,19 @@ public class InputParser { Feature result; - if (block instanceof BlockChar) { - result = new FeatureChar(((BlockChar) block).getChar()); - } else if (block instanceof BlockDivision) { - BlockDivision bd = (BlockDivision) block; - Function upper = parseContainer(context, bd.getUpperContainer()); - Function lower = parseContainer(context, bd.getLowerContainer()); - result = new FeatureDivision(upper, lower); - } else { - throw new Error(Errors.SYNTAX_ERROR); + int blockType = block.getClassID(); + switch (blockType) { + case BlockChar.CLASS_ID: + result = new FeatureChar(((BlockChar) block).getChar()); + break; + case BlockDivision.CLASS_ID: + BlockDivision bd = (BlockDivision) block; + Function upper = parseContainer(context, bd.getUpperContainer()); + Function lower = parseContainer(context, bd.getLowerContainer()); + result = new FeatureDivision(upper, lower); + break; + default: + throw new Error(Errors.SYNTAX_ERROR); } return result; @@ -108,17 +113,31 @@ public class InputParser { } //Phase 2 - stackIterator = process.iterator(); + stackIterator = process.listIterator(); while (stackIterator.hasNext()) { Function f = stackIterator.next(); + final int curIndex = stackIterator.previousIndex(); if (f instanceof Multiplication || f instanceof Division) { - + if (curIndex-1>=0 && stackIterator.hasNext()) { + Function next = process.get(curIndex+1); + Function prev = process.get(curIndex-1); + stackIterator.set( + f.setParameter(0, prev) + .setParameter(1, next) + ); + process.remove(curIndex+1); + process.remove(curIndex-1); + } else { + if (f.getParameter(0) == null || f.getParameter(1) == null) { + throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + } + } } } //Phase 3 - stackIterator = process.iterator(); + stackIterator = process.listIterator(); while (stackIterator.hasNext()) { Function f = stackIterator.next(); From b89883147ba4426d8d4fff4ba2c617cc3e13d1e1 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Sun, 9 Apr 2017 22:01:03 +0200 Subject: [PATCH 05/10] Partially finished the new input API --- .classpath | 2 +- src/org/warp/picalculator/TestGPU.java | 131 +++++++++++++++--- .../warp/picalculator/device/Keyboard.java | 45 ++++-- .../device/KeyboardEventListener.java | 13 ++ .../warp/picalculator/gui/DisplayManager.java | 1 + .../picalculator/gui/GUIErrorMessage.java | 36 +++++ .../{expression => }/GraphicalElement.java | 2 +- .../picalculator/gui/expression/Block.java | 3 + .../gui/expression/BlockChar.java | 5 + .../gui/expression/BlockContainer.java | 12 +- .../gui/expression/BlockDivision.java | 5 + .../gui/expression/BlockParenthesis.java | 72 ++++++++++ .../gui/expression/BlockSquareRoot.java | 7 +- .../containers/InlineInputContainer.java | 13 ++ .../expression/containers/InputContainer.java | 22 +-- .../containers/NormalInputContainer.java | 21 +++ .../containers/NormalOutputContainer.java | 12 +- .../containers/OutputContainer.java | 2 +- .../gui/graphicengine/gpu/GPURenderer.java | 39 ++++-- .../picalculator/math/functions/Division.java | 2 +- 20 files changed, 385 insertions(+), 60 deletions(-) create mode 100644 src/org/warp/picalculator/device/KeyboardEventListener.java create mode 100644 src/org/warp/picalculator/gui/GUIErrorMessage.java rename src/org/warp/picalculator/gui/{expression => }/GraphicalElement.java (87%) create mode 100644 src/org/warp/picalculator/gui/expression/BlockParenthesis.java diff --git a/.classpath b/.classpath index 1ebddf1e..e78a6bb4 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + diff --git a/src/org/warp/picalculator/TestGPU.java b/src/org/warp/picalculator/TestGPU.java index c88deb0e..79285d68 100644 --- a/src/org/warp/picalculator/TestGPU.java +++ b/src/org/warp/picalculator/TestGPU.java @@ -5,30 +5,22 @@ import java.io.IOException; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.RenderingLoop; -import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.device.Keyboard; +import org.warp.picalculator.device.Keyboard.Key; +import org.warp.picalculator.device.KeyboardEventListener; +import org.warp.picalculator.gui.GUIErrorMessage; import org.warp.picalculator.gui.expression.BlockContainer; -import org.warp.picalculator.gui.expression.BlockDivision; -import org.warp.picalculator.gui.expression.Caret; -import org.warp.picalculator.gui.expression.CaretState; import org.warp.picalculator.gui.expression.containers.NormalInputContainer; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Skin; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine; -import org.warp.picalculator.gui.graphicengine.gpu.GPURenderer; -import org.warp.picalculator.gui.screens.KeyboardDebugScreen; -import org.warp.picalculator.gui.screens.MarioScreen; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.functions.Expression; +import org.warp.picalculator.math.functions.Root; import org.warp.picalculator.math.parser.MathParser; -import java.lang.management.ManagementFactory; -import java.lang.management.OperatingSystemMXBean; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import it.unimi.dsi.fastutil.objects.ObjectArrayList; - public class TestGPU { public static final GraphicEngine d = new GPUEngine(); @@ -38,8 +30,104 @@ public class TestGPU { Utils.debugThirdScreen = false; d.create(); + Keyboard.startKeyboard(); + Keyboard.setAdditionalKeyboardListener(new KeyboardEventListener() { + @Override + public boolean keyPressed(Key k) { + switch (k) { + case LEFT: + c.moveLeft(); + return true; + case RIGHT: + c.moveRight(); + return true; + case NUM0: + c.typeChar('0'); + return true; + case NUM1: + c.typeChar('1'); + return true; + case NUM2: + c.typeChar('2'); + return true; + case NUM3: + c.typeChar('3'); + return true; + case NUM4: + c.typeChar('4'); + return true; + case NUM5: + c.typeChar('5'); + return true; + case NUM6: + c.typeChar('6'); + return true; + case NUM7: + c.typeChar('7'); + return true; + case NUM8: + c.typeChar('8'); + return true; + case NUM9: + c.typeChar('9'); + return true; + case PLUS: + c.typeChar(MathematicalSymbols.SUM); + return true; + case MINUS: + c.typeChar(MathematicalSymbols.SUBTRACTION); + return true; + case MULTIPLY: + c.typeChar(MathematicalSymbols.MULTIPLICATION); + return true; + case DIVIDE: + c.typeChar(MathematicalSymbols.DIVISION); + return true; + case SQRT: + c.typeChar(MathematicalSymbols.SQUARE_ROOT); + return true; + case PARENTHESIS_OPEN: + case SINE: + c.typeChar(MathematicalSymbols.PARENTHESIS_OPEN); + return true; + case PARENTHESIS_CLOSE: + case debug_DEG: + c.moveRight(); + return true; + case DELETE: + c.del(); + return true; + case RESET: + c.clear(); + return true; + case POWER: + d.destroy(); + System.exit(0); + return true; + case EQUAL: + Expression expr; + try { + expr = MathParser.parseInput(new MathContext(), c.root); + System.out.println("Parsed input:"+expr.toString()); + } catch (Error e) { + e.printStackTrace(); + } + } + return false; + + } + + @Override + public boolean keyReleased(Key k) { + return false; + + } + }); + final Scene s = new Scene(d); } + + private static NormalInputContainer c = null; private static class Scene implements RenderingLoop { @@ -48,8 +136,7 @@ public class TestGPU { private final Renderer r; private final GraphicEngine d; - - private final NormalInputContainer c; + private long lastTime = 0L; public Scene(GraphicEngine d) throws IOException, Error { this.d = d; @@ -76,9 +163,6 @@ public class TestGPU { c.typeChar('2'); c.recomputeDimensions(); - Expression expr = MathParser.parseInput(new MathContext(), c.root); - System.out.println("Parsed input:"+expr.toString()); - d.start(this); // fonts = new RAWFont[1]; @@ -95,7 +179,10 @@ public class TestGPU { // TODO Auto-generated catch block e.printStackTrace(); } - System.exit(0); + if (!Utils.debugOn) { + d.destroy(); + System.exit(0); + } }).start(); d.waitUntilExit(); @@ -119,6 +206,12 @@ public class TestGPU { r.glFillRect(162, 2.5f, 160, 160, 0, 0, 16, 16); //New expression framework test + if (lastTime == 0) { + lastTime = System.currentTimeMillis(); + } + double delta = System.currentTimeMillis()-lastTime; + lastTime = System.currentTimeMillis(); + c.beforeRender((float) (delta/1000d)); c.draw(d, r, 10, 220); } diff --git a/src/org/warp/picalculator/device/Keyboard.java b/src/org/warp/picalculator/device/Keyboard.java index 652d66b1..ed858957 100644 --- a/src/org/warp/picalculator/device/Keyboard.java +++ b/src/org/warp/picalculator/device/Keyboard.java @@ -6,6 +6,7 @@ import org.warp.picalculator.Utils; import org.warp.picalculator.device.chip.ParallelToSerial; import org.warp.picalculator.device.chip.SerialToParallel; import org.warp.picalculator.gui.DisplayManager; +import org.warp.picalculator.gui.GUIErrorMessage; import org.warp.picalculator.gui.screens.KeyboardDebugScreen; import org.warp.picalculator.gui.screens.MarioScreen; import org.warp.picalculator.gui.screens.Screen; @@ -31,8 +32,10 @@ public class Keyboard { public static volatile int debugKeyCode = -1; private static volatile boolean refreshRequest = false; + + private static KeyboardEventListener additionalListener; - public static void startKeyboard() { + public synchronized static void startKeyboard() { final Thread kt = new Thread(() -> { if (Utils.debugOn) { try { @@ -94,7 +97,7 @@ public class Keyboard { kt.start(); } - private static void debugKeyPressed(int keyCode) { + private synchronized static void debugKeyPressed(int keyCode) { switch (keyCode) { case KeyEvent.VK_ESCAPE: Keyboard.keyPressed(Key.POWER); @@ -398,7 +401,7 @@ public class Keyboard { } } - private static void keyReleasedRaw(int row, int col) { + private synchronized static void keyReleasedRaw(int row, int col) { KeyboardDebugScreen.keyX = row; KeyboardDebugScreen.keyY = col; if (row == 1 && col == 1) { @@ -406,7 +409,7 @@ public class Keyboard { } } - static void keyPressedRaw(int row, int col) { + static synchronized void keyPressedRaw(int row, int col) { KeyboardDebugScreen.keyX = row; KeyboardDebugScreen.keyY = col; if (row == 1 && col == 1) { @@ -695,11 +698,25 @@ public class Keyboard { } } - public static void keyPressed(Key k) { + public synchronized static void keyPressed(Key k) { + boolean done = false; + if (additionalListener != null) { + try { + done = additionalListener.keyPressed(k); + } catch (Exception ex) { + new GUIErrorMessage(ex); + } + } if (DisplayManager.INSTANCE != null) { final Screen scr = DisplayManager.INSTANCE.getScreen(); boolean refresh = false; - if (scr != null && scr.initialized && scr.keyPressed(k)) { + boolean scrdone = false; + try { + scrdone = scr.keyPressed(k); + } catch (Exception ex) { + new GUIErrorMessage(ex); + } + if (scr != null && scr.initialized && scrdone) { refresh = true; } else { switch (k) { @@ -756,6 +773,8 @@ public class Keyboard { if (refresh) { refreshRequest = true; } + } else if (!done) { + Utils.debug.println("Key " + k.toString() + " ignored."); } } @@ -763,7 +782,11 @@ public class Keyboard { } - public static void keyReleased(Key k) { + public synchronized static void keyReleased(Key k) { + boolean done = false; + if (additionalListener != null) { + done = additionalListener.keyReleased(k); + } boolean refresh = false; if (DisplayManager.INSTANCE != null) { final Screen scr = DisplayManager.INSTANCE.getScreen(); @@ -778,10 +801,16 @@ public class Keyboard { } } if (refresh) { -// PIDisplay.display.repaint(); + refreshRequest = true; } + } else if (!done) { + Utils.debug.println("Key " + k.toString() + " ignored."); } } + + public static void setAdditionalKeyboardListener(KeyboardEventListener l) { + additionalListener = l; + } public static enum Key { POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, STEP, SIMPLIFY, 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, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI diff --git a/src/org/warp/picalculator/device/KeyboardEventListener.java b/src/org/warp/picalculator/device/KeyboardEventListener.java new file mode 100644 index 00000000..cc0de33b --- /dev/null +++ b/src/org/warp/picalculator/device/KeyboardEventListener.java @@ -0,0 +1,13 @@ +package org.warp.picalculator.device; + +import org.warp.picalculator.device.Keyboard.Key; + +public interface KeyboardEventListener { + public default boolean keyPressed(Key k) { + return false; + } + + public default boolean keyReleased(Key k) { + return false; + } +} diff --git a/src/org/warp/picalculator/gui/DisplayManager.java b/src/org/warp/picalculator/gui/DisplayManager.java index cd1be4ef..c61f5b96 100644 --- a/src/org/warp/picalculator/gui/DisplayManager.java +++ b/src/org/warp/picalculator/gui/DisplayManager.java @@ -38,6 +38,7 @@ public final class DisplayManager implements RenderingLoop { public static Screen screen; public static String displayDebugString = ""; + public static ObjectArrayList errorMessages = new ObjectArrayList<>(); public DisplayManager(Screen screen) { setScreen(screen); diff --git a/src/org/warp/picalculator/gui/GUIErrorMessage.java b/src/org/warp/picalculator/gui/GUIErrorMessage.java new file mode 100644 index 00000000..cd31e1cc --- /dev/null +++ b/src/org/warp/picalculator/gui/GUIErrorMessage.java @@ -0,0 +1,36 @@ +package org.warp.picalculator.gui; + +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; +import org.warp.picalculator.Error; + +public class GUIErrorMessage { + + private String err; + private long creationTime; + + public GUIErrorMessage(Error e) { + this.err = e.getLocalizedMessage(); + this.creationTime = System.currentTimeMillis(); + } + + public GUIErrorMessage(Exception ex) { + err = ex.getLocalizedMessage(); + this.creationTime = System.currentTimeMillis(); + } + + public void draw(GraphicEngine g, Renderer r, String msg) { + int scrW = g.getWidth(); + int scrH = g.getHeight(); + int width = 200; + int height = 20; + int margin = 4; + r.glClearSkin(); + r.glColor(0x00000000); + r.glFillRect(scrW-width-margin, scrH-height-margin, width, height, 0, 0, 0, 0); + } + + public long getCreationTime() { + return creationTime; + } +} diff --git a/src/org/warp/picalculator/gui/expression/GraphicalElement.java b/src/org/warp/picalculator/gui/GraphicalElement.java similarity index 87% rename from src/org/warp/picalculator/gui/expression/GraphicalElement.java rename to src/org/warp/picalculator/gui/GraphicalElement.java index 4d6ab338..867ac64d 100644 --- a/src/org/warp/picalculator/gui/expression/GraphicalElement.java +++ b/src/org/warp/picalculator/gui/GraphicalElement.java @@ -1,4 +1,4 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui; public interface GraphicalElement { diff --git a/src/org/warp/picalculator/gui/expression/Block.java b/src/org/warp/picalculator/gui/expression/Block.java index b1d2ffb8..7b70cf4c 100644 --- a/src/org/warp/picalculator/gui/expression/Block.java +++ b/src/org/warp/picalculator/gui/expression/Block.java @@ -1,5 +1,6 @@ package org.warp.picalculator.gui.expression; +import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.math.parser.features.interfaces.Feature; @@ -26,6 +27,8 @@ public abstract class Block implements GraphicalElement { @Override public abstract void recomputeDimensions(); + + public abstract int computeCaretMaxBound(); @Override public int getWidth() { diff --git a/src/org/warp/picalculator/gui/expression/BlockChar.java b/src/org/warp/picalculator/gui/expression/BlockChar.java index 04f3e6a0..c5a75e3f 100644 --- a/src/org/warp/picalculator/gui/expression/BlockChar.java +++ b/src/org/warp/picalculator/gui/expression/BlockChar.java @@ -55,4 +55,9 @@ public class BlockChar extends Block { return CLASS_ID; } + @Override + public int computeCaretMaxBound() { + return 0; + } + } diff --git a/src/org/warp/picalculator/gui/expression/BlockContainer.java b/src/org/warp/picalculator/gui/expression/BlockContainer.java index 332975c5..2229b596 100644 --- a/src/org/warp/picalculator/gui/expression/BlockContainer.java +++ b/src/org/warp/picalculator/gui/expression/BlockContainer.java @@ -1,13 +1,11 @@ package org.warp.picalculator.gui.expression; -import java.io.IOException; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import org.warp.picalculator.device.graphicengine.Display; +import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -import org.warp.picalculator.gui.graphicengine.gpu.GPUFont; public class BlockContainer implements GraphicalElement { @@ -284,5 +282,13 @@ public class BlockContainer implements GraphicalElement { private static void checkInitialized() { if (!initialized) throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!"); } + + public int computeCaretMaxBound() { + int maxpos = 0; + for (Block b : content) { + maxpos+=1+b.computeCaretMaxBound(); + } + return maxpos+1; + } } \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/expression/BlockDivision.java b/src/org/warp/picalculator/gui/expression/BlockDivision.java index a2c3870c..12a6d8cd 100644 --- a/src/org/warp/picalculator/gui/expression/BlockDivision.java +++ b/src/org/warp/picalculator/gui/expression/BlockDivision.java @@ -99,4 +99,9 @@ public class BlockDivision extends Block { public int getClassID() { return CLASS_ID; } + + @Override + public int computeCaretMaxBound() { + return containerUp.computeCaretMaxBound()+containerDown.computeCaretMaxBound(); + } } diff --git a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java b/src/org/warp/picalculator/gui/expression/BlockParenthesis.java new file mode 100644 index 00000000..1ad4fa05 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockParenthesis.java @@ -0,0 +1,72 @@ +package org.warp.picalculator.gui.expression; + +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; + +public class BlockParenthesis extends Block { + + public static final int CLASS_ID = 0x00000004; + + private final BlockContainer containerNumber; + + public BlockParenthesis() { + this.containerNumber = new BlockContainer(false); + recomputeDimensions(); + } + + @Override + public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { + BlockContainer.getDefaultFont(small).use(ge); + r.glColor(BlockContainer.getDefaultColor()); + containerNumber.draw(ge, r, x+7, y+3, caret); + } + + @Override + public boolean putBlock(Caret caret, Block newBlock) { + boolean added = false; + added = added|containerNumber.putBlock(caret, newBlock); + if (added) { + recomputeDimensions(); + } + return added; + } + + @Override + public boolean delBlock(Caret caret) { + boolean removed = false; + removed = removed|containerNumber.delBlock(caret); + if (removed) { + recomputeDimensions(); + } + return removed; + } + + @Override + public void recomputeDimensions() { + this.width = containerNumber.getWidth()+BlockContainer.getDefaultCharWidth(small)*2; + this.height = containerNumber.getHeight(); + this.line = containerNumber.getLine(); + } + + @Override + public void setSmall(boolean small) { + this.small = small; + this.containerNumber.setSmall(small); + recomputeDimensions(); + } + + public BlockContainer getNumberContainer() { + return containerNumber; + } + + @Override + public int getClassID() { + return CLASS_ID; + } + + @Override + public int computeCaretMaxBound() { + return containerNumber.computeCaretMaxBound(); + } + +} diff --git a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java b/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java index 74dd0581..87af3e3b 100644 --- a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java +++ b/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java @@ -9,7 +9,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; public class BlockSquareRoot extends Block { - public static final int CLASS_ID = 0x00000002; + public static final int CLASS_ID = 0x00000003; private final BlockContainer containerNumber; @@ -84,4 +84,9 @@ public class BlockSquareRoot extends Block { public int getClassID() { return CLASS_ID; } + + @Override + public int computeCaretMaxBound() { + return containerNumber.computeCaretMaxBound(); + } } diff --git a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java index d55f3b10..ee07e524 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java @@ -5,6 +5,19 @@ import org.warp.picalculator.gui.expression.BlockChar; import org.warp.picalculator.math.MathematicalSymbols; public class InlineInputContainer extends InputContainer { + + public InlineInputContainer() { + super(); + } + + public InlineInputContainer(boolean small) { + super(small); + } + + public InlineInputContainer(boolean small, int minWidth, int minHeight) { + super(small, minWidth, minHeight); + } + @Override public Block parseChar(char c) { return new BlockChar(MathematicalSymbols.DIVISION); diff --git a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java index 8a23aeb0..4fbdebe8 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java @@ -1,10 +1,10 @@ package org.warp.picalculator.gui.expression.containers; +import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.expression.CaretState; -import org.warp.picalculator.gui.expression.GraphicalElement; import org.warp.picalculator.gui.expression.layouts.InputLayout; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; @@ -14,6 +14,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { private Caret caret; private static final float CARET_DURATION = 0.5f; private float caretTime; + private int maxPosition = 0; public InputContainer() { caret = new Caret(CaretState.VISIBLE_ON, 0); @@ -36,6 +37,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { caret.resetRemaining(); if (root.putBlock(caret, b)) { caret.setPosition(caret.getPosition()+1); + maxPosition=root.computeCaretMaxBound(); root.recomputeDimensions(); } } @@ -54,21 +56,26 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { } if (caret.getPosition() > 0) { caret.setPosition(caret.getPosition()-1); + maxPosition=root.computeCaretMaxBound(); } caret.turnOn(); caretTime = 0; } public void moveLeft() { - if (caret.getPosition() > 0) { - caret.setPosition(caret.getPosition()-1); + int curPos = caret.getPosition(); + if (curPos > 0) { + caret.setPosition(curPos-1); } caret.turnOn(); caretTime = 0; } public void moveRight() { - caret.setPosition(caret.getPosition()+1); + int curPos = caret.getPosition(); + if (curPos+1 < maxPosition) { + caret.setPosition(curPos+1); + } caret.turnOn(); caretTime = 0; } @@ -108,6 +115,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { somethingChanged = true; } } + return somethingChanged; } @@ -121,16 +129,12 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { public void draw(GraphicEngine ge, Renderer r, int x, int y) { caret.resetRemaining(); root.draw(ge, r, x, y, caret); - - int remaining = caret.getRemaining(); - if (remaining >= 0) { - caret.setPosition(caret.getPosition()-remaining-1); - } } public void clear() { caret = new Caret(CaretState.VISIBLE_ON, 0); root.clear(); + maxPosition=root.computeCaretMaxBound(); recomputeDimensions(); } } diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java index a2ae198a..00ec17f4 100644 --- a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java @@ -2,11 +2,28 @@ package org.warp.picalculator.gui.expression.containers; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.BlockDivision; +import org.warp.picalculator.gui.expression.BlockParenthesis; import org.warp.picalculator.gui.expression.BlockSquareRoot; +import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.expression.CaretState; import org.warp.picalculator.math.MathematicalSymbols; public class NormalInputContainer extends InputContainer { + + public NormalInputContainer() { + super(); + } + + public NormalInputContainer(boolean small) { + super(small); + } + + public NormalInputContainer(boolean small, int minWidth, int minHeight) { + super(small, minWidth, minHeight); + } + @Override public Block parseChar(char c) { switch(c) { @@ -14,8 +31,12 @@ public class NormalInputContainer extends InputContainer { return new BlockDivision(); case MathematicalSymbols.SQUARE_ROOT: return new BlockSquareRoot(); + case MathematicalSymbols.PARENTHESIS_OPEN: + case MathematicalSymbols.PARENTHESIS_CLOSE: + return new BlockParenthesis(); case MathematicalSymbols.MULTIPLICATION: case MathematicalSymbols.SUM: + case MathematicalSymbols.SUM_SUBTRACTION: case MathematicalSymbols.SUBTRACTION: case '0': case '1': diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java index 081f2f46..53f8b554 100644 --- a/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java @@ -1,5 +1,15 @@ package org.warp.picalculator.gui.expression.containers; public class NormalOutputContainer extends OutputContainer { - + public NormalOutputContainer() { + super(); + } + + public NormalOutputContainer(boolean small) { + super(small); + } + + public NormalOutputContainer(boolean small, int minWidth, int minHeight) { + super(small, minWidth, minHeight); + } } diff --git a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java index 221ea519..07a52a83 100644 --- a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java @@ -1,10 +1,10 @@ package org.warp.picalculator.gui.expression.containers; +import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.expression.CaretState; -import org.warp.picalculator.gui.expression.GraphicalElement; import org.warp.picalculator.gui.expression.layouts.InputLayout; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java index 2f5e23dc..1f10c170 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java @@ -224,12 +224,17 @@ public class GPURenderer implements Renderer { } public void startDrawCycle() { - fbVertices = Buffers.newDirectFloatBuffer(3 * 4); - txVertices = Buffers.newDirectFloatBuffer(2 * 4); - colVertices = Buffers.newDirectFloatBuffer(4 * 4); + if (fbVertices == null) { + fbVertices = Buffers.newDirectFloatBuffer(3 * 4); + txVertices = Buffers.newDirectFloatBuffer(2 * 4); + colVertices = Buffers.newDirectFloatBuffer(4 * 4); + } fbElements = 0; } + private boolean precTexEnabled; + private Texture precTex; + public void endDrawCycle() { fbVertices.rewind(); txVertices.rewind(); @@ -239,21 +244,25 @@ public class GPURenderer implements Renderer { gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, txVertices); gl.glVertexPointer(3, GL.GL_FLOAT, 0, fbVertices); - if (currentTexEnabled) { - gl.glEnable(GL2ES1.GL_TEXTURE_2D); - currentTex.bind(gl); - } else { - gl.glDisable(GL2ES1.GL_TEXTURE_2D); + if (precTexEnabled != currentTexEnabled | precTex != currentTex) { + precTexEnabled = currentTexEnabled; + precTex = currentTex; + if (currentTexEnabled) { + gl.glEnable(GL2ES1.GL_TEXTURE_2D); + currentTex.bind(gl); + } else { + gl.glDisable(GL2ES1.GL_TEXTURE_2D); + } } - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, fbElements*4); - deleteBuffer(fbVertices); - deleteBuffer(txVertices); - deleteBuffer(colVertices); - fbVertices = null; - txVertices = null; - colVertices = null; +// deleteBuffer(fbVertices); +// deleteBuffer(txVertices); +// deleteBuffer(colVertices); +// fbVertices = null; +// txVertices = null; +// colVertices = null; } public void deleteBuffer(final Buffer realNioBuffer) { diff --git a/src/org/warp/picalculator/math/functions/Division.java b/src/org/warp/picalculator/math/functions/Division.java index 2458c3d8..01c84013 100644 --- a/src/org/warp/picalculator/math/functions/Division.java +++ b/src/org/warp/picalculator/math/functions/Division.java @@ -5,7 +5,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.expression.GraphicalElement; +import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; From c2df21d6827560d643646c9101214676a1498f3d Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Mon, 10 Apr 2017 22:50:43 +0200 Subject: [PATCH 06/10] Started rewriting math screen and conversion logics --- .classpath | 2 +- res/draft2.png | Bin 0 -> 42801 bytes src/org/warp/picalculator/BMPFile.java | 3 +- src/org/warp/picalculator/Main.java | 5 +- .../warp/picalculator/TestCalcBenchmark.java | 16 +- src/org/warp/picalculator/TestDrivers.java | 12 +- src/org/warp/picalculator/TestGPU.java | 36 ++- src/org/warp/picalculator/Utils.java | 61 ++-- .../warp/picalculator/device/CacheFile.java | 88 ++++++ .../warp/picalculator/device/Keyboard.java | 10 +- .../device/KeyboardEventListener.java | 2 +- .../device/graphicengine/RAWFont.java | 260 +++++++++--------- .../warp/picalculator/gui/DisplayManager.java | 20 +- .../picalculator/gui/GUIErrorMessage.java | 28 +- .../warp/picalculator/gui/GraphicUtils.java | 85 +++--- .../picalculator/gui/GraphicalElement.java | 13 +- .../picalculator/gui/expression/Block.java | 20 +- .../gui/expression/BlockChar.java | 14 +- .../gui/expression/BlockContainer.java | 130 +++++---- .../gui/expression/BlockDivision.java | 40 ++- .../gui/expression/BlockParenthesis.java | 20 +- .../gui/expression/BlockSquareRoot.java | 44 ++- .../picalculator/gui/expression/Caret.java | 30 +- .../gui/expression/CaretState.java | 4 +- .../containers/InlineInputContainer.java | 8 +- .../expression/containers/InputContainer.java | 100 +++++-- .../containers/NormalInputContainer.java | 13 +- .../containers/NormalOutputContainer.java | 4 +- .../containers/OutputContainer.java | 45 ++- .../gui/graphicengine/GraphicEngine.java | 2 +- .../gui/graphicengine/Renderer.java | 13 +- .../gui/graphicengine/cpu/CPUEngine.java | 28 +- .../gui/graphicengine/cpu/CPUSkin.java | 3 +- .../gui/graphicengine/cpu/SwingWindow.java | 24 +- .../graphicengine/gpu/DeallocationHelper.java | 18 +- .../gui/graphicengine/gpu/GPUEngine.java | 19 +- .../gui/graphicengine/gpu/GPUFont.java | 9 +- .../gui/graphicengine/gpu/GPURenderer.java | 60 ++-- .../gui/graphicengine/gpu/GPUSkin.java | 9 +- .../gui/graphicengine/gpu/NEWTWindow.java | 55 ++-- .../screens/ChooseVariableValueScreen.java | 2 +- .../gui/screens/KeyboardDebugScreen.java | 2 +- .../gui/screens/LoadingScreen.java | 11 +- .../picalculator/gui/screens/MarioScreen.java | 8 +- .../gui/screens/MathInputScreen.java | 180 ++++++------ .../gui/screens/SolveEquationScreen.java | 2 - src/org/warp/picalculator/math/Function.java | 21 +- .../picalculator/math/FunctionDynamic.java | 51 ++-- .../picalculator/math/FunctionOperator.java | 74 +++-- .../picalculator/math/FunctionSingle.java | 50 ++-- .../warp/picalculator/math/MathContext.java | 15 +- .../math/MathematicalSymbols.java | 5 +- .../picalculator/math/functions/Division.java | 25 +- .../math/functions/EmptyNumber.java | 10 +- .../math/functions/Expression.java | 17 +- .../picalculator/math/functions/Joke.java | 6 - .../math/functions/Multiplication.java | 10 +- .../picalculator/math/functions/Negative.java | 4 - .../picalculator/math/functions/Number.java | 19 +- .../picalculator/math/functions/Power.java | 3 +- .../picalculator/math/functions/Root.java | 6 +- .../math/functions/RootSquare.java | 2 - .../math/functions/Subtraction.java | 3 +- .../warp/picalculator/math/functions/Sum.java | 5 +- .../math/functions/SumSubtraction.java | 6 +- .../math/functions/Undefined.java | 5 +- .../picalculator/math/functions/Variable.java | 14 +- .../math/functions/equations/Equation.java | 8 +- .../functions/equations/EquationsSystem.java | 3 +- .../equations/EquationsSystemPart.java | 6 +- .../functions/trigonometry/ArcCosine.java | 1 - .../math/functions/trigonometry/ArcSine.java | 1 - .../functions/trigonometry/ArcTangent.java | 1 - .../math/functions/trigonometry/Cosine.java | 1 - .../math/functions/trigonometry/Sine.java | 3 +- .../math/functions/trigonometry/Tangent.java | 3 +- .../picalculator/math/parser/MathParser.java | 227 ++++++++++----- .../math/parser/features/FeatureChar.java | 2 +- .../parser/features/FeatureDoubleImpl.java | 4 +- .../math/parser/features/FeatureNumber.java | 14 +- .../parser/features/FeatureSingleImpl.java | 4 +- .../math/parser/features/FeatureVariable.java | 15 + .../parser/features/interfaces/Feature.java | 2 +- .../features/interfaces/FeatureBasic.java | 3 +- .../features/interfaces/FeatureDouble.java | 3 + .../features/interfaces/FeatureMultiple.java | 5 + .../features/interfaces/FeatureSingle.java | 1 + .../math/rules/ExponentRule16.java | 12 +- .../math/rules/ExponentRule9.java | 1 - .../math/rules/FractionsRule11.java | 4 +- .../math/rules/VariableRule2.java | 1 - 91 files changed, 1219 insertions(+), 1015 deletions(-) create mode 100644 res/draft2.png create mode 100644 src/org/warp/picalculator/device/CacheFile.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureVariable.java diff --git a/.classpath b/.classpath index e78a6bb4..4e2b6ee8 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + diff --git a/res/draft2.png b/res/draft2.png new file mode 100644 index 0000000000000000000000000000000000000000..93339692385f703ba6bab4f75e814bfe71f5c5ab GIT binary patch literal 42801 zcmeFZc{tSX`!_sAQOZ)b5-ODn(SmHFP1>ZAY#B;Xw#m-SSW;4!C`Hz(6lIs4nL)BI zLt@4*+gOIdm>FX*_w}B>_x-(p&%e*{{P%p0<8w^jbG^@NJFjzjov&+N-MDVJee3S6 zFc@t6Uo$o1#-~ht4z%tXFs$4F#sh<;8srH;pSHgQ znb0RJLb_TG`V10NAoD^0P`l5MhCX2zBWy*W&#ISVRNl+d$Ak5t2QY<;|G$v`&)1}C za-hE-=g(n2Qd1`o2+VkB4UL9x7KA=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32Ig#y{vQ+s1`ZY{H!gbgq_RZYXnT)>EW8EVnA%7uO z@_!_sDq@!=w=aqkYM%Pwp=ayz=CG+kB9ZLbqz(L^V86h1cQKh-njA^5i`MaiO>P*dPx}P{#8~W|_Tj<7h5})w z*#|3bk9k*sOZ<$a{%I{xU_6Z?i^Hj{703^)>NK&$;k!`S)cGhck#&r&1{f9aAA^2{Em!@Os#H ziz4=|Oh=MQ9hfN8qpFWF)Fz}pFvtR-V${I@`hZ}e;h%b&HMvJJmq70tQXp9(2C@f8 zxU297z=ka>m8Zw8D!G7cVBXvr^7#*O_ZI<@4;)0VZVBVy0_;|G&R$3SQ&9h%iGMe~ zmy2G|rsJp_4%Gj!Vv7SPwYobF=pym5 zprmb{$8wS!OJJ^%uEWin%K`#n8JV||w;|cgHKQJQ2yiRuue#qre`$gKf+-FmfKHhG zQ*!;v{Co#RY5@_8xjyGW5aIm%ewIOP2yNH+r=s0Py-Bm=$v|(9n~f`O>FD<~?@e~M zU7RG_XuwJEu|z}c3&0*-cD*5Qf7CFTac3S2y1SDMyvj?#3-8Yj)kXgH@9eeE?E<8O zZ>g`L&d&H}Ke)}En(_*cqpXQy8kV`fnNm4uXH&v#fsp7t9gd0p6A9?Chz~|t6nLJW zWkY&*S2acI?F*Ks09VNbq^?vTW-E{XC7Cu5W>Tf-uIbAT0Q*hM`jiqM2RTl!AMGL1 zJ6{!QHB3zb7s**J)QHf7(n6W60sJ1VKSVg7JX5)~5y0ZR!2;fwwYI7Th@35zwdr{U zO6a&SSG3}^itdaf0)b%vLI7F81zUh_|MDe_+8JCDd;oF4_M)wAuw?GQ4oC~-s(|Ef zsF`X&#;p(*#LRp-jK40~7GW}vL~9{oreSaKWOrV?DzQy3a+p&p0d7KiRBczxpxHn& z fl) { + public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems( + ObjectArrayList fl) { for (int i = 0; i < fl.size(); i++) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) { if (fl.get(i) instanceof FunctionSingle) { @@ -536,14 +533,13 @@ public class Utils { } return results; } - public static Function[][] joinFunctionsResults(ObjectArrayList> ln) { final int[] sizes = new int[ln.size()]; for (int i = 0; i < ln.size(); i++) { sizes[i] = ln.get(i).size(); } - int[] curs = new int[sizes.length]; + final int[] curs = new int[sizes.length]; int total = 0; for (int i = 0; i < ln.size(); i++) { if (i == 0) { @@ -615,27 +611,27 @@ public class Utils { public static void printSystemResourcesUsage() { System.out.println("============"); - OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); - for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) { + final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); + for (final Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) { method.setAccessible(true); if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) { Object value; try { value = method.invoke(operatingSystemMXBean); - } catch (Exception e) { + } catch (final Exception e) { value = e; } // try boolean percent = false; boolean mb = false; - String displayName = method.getName(); - String displayValue = value.toString(); + final String displayName = method.getName(); + final String displayValue = value.toString(); if (displayName.endsWith("CpuLoad")) { percent = true; } if (displayName.endsWith("MemorySize")) { mb = true; } - ObjectArrayList arr = new ObjectArrayList<>(); + final ObjectArrayList arr = new ObjectArrayList<>(); arr.add("getFreePhysicalMemorySize"); arr.add("getProcessCpuLoad"); arr.add("getSystemCpuLoad"); @@ -643,14 +639,14 @@ public class Utils { if (arr.contains(displayName)) { if (percent) { try { - System.out.println(displayName + " = " + (((int)(Float.parseFloat(displayValue) * 10000f))/100f) + "%"); - }catch(Exception ex) { + System.out.println(displayName + " = " + (((int) (Float.parseFloat(displayValue) * 10000f)) / 100f) + "%"); + } catch (final Exception ex) { System.out.println(displayName + " = " + displayValue); } } else if (mb) { try { System.out.println(displayName + " = " + (Long.parseLong(displayValue) / 1024L / 1024L) + " MB"); - }catch(Exception ex) { + } catch (final Exception ex) { System.out.println(displayName + " = " + displayValue); } } else { @@ -664,21 +660,20 @@ public class Utils { public static boolean isRunningOnRaspberry() { if (System.getProperty("os.name").equals("Linux")) { - final File file = new File("/etc", "os-release"); - try (FileInputStream fis = new FileInputStream(file); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis))) { - String string; - while ((string = bufferedReader.readLine()) != null) { - if (string.toLowerCase().contains("raspbian")) { - if (string.toLowerCase().contains("name")) { - return true; - } - } - } - } catch (final Exception e) { - e.printStackTrace(); - } - } + final File file = new File("/etc", "os-release"); + try (FileInputStream fis = new FileInputStream(file); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis))) { + String string; + while ((string = bufferedReader.readLine()) != null) { + if (string.toLowerCase().contains("raspbian")) { + if (string.toLowerCase().contains("name")) { + return true; + } + } + } + } catch (final Exception e) { + e.printStackTrace(); + } + } return false; } } diff --git a/src/org/warp/picalculator/device/CacheFile.java b/src/org/warp/picalculator/device/CacheFile.java new file mode 100644 index 00000000..efbd5fc8 --- /dev/null +++ b/src/org/warp/picalculator/device/CacheFile.java @@ -0,0 +1,88 @@ +package org.warp.picalculator.device; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.UUID; + +import org.warp.picalculator.Main; + +public class CacheFile { + private String path; + private ObjectOutputStream lastOOS; + private FileOutputStream lastFOS; + private ObjectInputStream lastOIS; + private FileInputStream lastFIS; + + public CacheFile() { + do { + path = UUID.randomUUID().toString()+".ser"; + } while (Files.exists(Paths.get(path))); + try { + Files.createTempFile(Main.calculatorNameLOWER, ""); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public ObjectOutputStream getObjectOutputStram() { + if (lastOOS == null) { + try { + return new ObjectOutputStream(new FileOutputStream(path)); + } catch (IOException e) { + e.printStackTrace(); + return lastOOS; + } + } else { + return lastOOS; + } + } + + public ObjectInputStream getObjectInputStram() { + if (lastOIS == null) { + try { + return new ObjectInputStream(new FileInputStream(path)); + } catch (IOException e) { + return lastOIS; + } + } else { + return lastOIS; + } + } + + public void closeStreams() { + try { + if (lastOOS != null) { + lastOOS.close(); + lastOOS = null; + } + if (lastFOS != null) { + lastFOS.close(); + lastFOS = null; + } + if (lastOIS != null) { + lastOIS.close(); + lastOIS = null; + } + if (lastFIS != null) { + lastFIS.close(); + lastFIS = null; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void dispose() { + closeStreams(); + try { + Files.deleteIfExists(Paths.get(path)); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/org/warp/picalculator/device/Keyboard.java b/src/org/warp/picalculator/device/Keyboard.java index ed858957..71f30fc0 100644 --- a/src/org/warp/picalculator/device/Keyboard.java +++ b/src/org/warp/picalculator/device/Keyboard.java @@ -30,9 +30,9 @@ public class Keyboard { private static volatile boolean[][] precedentStates = new boolean[8][8]; public static volatile boolean[][] debugKeysDown = new boolean[8][8]; public static volatile int debugKeyCode = -1; - + private static volatile boolean refreshRequest = false; - + private static KeyboardEventListener additionalListener; public synchronized static void startKeyboard() { @@ -703,7 +703,7 @@ public class Keyboard { if (additionalListener != null) { try { done = additionalListener.keyPressed(k); - } catch (Exception ex) { + } catch (final Exception ex) { new GUIErrorMessage(ex); } } @@ -713,7 +713,7 @@ public class Keyboard { boolean scrdone = false; try { scrdone = scr.keyPressed(k); - } catch (Exception ex) { + } catch (final Exception ex) { new GUIErrorMessage(ex); } if (scr != null && scr.initialized && scrdone) { @@ -807,7 +807,7 @@ public class Keyboard { Utils.debug.println("Key " + k.toString() + " ignored."); } } - + public static void setAdditionalKeyboardListener(KeyboardEventListener l) { additionalListener = l; } diff --git a/src/org/warp/picalculator/device/KeyboardEventListener.java b/src/org/warp/picalculator/device/KeyboardEventListener.java index cc0de33b..7faca8ae 100644 --- a/src/org/warp/picalculator/device/KeyboardEventListener.java +++ b/src/org/warp/picalculator/device/KeyboardEventListener.java @@ -6,7 +6,7 @@ public interface KeyboardEventListener { public default boolean keyPressed(Key k) { return false; } - + public default boolean keyReleased(Key k) { return false; } diff --git a/src/org/warp/picalculator/device/graphicengine/RAWFont.java b/src/org/warp/picalculator/device/graphicengine/RAWFont.java index 3e1b988f..3b2191b1 100644 --- a/src/org/warp/picalculator/device/graphicengine/RAWFont.java +++ b/src/org/warp/picalculator/device/graphicengine/RAWFont.java @@ -20,103 +20,102 @@ import org.warp.picalculator.Utils; */ public class RAWFont { - public boolean[][] rawchars; - public int[] chars32; - public int minBound = 10; - public int maxBound = 0; - public int charW; - public int charH; - public int charS; - public int charIntCount; - public static final int intBits = 31; + public boolean[][] rawchars; + public int[] chars32; + public int minBound = 10; + public int maxBound = 0; + public int charW; + public int charH; + public int charS; + public int charIntCount; + public static final int intBits = 31; - public void create(String name) { - try { - loadFont("/font_"+name+".rft"); - } catch (IOException e) { + public void create(String name) { + try { + loadFont("/font_" + name + ".rft"); + } catch (final IOException e) { e.printStackTrace(); System.exit(1); } - chars32 = new int[(maxBound-minBound)*charIntCount]; - for (int charIndex = 0; charIndex < maxBound-minBound; charIndex++) { - boolean[] currentChar = rawchars[charIndex]; - if (currentChar == null) { - int currentInt = 0; - int currentBit = 0; - for (int i = 0; i < charS; i++) { - if (currentInt*intBits+currentBit >= (currentInt+1)*intBits) { - currentInt += 1; - currentBit = 0; - } - chars32[charIndex*charIntCount+currentInt] = (chars32[charIndex*charIntCount+currentInt] << 1) + 1; - currentBit += 1; - } - } else { - int currentInt = 0; - int currentBit = 0; - for (int i = 0; i < charS; i++) { - if (currentBit >= intBits) { - currentInt += 1; - currentBit = 0; - } - chars32[charIndex*charIntCount+currentInt] = (chars32[charIndex*charIntCount+currentInt]) | ((currentChar[i] ? 1 : 0) << currentBit); - currentBit++; - } - } - } - - Object obj = new Object(); - WeakReference ref = new WeakReference<>(obj); - obj = null; - while (ref.get() != null) { - System.gc(); - } - } + chars32 = new int[(maxBound - minBound) * charIntCount]; + for (int charIndex = 0; charIndex < maxBound - minBound; charIndex++) { + final boolean[] currentChar = rawchars[charIndex]; + if (currentChar == null) { + int currentInt = 0; + int currentBit = 0; + for (int i = 0; i < charS; i++) { + if (currentInt * intBits + currentBit >= (currentInt + 1) * intBits) { + currentInt += 1; + currentBit = 0; + } + chars32[charIndex * charIntCount + currentInt] = (chars32[charIndex * charIntCount + currentInt] << 1) + 1; + currentBit += 1; + } + } else { + int currentInt = 0; + int currentBit = 0; + for (int i = 0; i < charS; i++) { + if (currentBit >= intBits) { + currentInt += 1; + currentBit = 0; + } + chars32[charIndex * charIntCount + currentInt] = (chars32[charIndex * charIntCount + currentInt]) | ((currentChar[i] ? 1 : 0) << currentBit); + currentBit++; + } + } + } + + Object obj = new Object(); + final WeakReference ref = new WeakReference<>(obj); + obj = null; + while (ref.get() != null) { + System.gc(); + } + } private void loadFont(String string) throws IOException { - URL res = Main.instance.getClass().getResource(string); - int[] file = Utils.realBytes(Utils.convertStreamToByteArray(res.openStream(), res.getFile().length())); - int filelength = file.length; + final URL res = Main.instance.getClass().getResource(string); + final int[] file = Utils.realBytes(Utils.convertStreamToByteArray(res.openStream(), res.getFile().length())); + final int filelength = file.length; if (filelength >= 16) { if (file[0x0] == 114 && file[0x1] == 97 && file[0x2] == 119 && file[0x3] == 0xFF && file[0x8] == 0xFF && file[0xD] == 0xFF) { charW = file[0x4] << 8 | file[0x5]; charH = file[0x6] << 8 | file[0x7]; - charS = charW*charH; - charIntCount = (int) Math.ceil(((double)charS)/((double)intBits)); + charS = charW * charH; + charIntCount = (int) Math.ceil(((double) charS) / ((double) intBits)); minBound = file[0x9] << 24 | file[0xA] << 16 | file[0xB] << 8 | file[0xC]; maxBound = file[0xE] << 24 | file[0xF] << 16 | file[0x10] << 8 | file[0x11]; if (maxBound <= minBound) { maxBound = 10000; //TODO remove it: temp fix } - rawchars = new boolean[maxBound-minBound][]; - int index = 0x12; - while (index < filelength) { - try { - int charIndex = file[index] << 8 | file[index+1]; - boolean[] rawchar = new boolean[charS]; - int charbytescount = 0; - while (charbytescount*8 < charS) { - charbytescount+=1; - } - int currentBit = 0; - for (int i = 0; i <= charbytescount; i++) { - for (int bit = 0; bit < 8; bit++) { - if (currentBit >= charS) { - break; - } - rawchar[currentBit] = (((file[index + 2 + i] >> (8-1-bit)) & 0x1)==1)?true:false; - currentBit++; - } - } - rawchars[charIndex - minBound] = rawchar; - index += 2 + charbytescount; - } - catch (Exception ex) { - ex.printStackTrace(); - System.out.println(string); - System.exit(-1); - } - } + rawchars = new boolean[maxBound - minBound][]; + int index = 0x12; + while (index < filelength) { + try { + final int charIndex = file[index] << 8 | file[index + 1]; + final boolean[] rawchar = new boolean[charS]; + int charbytescount = 0; + while (charbytescount * 8 < charS) { + charbytescount += 1; + } + int currentBit = 0; + for (int i = 0; i <= charbytescount; i++) { + for (int bit = 0; bit < 8; bit++) { + if (currentBit >= charS) { + break; + } + rawchar[currentBit] = (((file[index + 2 + i] >> (8 - 1 - bit)) & 0x1) == 1) ? true : false; + currentBit++; + } + } + rawchars[charIndex - minBound] = rawchar; + index += 2 + charbytescount; + } catch (final Exception ex) { + ex.printStackTrace(); + System.out.println(string); + System.exit(-1); + } + } } else { throw new IOException(); } @@ -126,56 +125,55 @@ public class RAWFont { } public int[] getCharIndexes(String txt) { - final int l = txt.length(); - int[] indexes = new int[l]; - char[] chars = txt.toCharArray(); - for (int i = 0; i < l; i++) { - indexes[i] = (chars[i] & 0xFFFF)-minBound; - } - return indexes; - } + final int l = txt.length(); + final int[] indexes = new int[l]; + final char[] chars = txt.toCharArray(); + for (int i = 0; i < l; i++) { + indexes[i] = (chars[i] & 0xFFFF) - minBound; + } + return indexes; + } - @SuppressWarnings("unused") + @SuppressWarnings("unused") private void saveArray(int[] screen, String coutputpng) { - BufferedImage bi = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB); - final int[] a = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData(); - System.arraycopy(screen, 0, a, 0, screen.length); - try { - ImageIO.write(bi, "PNG", new File(coutputpng)); - } catch (IOException ex) { - Logger.getLogger(RAWFont.class.getName()).log(Level.SEVERE, null, ex); - } - } + final BufferedImage bi = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB); + final int[] a = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData(); + System.arraycopy(screen, 0, a, 0, screen.length); + try { + ImageIO.write(bi, "PNG", new File(coutputpng)); + } catch (final IOException ex) { + Logger.getLogger(RAWFont.class.getName()).log(Level.SEVERE, null, ex); + } + } - public void drawText(int[] screen, int[] screenSize, int x, int y, int[] text, int color) { - final int screenLength = screen.length; - int screenPos = 0; - - - int currentInt; - int currentIntBitPosition; - int bitData; - int cpos; - int j; - final int l = text.length; - for (int i = 0; i < l; i++) { - cpos = (i * (charW + 1)); - final int charIndex = text[i]; - for (int dy = 0; dy < charH; dy++) { - for (int dx = 0; dx < charW; dx++) { - j = x + cpos + dx; - if (j > 0 & j < screenSize[0]) { - int bit = dx + dy * charW; - currentInt = (int) (Math.floor(bit)/(intBits)); - currentIntBitPosition = bit-(currentInt*intBits); - bitData = (chars32[charIndex*charIntCount+currentInt] >> currentIntBitPosition) & 1; - screenPos = x + cpos + dx + (y + dy) * screenSize[0]; - if (bitData == 1 & screenLength > screenPos) { - screen[screenPos] = color; - } - } - } - } - } - } + public void drawText(int[] screen, int[] screenSize, int x, int y, int[] text, int color) { + final int screenLength = screen.length; + int screenPos = 0; + + int currentInt; + int currentIntBitPosition; + int bitData; + int cpos; + int j; + final int l = text.length; + for (int i = 0; i < l; i++) { + cpos = (i * (charW + 1)); + final int charIndex = text[i]; + for (int dy = 0; dy < charH; dy++) { + for (int dx = 0; dx < charW; dx++) { + j = x + cpos + dx; + if (j > 0 & j < screenSize[0]) { + final int bit = dx + dy * charW; + currentInt = (int) (Math.floor(bit) / (intBits)); + currentIntBitPosition = bit - (currentInt * intBits); + bitData = (chars32[charIndex * charIntCount + currentInt] >> currentIntBitPosition) & 1; + screenPos = x + cpos + dx + (y + dy) * screenSize[0]; + if (bitData == 1 & screenLength > screenPos) { + screen[screenPos] = color; + } + } + } + } + } + } } diff --git a/src/org/warp/picalculator/gui/DisplayManager.java b/src/org/warp/picalculator/gui/DisplayManager.java index c61f5b96..a141e1d8 100644 --- a/src/org/warp/picalculator/gui/DisplayManager.java +++ b/src/org/warp/picalculator/gui/DisplayManager.java @@ -1,10 +1,6 @@ package org.warp.picalculator.gui; import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.OperatingSystemMXBean; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Main; @@ -357,7 +353,7 @@ public final class DisplayManager implements RenderingLoop { Main.screenSize[1] = engine.getHeight(); } }; - + public void loop() { try { load_skin(); @@ -373,7 +369,7 @@ public final class DisplayManager implements RenderingLoop { } //Working thread - Thread workThread = new Thread(() -> { + final Thread workThread = new Thread(() -> { try { while (true) { float dt = 0; @@ -388,7 +384,7 @@ public final class DisplayManager implements RenderingLoop { * Calcoli */ checkDisplayResized(); - + screen.beforeRender(dt); Thread.sleep(50); @@ -449,9 +445,9 @@ public final class DisplayManager implements RenderingLoop { workThread.setDaemon(true); workThread.setName("Work thread"); workThread.start(); - + engine.start(getDrawable()); - + engine.waitUntilExit(); } catch (final Exception ex) { ex.printStackTrace(); @@ -488,13 +484,13 @@ public final class DisplayManager implements RenderingLoop { public static float getBrightness() { return brightness; } - + public static int currentSession = 0; public static Screen[] sessions = new Screen[5]; @Deprecated public static void colore(float f1, float f2, float f3, float f4) { - renderer.glColor4f(f1,f2,f3,f4); + renderer.glColor4f(f1, f2, f3, f4); } public static RenderingLoop getDrawable() { @@ -503,6 +499,6 @@ public final class DisplayManager implements RenderingLoop { @Deprecated public static void drawSkinPart(int x, int y, int uvX, int uvY, int uvX2, int uvY2) { - renderer.glFillRect(x, y, uvX2-uvX, uvY2-uvY, uvX, uvY, uvX2-uvX, uvY2-uvY); + renderer.glFillRect(x, y, uvX2 - uvX, uvY2 - uvY, uvX, uvY, uvX2 - uvX, uvY2 - uvY); } } \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/GUIErrorMessage.java b/src/org/warp/picalculator/gui/GUIErrorMessage.java index cd31e1cc..feaeaee1 100644 --- a/src/org/warp/picalculator/gui/GUIErrorMessage.java +++ b/src/org/warp/picalculator/gui/GUIErrorMessage.java @@ -6,30 +6,30 @@ import org.warp.picalculator.Error; public class GUIErrorMessage { - private String err; - private long creationTime; + private final String err; + private final long creationTime; public GUIErrorMessage(Error e) { - this.err = e.getLocalizedMessage(); - this.creationTime = System.currentTimeMillis(); + err = e.getLocalizedMessage(); + creationTime = System.currentTimeMillis(); } - + public GUIErrorMessage(Exception ex) { err = ex.getLocalizedMessage(); - this.creationTime = System.currentTimeMillis(); + creationTime = System.currentTimeMillis(); } - + public void draw(GraphicEngine g, Renderer r, String msg) { - int scrW = g.getWidth(); - int scrH = g.getHeight(); - int width = 200; - int height = 20; - int margin = 4; + final int scrW = g.getWidth(); + final int scrH = g.getHeight(); + final int width = 200; + final int height = 20; + final int margin = 4; r.glClearSkin(); r.glColor(0x00000000); - r.glFillRect(scrW-width-margin, scrH-height-margin, width, height, 0, 0, 0, 0); + r.glFillRect(scrW - width - margin, scrH - height - margin, width, height, 0, 0, 0, 0); } - + public long getCreationTime() { return creationTime; } diff --git a/src/org/warp/picalculator/gui/GraphicUtils.java b/src/org/warp/picalculator/gui/GraphicUtils.java index 041906f6..14d7b2b3 100644 --- a/src/org/warp/picalculator/gui/GraphicUtils.java +++ b/src/org/warp/picalculator/gui/GraphicUtils.java @@ -1,60 +1,53 @@ package org.warp.picalculator.gui; public class GraphicUtils { - public static final float sin(float rad) - { - return sin[(int) (rad * radToIndex) & SIN_MASK]; - } + public static final float sin(float rad) { + return sin[(int) (rad * radToIndex) & SIN_MASK]; + } - public static final float cos(float rad) - { - return cos[(int) (rad * radToIndex) & SIN_MASK]; - } + public static final float cos(float rad) { + return cos[(int) (rad * radToIndex) & SIN_MASK]; + } - public static final float sinDeg(float deg) - { - return sin[(int) (deg * degToIndex) & SIN_MASK]; - } + public static final float sinDeg(float deg) { + return sin[(int) (deg * degToIndex) & SIN_MASK]; + } - public static final float cosDeg(float deg) - { - return cos[(int) (deg * degToIndex) & SIN_MASK]; - } + public static final float cosDeg(float deg) { + return cos[(int) (deg * degToIndex) & SIN_MASK]; + } - private static final float RAD,DEG; - private static final int SIN_BITS,SIN_MASK,SIN_COUNT; - private static final float radFull,radToIndex; - private static final float degFull,degToIndex; - private static final float[] sin, cos; + private static final float RAD, DEG; + private static final int SIN_BITS, SIN_MASK, SIN_COUNT; + private static final float radFull, radToIndex; + private static final float degFull, degToIndex; + private static final float[] sin, cos; - static - { - RAD = (float) Math.PI / 180.0f; - DEG = 180.0f / (float) Math.PI; + static { + RAD = (float) Math.PI / 180.0f; + DEG = 180.0f / (float) Math.PI; - SIN_BITS = 12; - SIN_MASK = ~(-1 << SIN_BITS); - SIN_COUNT = SIN_MASK + 1; + SIN_BITS = 12; + SIN_MASK = ~(-1 << SIN_BITS); + SIN_COUNT = SIN_MASK + 1; - radFull = (float) (Math.PI * 2.0); - degFull = (float) (360.0); - radToIndex = SIN_COUNT / radFull; - degToIndex = SIN_COUNT / degFull; + radFull = (float) (Math.PI * 2.0); + degFull = (float) (360.0); + radToIndex = SIN_COUNT / radFull; + degToIndex = SIN_COUNT / degFull; - sin = new float[SIN_COUNT]; - cos = new float[SIN_COUNT]; + sin = new float[SIN_COUNT]; + cos = new float[SIN_COUNT]; - for (int i = 0; i < SIN_COUNT; i++) - { - sin[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull); - cos[i] = (float) Math.cos((i + 0.5f) / SIN_COUNT * radFull); - } + for (int i = 0; i < SIN_COUNT; i++) { + sin[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull); + cos[i] = (float) Math.cos((i + 0.5f) / SIN_COUNT * radFull); + } - // Four cardinal directions (credits: Nate) - for (int i = 0; i < 360; i += 90) - { - sin[(int)(i * degToIndex) & SIN_MASK] = (float)Math.sin(i * Math.PI / 180.0); - cos[(int)(i * degToIndex) & SIN_MASK] = (float)Math.cos(i * Math.PI / 180.0); - } - } + // Four cardinal directions (credits: Nate) + for (int i = 0; i < 360; i += 90) { + sin[(int) (i * degToIndex) & SIN_MASK] = (float) Math.sin(i * Math.PI / 180.0); + cos[(int) (i * degToIndex) & SIN_MASK] = (float) Math.cos(i * Math.PI / 180.0); + } + } } diff --git a/src/org/warp/picalculator/gui/GraphicalElement.java b/src/org/warp/picalculator/gui/GraphicalElement.java index 867ac64d..22481d97 100644 --- a/src/org/warp/picalculator/gui/GraphicalElement.java +++ b/src/org/warp/picalculator/gui/GraphicalElement.java @@ -3,25 +3,28 @@ package org.warp.picalculator.gui; public interface GraphicalElement { /** - * Recompute element's dimension parameters, like width, height, line or length. + * Recompute element's dimension parameters, like width, + * height, line or + * length. */ public void recomputeDimensions(); - + /** * * @return Width of the element. */ public int getWidth(); - + /** * * @return Height of the element. */ public int getHeight(); - + /** * - * @return Position of the vertical alignment line of the element, relative to itself. + * @return Position of the vertical alignment line of the element, relative + * to itself. */ public int getLine(); } diff --git a/src/org/warp/picalculator/gui/expression/Block.java b/src/org/warp/picalculator/gui/expression/Block.java index 7b70cf4c..b5a5be01 100644 --- a/src/org/warp/picalculator/gui/expression/Block.java +++ b/src/org/warp/picalculator/gui/expression/Block.java @@ -3,21 +3,23 @@ package org.warp.picalculator.gui.expression; import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -import org.warp.picalculator.math.parser.features.interfaces.Feature; public abstract class Block implements GraphicalElement { - + protected boolean small; protected int width; protected int height; protected int line; - + /** * - * @param r Graphic Renderer class. - * @param x Position relative to the window. - * @param y Position relative to the window. - * @param small + * @param r + * Graphic Renderer class. + * @param x + * Position relative to the window. + * @param y + * Position relative to the window. + * @param small */ public abstract void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret); @@ -29,7 +31,7 @@ public abstract class Block implements GraphicalElement { public abstract void recomputeDimensions(); public abstract int computeCaretMaxBound(); - + @Override public int getWidth() { return width; @@ -50,6 +52,6 @@ public abstract class Block implements GraphicalElement { } public abstract void setSmall(boolean small); - + public abstract int getClassID(); } diff --git a/src/org/warp/picalculator/gui/expression/BlockChar.java b/src/org/warp/picalculator/gui/expression/BlockChar.java index c5a75e3f..fbce019d 100644 --- a/src/org/warp/picalculator/gui/expression/BlockChar.java +++ b/src/org/warp/picalculator/gui/expression/BlockChar.java @@ -2,15 +2,13 @@ package org.warp.picalculator.gui.expression; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -import org.warp.picalculator.math.parser.features.FeatureChar; -import org.warp.picalculator.math.parser.features.interfaces.Feature; public class BlockChar extends Block { - + public static final int CLASS_ID = 0x00000001; - + private final char ch; - + public BlockChar(char ch) { this.ch = ch; recomputeDimensions(); @@ -32,12 +30,12 @@ public class BlockChar extends Block { public boolean delBlock(Caret caret) { return false; } - + @Override public void recomputeDimensions() { width = BlockContainer.getDefaultCharWidth(small); height = BlockContainer.getDefaultCharHeight(small); - line = height/2; + line = height / 2; } @Override @@ -45,7 +43,7 @@ public class BlockChar extends Block { this.small = small; recomputeDimensions(); } - + public char getChar() { return ch; } diff --git a/src/org/warp/picalculator/gui/expression/BlockContainer.java b/src/org/warp/picalculator/gui/expression/BlockContainer.java index 2229b596..bd553ab7 100644 --- a/src/org/warp/picalculator/gui/expression/BlockContainer.java +++ b/src/org/warp/picalculator/gui/expression/BlockContainer.java @@ -10,7 +10,7 @@ import org.warp.picalculator.gui.graphicengine.Renderer; public class BlockContainer implements GraphicalElement { private static boolean initialized = false; - + private final int minWidth; private final int minHeight; private final ObjectArrayList content; @@ -19,29 +19,29 @@ public class BlockContainer implements GraphicalElement { private int height; private int line; public final boolean withBorder; - + public BlockContainer() { this(false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true); } - + public BlockContainer(boolean small) { this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), true); } - + public BlockContainer(boolean small, boolean withBorder) { this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), withBorder); } - + public BlockContainer(boolean small, int minWidth, int minHeight, boolean withBorder) { this(small, minWidth, minHeight, new ObjectArrayList<>(), withBorder); } - + public BlockContainer(boolean small, int minWidth, int minHeight, ObjectArrayList content, boolean withBorder) { this.small = small; this.minWidth = minWidth; this.minHeight = minHeight; this.withBorder = withBorder; - for (Block b: content) { + for (final Block b : content) { if (b.isSmall() != small) { b.setSmall(small); } @@ -61,13 +61,17 @@ public class BlockContainer implements GraphicalElement { } recomputeDimensions(); } - + public void appendBlock(Block b) { + appendBlockUnsafe(b); + recomputeDimensions(); + } + + public void appendBlockUnsafe(Block b) { if (b.isSmall() != small) { b.setSmall(small); } content.add(b); - recomputeDimensions(); } public void removeBlock(Block b) { @@ -79,46 +83,53 @@ public class BlockContainer implements GraphicalElement { content.remove(i); recomputeDimensions(); } - + public Block getBlockAt(int i) { return content.get(i); } - + public void clear() { content.clear(); recomputeDimensions(); } - + /** * - * @param ge Graphic Engine class. - * @param r Graphic Renderer class of ge. - * @param x Position relative to the window. - * @param y Position relative to the window. - * @param caret Position of the caret. + * @param ge + * Graphic Engine class. + * @param r + * Graphic Renderer class of ge. + * @param x + * Position relative to the window. + * @param y + * Position relative to the window. + * @param caret + * Position of the caret. */ public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { int paddingX = 1; if (caret.getRemaining() == 0) { if (content.size() > 0) { - BlockContainer.drawCaret(ge, r, caret, x, y+line-content.get(0).line, content.get(0).height); + BlockContainer.drawCaret(ge, r, caret, x, y + line - content.get(0).line, content.get(0).height); } else { BlockContainer.drawCaret(ge, r, caret, x, y, height); } } - + if (withBorder && content.size() == 0) { - r.glDrawLine(x+paddingX, y, x+paddingX+width-1, y); - r.glDrawLine(x+paddingX, y, x+paddingX, y+height-1); - r.glDrawLine(x+paddingX+width-1, y, x+paddingX+width-1, y+height-1); - r.glDrawLine(x+paddingX, y+height-1, x+paddingX+width-1, y+height-1); + r.glDrawLine(x + paddingX, y, x + paddingX + width - 1, y); + r.glDrawLine(x + paddingX, y, x + paddingX, y + height - 1); + r.glDrawLine(x + paddingX + width - 1, y, x + paddingX + width - 1, y + height - 1); + r.glDrawLine(x + paddingX, y + height - 1, x + paddingX + width - 1, y + height - 1); } else { - for (Block b : content) { + for (final Block b : content) { caret.skip(1); - b.draw(ge, r, x+paddingX, y+line-b.line, caret); + b.draw(ge, r, x + paddingX, y + line - b.line, caret); paddingX += b.getWidth(); - if (caret.getRemaining() == 0) BlockContainer.drawCaret(ge, r, caret, x + paddingX, y+line-b.line, b.height); + if (caret.getRemaining() == 0) { + BlockContainer.drawCaret(ge, r, caret, x + paddingX, y + line - b.line, b.height); + } paddingX += 1; } } @@ -129,17 +140,17 @@ public class BlockContainer implements GraphicalElement { boolean added = false; if (caret.getRemaining() == 0) { - this.addBlock(0, newBlock); + addBlock(0, newBlock); added = true; } - + int pos = 0; - for (Block b : content) { + for (final Block b : content) { caret.skip(1); pos++; - added = added|b.putBlock(caret, newBlock); + added = added | b.putBlock(caret, newBlock); if (caret.getRemaining() == 0) { - this.addBlock(pos, newBlock); + addBlock(pos, newBlock); added = true; } } @@ -152,16 +163,16 @@ public class BlockContainer implements GraphicalElement { public boolean delBlock(Caret caret) { boolean removed = false; - + int pos = 0; - for (Block b : content) { + for (final Block b : content) { caret.skip(1); pos++; - int deltaCaret = caret.getRemaining(); - removed = removed|b.delBlock(caret); + final int deltaCaret = caret.getRemaining(); + removed = removed | b.delBlock(caret); if (caret.getRemaining() == 0 || (removed == false && deltaCaret >= 0 && caret.getRemaining() < 0)) { - this.removeAt(pos-1); - caret.setPosition(caret.getPosition()-deltaCaret); + removeAt(pos - 1); + caret.setPosition(caret.getPosition() - deltaCaret); removed = true; } } @@ -172,15 +183,14 @@ public class BlockContainer implements GraphicalElement { return removed; } - @Override public void recomputeDimensions() { int l = 0; //Line int w = 0; //Width int h2 = 0; //Height under the line. h = h2 + l int h = 0; //Height - - for (Block b : content) { + + for (final Block b : content) { w += b.getWidth() + 1; final int bl = b.getLine(); final int bh = b.getHeight(); @@ -192,11 +202,11 @@ public class BlockContainer implements GraphicalElement { h2 = bh2; } } - + if (content.size() > 0) { w -= 1; } - + h = h2 + l; line = l; @@ -209,7 +219,7 @@ public class BlockContainer implements GraphicalElement { height = h; } else { height = minHeight; - line = height/2; + line = height / 2; } } @@ -231,7 +241,7 @@ public class BlockContainer implements GraphicalElement { private static final BinaryFont[] defFonts = new BinaryFont[2]; private static final int[] defFontSizes = new int[4]; private static final int defColor = 0xFF000000; - + public static void initializeFonts(BinaryFont big, BinaryFont small) { defFonts[0] = big; defFonts[1] = small; @@ -241,10 +251,10 @@ public class BlockContainer implements GraphicalElement { defFontSizes[3] = small.getCharacterHeight(); initialized = true; } - + public static BinaryFont getDefaultFont(boolean small) { checkInitialized(); - return defFonts[small?1:0]; + return defFonts[small ? 1 : 0]; } public static int getDefaultColor() { @@ -253,20 +263,20 @@ public class BlockContainer implements GraphicalElement { public static int getDefaultCharWidth(boolean b) { checkInitialized(); - return defFontSizes[b?2:0]; + return defFontSizes[b ? 2 : 0]; } - + public static int getDefaultCharHeight(boolean b) { checkInitialized(); - return defFontSizes[b?3:1]; + return defFontSizes[b ? 3 : 1]; } - + public static void drawCaret(GraphicEngine ge, Renderer r, Caret caret, int x, int y, int height) { if (caret.getState() == CaretState.VISIBLE_ON) { r.glColor(getDefaultColor()); - r.glDrawLine(x, y, x, y-1+height); - r.glDrawLine(x+1, y, x+1, y-1+height); - r.glDrawLine(x+2, y, x+2, y-1+height); + r.glDrawLine(x, y, x, y - 1 + height); + r.glDrawLine(x + 1, y, x + 1, y - 1 + height); + r.glDrawLine(x + 2, y, x + 2, y - 1 + height); } } @@ -278,17 +288,19 @@ public class BlockContainer implements GraphicalElement { public ObjectArrayList getContent() { return content.clone(); } - + private static void checkInitialized() { - if (!initialized) throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!"); + if (!initialized) { + throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!"); + } } public int computeCaretMaxBound() { int maxpos = 0; - for (Block b : content) { - maxpos+=1+b.computeCaretMaxBound(); + for (final Block b : content) { + maxpos += 1 + b.computeCaretMaxBound(); } - return maxpos+1; + return maxpos + 1; } - + } \ No newline at end of file diff --git a/src/org/warp/picalculator/gui/expression/BlockDivision.java b/src/org/warp/picalculator/gui/expression/BlockDivision.java index 12a6d8cd..aa8f83eb 100644 --- a/src/org/warp/picalculator/gui/expression/BlockDivision.java +++ b/src/org/warp/picalculator/gui/expression/BlockDivision.java @@ -1,14 +1,10 @@ package org.warp.picalculator.gui.expression; -import org.warp.picalculator.Main; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -import org.warp.picalculator.math.parser.features.interfaces.Feature; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; public class BlockDivision extends Block { - + public static final int CLASS_ID = 0x00000002; private final BlockContainer containerUp; @@ -17,10 +13,10 @@ public class BlockDivision extends Block { private int paddingLeftUpper; private int paddingLeftLower; private int h1; - + public BlockDivision() { - this.containerUp = new BlockContainer(false); - this.containerDown = new BlockContainer(false); + containerUp = new BlockContainer(false); + containerDown = new BlockContainer(false); recomputeDimensions(); } @@ -28,16 +24,16 @@ public class BlockDivision extends Block { public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { BlockContainer.getDefaultFont(small).use(ge); r.glColor(BlockContainer.getDefaultColor()); - containerUp.draw(ge, r, x+1+paddingLeftUpper, y, caret); - r.glDrawLine(x, y+h1+1, x+width-1, y+h1+1); - containerDown.draw(ge, r, x+1+paddingLeftLower, y + h1+3, caret); + containerUp.draw(ge, r, x + 1 + paddingLeftUpper, y, caret); + r.glDrawLine(x, y + h1 + 1, x + width - 1, y + h1 + 1); + containerDown.draw(ge, r, x + 1 + paddingLeftLower, y + h1 + 3, caret); } @Override public boolean putBlock(Caret caret, Block newBlock) { boolean added = false; - added = added|containerUp.putBlock(caret, newBlock); - added = added|containerDown.putBlock(caret, newBlock); + added = added | containerUp.putBlock(caret, newBlock); + added = added | containerDown.putBlock(caret, newBlock); if (added) { recomputeDimensions(); } @@ -47,8 +43,8 @@ public class BlockDivision extends Block { @Override public boolean delBlock(Caret caret) { boolean removed = false; - removed = removed|containerUp.delBlock(caret); - removed = removed|containerDown.delBlock(caret); + removed = removed | containerUp.delBlock(caret); + removed = removed | containerDown.delBlock(caret); if (removed) { recomputeDimensions(); } @@ -61,9 +57,9 @@ public class BlockDivision extends Block { final int w2 = containerDown.getWidth(); final int h1 = containerUp.getHeight(); final int h2 = containerDown.getHeight(); - width = (w1>w2?w1:w2) + 4; - height = h1+3+h2; - line = h1+1; + width = (w1 > w2 ? w1 : w2) + 4; + height = h1 + 3 + h2; + line = h1 + 1; this.h1 = h1; if (w1 != w2) { if (w1 > w2) { @@ -82,15 +78,15 @@ public class BlockDivision extends Block { @Override public void setSmall(boolean small) { this.small = small; - this.containerUp.setSmall(small); - this.containerDown.setSmall(small); + containerUp.setSmall(small); + containerDown.setSmall(small); recomputeDimensions(); } public BlockContainer getUpperContainer() { return containerUp; } - + public BlockContainer getLowerContainer() { return containerDown; } @@ -102,6 +98,6 @@ public class BlockDivision extends Block { @Override public int computeCaretMaxBound() { - return containerUp.computeCaretMaxBound()+containerDown.computeCaretMaxBound(); + return containerUp.computeCaretMaxBound() + containerDown.computeCaretMaxBound(); } } diff --git a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java b/src/org/warp/picalculator/gui/expression/BlockParenthesis.java index 1ad4fa05..91c89e27 100644 --- a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java +++ b/src/org/warp/picalculator/gui/expression/BlockParenthesis.java @@ -4,27 +4,27 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; public class BlockParenthesis extends Block { - + public static final int CLASS_ID = 0x00000004; private final BlockContainer containerNumber; public BlockParenthesis() { - this.containerNumber = new BlockContainer(false); + containerNumber = new BlockContainer(false); recomputeDimensions(); } - + @Override public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { BlockContainer.getDefaultFont(small).use(ge); r.glColor(BlockContainer.getDefaultColor()); - containerNumber.draw(ge, r, x+7, y+3, caret); + containerNumber.draw(ge, r, x + 7, y + 3, caret); } @Override public boolean putBlock(Caret caret, Block newBlock) { boolean added = false; - added = added|containerNumber.putBlock(caret, newBlock); + added = added | containerNumber.putBlock(caret, newBlock); if (added) { recomputeDimensions(); } @@ -34,7 +34,7 @@ public class BlockParenthesis extends Block { @Override public boolean delBlock(Caret caret) { boolean removed = false; - removed = removed|containerNumber.delBlock(caret); + removed = removed | containerNumber.delBlock(caret); if (removed) { recomputeDimensions(); } @@ -43,15 +43,15 @@ public class BlockParenthesis extends Block { @Override public void recomputeDimensions() { - this.width = containerNumber.getWidth()+BlockContainer.getDefaultCharWidth(small)*2; - this.height = containerNumber.getHeight(); - this.line = containerNumber.getLine(); + width = containerNumber.getWidth() + BlockContainer.getDefaultCharWidth(small) * 2; + height = containerNumber.getHeight(); + line = containerNumber.getLine(); } @Override public void setSmall(boolean small) { this.small = small; - this.containerNumber.setSmall(small); + containerNumber.setSmall(small); recomputeDimensions(); } diff --git a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java b/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java index 87af3e3b..5889249c 100644 --- a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java +++ b/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java @@ -1,22 +1,18 @@ package org.warp.picalculator.gui.expression; -import org.warp.picalculator.Main; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -import org.warp.picalculator.math.parser.features.interfaces.Feature; - -import it.unimi.dsi.fastutil.objects.ObjectArrayList; public class BlockSquareRoot extends Block { - + public static final int CLASS_ID = 0x00000003; private final BlockContainer containerNumber; - + private int h1; - + public BlockSquareRoot() { - this.containerNumber = new BlockContainer(false); + containerNumber = new BlockContainer(false); recomputeDimensions(); } @@ -24,21 +20,21 @@ public class BlockSquareRoot extends Block { public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { BlockContainer.getDefaultFont(small).use(ge); r.glColor(BlockContainer.getDefaultColor()); - r.glDrawLine(x, y+height-10+1, x, y+height-10+2); // / - r.glDrawLine(x+1, y+height-10, x+1, y+height-10+1); // / - r.glDrawLine(x+2, y+height-10+2, x+2, y+height-10+6); // \ - r.glDrawLine(x+3, y+height-10+7, x+3, y+height-10+9); // \ - r.glDrawLine(x+5, y+height-h1-1-2, x+width-1, y+height-h1-1-2); // ---- - r.glDrawLine(x+5, y+height-h1-1-2, x+5, y+height-(h1-2)/3f*2f-1); // | - r.glDrawLine(x+4, y+height-(h1-2)/3f*2f-1, x+4, y+height-(h1-2)/3f-1); // | - r.glDrawLine(x+3, y+height-(h1-2)/3f-1, x+3, y+height-1); // | - containerNumber.draw(ge, r, x+7, y+3, caret); + r.glDrawLine(x, y + height - 10 + 1, x, y + height - 10 + 2); // / + r.glDrawLine(x + 1, y + height - 10, x + 1, y + height - 10 + 1); // / + r.glDrawLine(x + 2, y + height - 10 + 2, x + 2, y + height - 10 + 6); // \ + r.glDrawLine(x + 3, y + height - 10 + 7, x + 3, y + height - 10 + 9); // \ + r.glDrawLine(x + 5, y + height - h1 - 1 - 2, x + width - 1, y + height - h1 - 1 - 2); // ---- + r.glDrawLine(x + 5, y + height - h1 - 1 - 2, x + 5, y + height - (h1 - 2) / 3f * 2f - 1); // | + r.glDrawLine(x + 4, y + height - (h1 - 2) / 3f * 2f - 1, x + 4, y + height - (h1 - 2) / 3f - 1); // | + r.glDrawLine(x + 3, y + height - (h1 - 2) / 3f - 1, x + 3, y + height - 1); // | + containerNumber.draw(ge, r, x + 7, y + 3, caret); } @Override public boolean putBlock(Caret caret, Block newBlock) { boolean added = false; - added = added|containerNumber.putBlock(caret, newBlock); + added = added | containerNumber.putBlock(caret, newBlock); if (added) { recomputeDimensions(); } @@ -48,7 +44,7 @@ public class BlockSquareRoot extends Block { @Override public boolean delBlock(Caret caret) { boolean removed = false; - removed = removed|containerNumber.delBlock(caret); + removed = removed | containerNumber.delBlock(caret); if (removed) { recomputeDimensions(); } @@ -60,19 +56,19 @@ public class BlockSquareRoot extends Block { final int w1 = containerNumber.getWidth(); h1 = containerNumber.getHeight(); final int l1 = containerNumber.getLine(); - width = 8+w1+2; - height = 3+h1; - line = 3+l1; + width = 8 + w1 + 2; + height = 3 + h1; + line = 3 + l1; if (height < 9) { height = 9; - line+=(9-(3+h1)); + line += (9 - (3 + h1)); } } @Override public void setSmall(boolean small) { this.small = small; - this.containerNumber.setSmall(small); + containerNumber.setSmall(small); recomputeDimensions(); } diff --git a/src/org/warp/picalculator/gui/expression/Caret.java b/src/org/warp/picalculator/gui/expression/Caret.java index 736e5c89..8c4f1714 100644 --- a/src/org/warp/picalculator/gui/expression/Caret.java +++ b/src/org/warp/picalculator/gui/expression/Caret.java @@ -5,45 +5,45 @@ public class Caret { private int pos; private int remaining; private CaretState state; - + public Caret(CaretState state, int pos) { this.state = state; this.pos = pos; - this.remaining = pos; + remaining = pos; } - + public void skip(int i) { - remaining-=i; + remaining -= i; } - + public int getPosition() { return pos; } - + public int getRemaining() { return remaining; } - + public CaretState getState() { return state; } - + public void flipState() { - if (this.state == CaretState.VISIBLE_ON) { - this.state = CaretState.VISIBLE_OFF; - } else if (this.state == CaretState.VISIBLE_OFF) { - this.state = CaretState.VISIBLE_ON; + if (state == CaretState.VISIBLE_ON) { + state = CaretState.VISIBLE_OFF; + } else if (state == CaretState.VISIBLE_OFF) { + state = CaretState.VISIBLE_ON; } } public void turnOn() { - if (this.state == CaretState.VISIBLE_OFF) { - this.state = CaretState.VISIBLE_ON; + if (state == CaretState.VISIBLE_OFF) { + state = CaretState.VISIBLE_ON; } } public void setPosition(int i) { - this.pos = i; + pos = i; } public void resetRemaining() { diff --git a/src/org/warp/picalculator/gui/expression/CaretState.java b/src/org/warp/picalculator/gui/expression/CaretState.java index a5d63be0..94b77e97 100644 --- a/src/org/warp/picalculator/gui/expression/CaretState.java +++ b/src/org/warp/picalculator/gui/expression/CaretState.java @@ -1,7 +1,5 @@ package org.warp.picalculator.gui.expression; public enum CaretState { - VISIBLE_ON, - VISIBLE_OFF, - HIDDEN + VISIBLE_ON, VISIBLE_OFF, HIDDEN } diff --git a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java index ee07e524..3dff2f57 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java @@ -5,19 +5,19 @@ import org.warp.picalculator.gui.expression.BlockChar; import org.warp.picalculator.math.MathematicalSymbols; public class InlineInputContainer extends InputContainer { - + public InlineInputContainer() { super(); } - + public InlineInputContainer(boolean small) { super(small); } - + public InlineInputContainer(boolean small, int minWidth, int minHeight) { super(small, minWidth, minHeight); } - + @Override public Block parseChar(char c) { return new BlockChar(MathematicalSymbols.DIVISION); diff --git a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java index 4fbdebe8..6f734fb6 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java @@ -1,5 +1,8 @@ package org.warp.picalculator.gui.expression.containers; +import java.io.ObjectOutputStream; +import java.io.Serializable; + import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockContainer; @@ -9,42 +12,47 @@ import org.warp.picalculator.gui.expression.layouts.InputLayout; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -public abstract class InputContainer implements GraphicalElement, InputLayout { - public final BlockContainer root; +import it.unimi.dsi.fastutil.Arrays; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +public abstract class InputContainer implements GraphicalElement, InputLayout, Serializable { + private static final long serialVersionUID = 923589369317765667L; + private final BlockContainer root; private Caret caret; private static final float CARET_DURATION = 0.5f; private float caretTime; private int maxPosition = 0; - + private boolean parsed = false; + public InputContainer() { caret = new Caret(CaretState.VISIBLE_ON, 0); root = new BlockContainer(false, false); } - + public InputContainer(boolean small) { caret = new Caret(CaretState.VISIBLE_ON, 0); root = new BlockContainer(small, false); } - + public InputContainer(boolean small, int minWidth, int minHeight) { caret = new Caret(CaretState.VISIBLE_ON, 0); root = new BlockContainer(small, false); } - + public void typeChar(char c) { - Block b = parseChar(c); + final Block b = parseChar(c); if (b != null) { caret.resetRemaining(); if (root.putBlock(caret, b)) { - caret.setPosition(caret.getPosition()+1); - maxPosition=root.computeCaretMaxBound(); + caret.setPosition(caret.getPosition() + 1); + maxPosition = root.computeCaretMaxBound(); root.recomputeDimensions(); } } caretTime = 0; caret.turnOn(); } - + public void typeChar(String c) { typeChar(c.charAt(0)); } @@ -55,26 +63,26 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { root.recomputeDimensions(); } if (caret.getPosition() > 0) { - caret.setPosition(caret.getPosition()-1); - maxPosition=root.computeCaretMaxBound(); + caret.setPosition(caret.getPosition() - 1); + maxPosition = root.computeCaretMaxBound(); } caret.turnOn(); caretTime = 0; } public void moveLeft() { - int curPos = caret.getPosition(); + final int curPos = caret.getPosition(); if (curPos > 0) { - caret.setPosition(curPos-1); + caret.setPosition(curPos - 1); } caret.turnOn(); caretTime = 0; } public void moveRight() { - int curPos = caret.getPosition(); - if (curPos+1 < maxPosition) { - caret.setPosition(curPos+1); + final int curPos = caret.getPosition(); + if (curPos + 1 < maxPosition) { + caret.setPosition(curPos + 1); } caret.turnOn(); caretTime = 0; @@ -98,11 +106,12 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { @Override public int getLine() { return root.getLine(); - } - + } + /** * - * @param delta Time, in seconds + * @param delta + * Time, in seconds * @return true if something changed */ public boolean beforeRender(float delta) { @@ -115,16 +124,20 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { somethingChanged = true; } } - + return somethingChanged; } - + /** * - * @param ge Graphic Engine class. - * @param r Graphic Renderer class of ge. - * @param x Position relative to the window. - * @param y Position relative to the window. + * @param ge + * Graphic Engine class. + * @param r + * Graphic Renderer class of ge. + * @param x + * Position relative to the window. + * @param y + * Position relative to the window. */ public void draw(GraphicEngine ge, Renderer r, int x, int y) { caret.resetRemaining(); @@ -134,7 +147,40 @@ public abstract class InputContainer implements GraphicalElement, InputLayout { public void clear() { caret = new Caret(CaretState.VISIBLE_ON, 0); root.clear(); - maxPosition=root.computeCaretMaxBound(); + maxPosition = root.computeCaretMaxBound(); recomputeDimensions(); } + + public boolean isEmpty() { + return maxPosition <= 1; + } + + public int getCaretMaxPosition() { + return maxPosition; + } + + public void setCaretPosition(int pos) { + if (pos > 0 && pos < maxPosition) { + caret.setPosition(pos); + } + caret.turnOn(); + caretTime = 0; + } + + public void setParsed(boolean parsed) { + this.parsed = parsed; + } + + public boolean isAlreadyParsed() { + return parsed; + } + + /** + * WARNING! DO NOT MODIFY THIS ARRAY!!! + * + * @return an arraylist representing the content + */ + public ObjectArrayList getContent() { + return root.getContent(); + } } diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java index 00ec17f4..ec6aadd8 100644 --- a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java @@ -2,31 +2,28 @@ package org.warp.picalculator.gui.expression.containers; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockChar; -import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.BlockDivision; import org.warp.picalculator.gui.expression.BlockParenthesis; import org.warp.picalculator.gui.expression.BlockSquareRoot; -import org.warp.picalculator.gui.expression.Caret; -import org.warp.picalculator.gui.expression.CaretState; import org.warp.picalculator.math.MathematicalSymbols; public class NormalInputContainer extends InputContainer { - + public NormalInputContainer() { super(); } - + public NormalInputContainer(boolean small) { super(small); } - + public NormalInputContainer(boolean small, int minWidth, int minHeight) { super(small, minWidth, minHeight); } - + @Override public Block parseChar(char c) { - switch(c) { + switch (c) { case MathematicalSymbols.DIVISION: return new BlockDivision(); case MathematicalSymbols.SQUARE_ROOT: diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java index 53f8b554..1ca2e426 100644 --- a/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/NormalOutputContainer.java @@ -4,11 +4,11 @@ public class NormalOutputContainer extends OutputContainer { public NormalOutputContainer() { super(); } - + public NormalOutputContainer(boolean small) { super(small); } - + public NormalOutputContainer(boolean small, int minWidth, int minHeight) { super(small, minWidth, minHeight); } diff --git a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java index 07a52a83..a751b256 100644 --- a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java @@ -1,29 +1,41 @@ package org.warp.picalculator.gui.expression.containers; +import java.io.Serializable; + import org.warp.picalculator.gui.GraphicalElement; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.expression.CaretState; -import org.warp.picalculator.gui.expression.layouts.InputLayout; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; -public abstract class OutputContainer implements GraphicalElement, OutputLayout { +import it.unimi.dsi.fastutil.objects.ObjectArrayList; + +public abstract class OutputContainer implements GraphicalElement, OutputLayout, Serializable { + private static final long serialVersionUID = -5714825964892683571L; public final BlockContainer root; private final Caret caret = new Caret(CaretState.HIDDEN, 0); - + public OutputContainer() { root = new BlockContainer(); } - + public OutputContainer(boolean small) { root = new BlockContainer(small); } - + public OutputContainer(boolean small, int minWidth, int minHeight) { root = new BlockContainer(small); } + + public void setContent(ObjectArrayList blocks) { + root.clear(); + for (Block b : blocks) { + root.appendBlockUnsafe(b); + } + recomputeDimensions(); + } @Override public void recomputeDimensions() { @@ -43,22 +55,27 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout @Override public int getLine() { return root.getLine(); - } - + } + /** * - * @param delta Time, in seconds + * @param delta + * Time, in seconds */ public void beforeRender(double delta) { - + } - + /** * - * @param ge Graphic Engine class. - * @param r Graphic Renderer class of ge. - * @param x Position relative to the window. - * @param y Position relative to the window. + * @param ge + * Graphic Engine class. + * @param r + * Graphic Renderer class of ge. + * @param x + * Position relative to the window. + * @param y + * Position relative to the window. */ public void draw(GraphicEngine ge, Renderer r, int x, int y) { root.draw(ge, r, x, y, caret); diff --git a/src/org/warp/picalculator/gui/graphicengine/GraphicEngine.java b/src/org/warp/picalculator/gui/graphicengine/GraphicEngine.java index 42db692c..c03d95c5 100644 --- a/src/org/warp/picalculator/gui/graphicengine/GraphicEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/GraphicEngine.java @@ -37,6 +37,6 @@ public interface GraphicEngine { public void waitUntilExit(); public boolean isSupported(); - + public boolean doesRefreshPauses(); } diff --git a/src/org/warp/picalculator/gui/graphicengine/Renderer.java b/src/org/warp/picalculator/gui/graphicengine/Renderer.java index d3f1984c..c0dd3a49 100644 --- a/src/org/warp/picalculator/gui/graphicengine/Renderer.java +++ b/src/org/warp/picalculator/gui/graphicengine/Renderer.java @@ -1,7 +1,5 @@ package org.warp.picalculator.gui.graphicengine; -import java.awt.FontMetrics; - public interface Renderer { public void glColor3i(int r, int gg, int b); @@ -25,22 +23,23 @@ public interface Renderer { public void glDrawLine(float x0, float y0, float x1, float y1); - public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight); + public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, + float uvHeight); public void glFillColor(float x, float y, float width, float height); public void glDrawCharLeft(int x, int y, char ch); - + public void glDrawCharCenter(int x, int y, char ch); - + public void glDrawCharRight(int x, int y, char ch); - + public void glDrawStringLeft(float x, float y, String text); public void glDrawStringCenter(float x, float y, String text); public void glDrawStringRight(float x, float y, String text); - + public void glClearSkin(); public BinaryFont getCurrentFont(); diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java index 7f9f1f56..2aa2c979 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUEngine.java @@ -45,7 +45,7 @@ public class CPUEngine implements GraphicEngine { g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB); INSTANCE.wasResized = false; } - + @Override public void create() { INSTANCE = new SwingWindow(this); @@ -87,7 +87,7 @@ public class CPUEngine implements GraphicEngine { @Override public void start(RenderingLoop d) { INSTANCE.setRenderingLoop(d); - Thread th = new Thread(() -> { + final Thread th = new Thread(() -> { try { double extratime = 0; while (initialized) { @@ -171,7 +171,7 @@ public class CPUEngine implements GraphicEngine { @Override public void glClearColor4f(float red, float green, float blue, float alpha) { - clearcolor = ((int)(alpha*255) << 24) + ((int)(red*255) << 16) + ((int)(green*255) << 8) + ((int)(blue*255)); + clearcolor = ((int) (alpha * 255) << 24) + ((int) (red * 255) << 16) + ((int) (green * 255) << 8) + ((int) (blue * 255)); } @Override @@ -269,13 +269,13 @@ public class CPUEngine implements GraphicEngine { } if (iy0 == iy1) { for (int x = 0; x <= ix1 - ix0; x++) { - if ((ix0+x < size[0]) & (iy0 < size[1])) { + if ((ix0 + x < size[0]) & (iy0 < size[1])) { canvas2d[ix0 + x + iy0 * size[0]] = color; } } } else if (ix0 == ix1) { for (int y = 0; y <= iy1 - iy0; y++) { - if ((ix0 < size[0]) & (iy0+y < size[1])) { + if ((ix0 < size[0]) & (iy0 + y < size[1])) { canvas2d[ix0 + (iy0 + y) * size[0]] = color; } } @@ -305,12 +305,12 @@ public class CPUEngine implements GraphicEngine { public void glFillColor(float x, float y, float width, float height) { x += Main.screenPos[0]; y += Main.screenPos[1]; - + final int ix = (int) x; final int iy = (int) y; final int iw = (int) width; final int ih = (int) height; - + int x1 = ix + iw; int y1 = iy + ih; if (ix >= size[0] || iy >= size[0]) { @@ -337,7 +337,7 @@ public class CPUEngine implements GraphicEngine { final int ix = (int) x; final int iy = (int) y; - + final int[] text = currentFont.getCharIndexes(textString); final int[] screen = canvas2d; final int[] screenSize = size; @@ -418,17 +418,17 @@ public class CPUEngine implements GraphicEngine { @Override public void glDrawCharLeft(int x, int y, char ch) { - glDrawStringLeft(x, y, ch+""); + glDrawStringLeft(x, y, ch + ""); } @Override public void glDrawCharCenter(int x, int y, char ch) { - glDrawStringCenter(x, y, ch+""); + glDrawStringCenter(x, y, ch + ""); } @Override public void glDrawCharRight(int x, int y, char ch) { - glDrawStringRight(x, y, ch+""); + glDrawStringRight(x, y, ch + ""); } } @@ -463,9 +463,9 @@ public class CPUEngine implements GraphicEngine { try { do { Thread.sleep(500); - } while(initialized); - } catch (InterruptedException e) { - + } while (initialized); + } catch (final InterruptedException e) { + } } diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java index 3a5b5598..511bc704 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/CPUSkin.java @@ -5,7 +5,6 @@ import java.io.IOException; import javax.imageio.ImageIO; -import org.warp.picalculator.Main; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Skin; import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine.CPURenderer; @@ -21,7 +20,7 @@ public class CPUSkin implements Skin { @Override public void load(String file) throws IOException { - final BufferedImage img = ImageIO.read(this.getClass().getResource("/"+file)); + final BufferedImage img = ImageIO.read(this.getClass().getResource("/" + file)); skinData = getMatrixOfImage(img); skinSize = new int[] { img.getWidth(), img.getHeight() }; } diff --git a/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java b/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java index ac29e302..3326ef7b 100644 --- a/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java +++ b/src/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java @@ -221,7 +221,7 @@ public class SwingWindow extends JFrame { public int getHeight() { return c.getHeight(); } - + public void setRenderingLoop(RenderingLoop renderingLoop) { this.renderingLoop = renderingLoop; } @@ -240,21 +240,21 @@ public class SwingWindow extends JFrame { // long time1 = System.nanoTime(); if (renderingLoop != null) { renderingLoop.refresh(); - + final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData(); - // System.arraycopy(canvas2d, 0, a, 0, canvas2d.length); + // System.arraycopy(canvas2d, 0, a, 0, canvas2d.length); CPUEngine.canvas2d = a; g.clearRect(0, 0, display.size[0], display.size[1]); g.drawImage(display.g, 0, 0, null); - // long time2 = System.nanoTime(); - // double timeDelta = ((double)(time2-time1))/1000000000d; - // double mediaAttuale = timeDelta; - // mediaValori.add(mediaAttuale); - // double somma = 0; - // for (Double val : mediaValori) { - // somma+=val; - // } - // System.out.println(somma/((double)mediaValori.size())); + // long time2 = System.nanoTime(); + // double timeDelta = ((double)(time2-time1))/1000000000d; + // double mediaAttuale = timeDelta; + // mediaValori.add(mediaAttuale); + // double somma = 0; + // for (Double val : mediaValori) { + // somma+=val; + // } + // System.out.println(somma/((double)mediaValori.size())); } } } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java b/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java index 80b53179..64184da1 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/DeallocationHelper.java @@ -401,15 +401,15 @@ public class DeallocationHelper { attachmentOrByteBufferFieldMap.put(bufferClass, bufferField); } } catch (final ClassNotFoundException cnfe) {// TODO The Java version - // isn't very useful - // under - // Android as it is - // always zero, rather - // use - // android.os.Build.VERSION.RELEASE - // to show something - // meaningful supported - // since the API level 1 + // isn't very useful + // under + // Android as it is + // always zero, rather + // use + // android.os.Build.VERSION.RELEASE + // to show something + // meaningful supported + // since the API level 1 final String msg = "The class " + classname + " hasn't been found while initializing the deallocator. Java vendor: " + javaVendor + " Java version: " + javaVersion; logger.log(Level.WARNING, msg, cnfe); } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java index 276687f6..13d0eabb 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUEngine.java @@ -9,7 +9,6 @@ import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Skin; import com.jogamp.opengl.GLProfile; -import com.jogamp.opengl.egl.EGL; public class GPUEngine implements org.warp.picalculator.gui.graphicengine.GraphicEngine { @@ -18,7 +17,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi private NEWTWindow wnd; private RenderingLoop d; private GPURenderer r; - int[] size = new int[]{Main.screenSize[0], Main.screenSize[1]}; + int[] size = new int[] { Main.screenSize[0], Main.screenSize[1] }; @Override public int[] getSize() { @@ -47,9 +46,9 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi @Override public void setDisplayMode(int ww, int wh) { - this.size[0] = ww; - this.size[1] = wh; - wnd.window.setSize(Utils.debugOn?ww*2:ww, Utils.debugOn?wh*2:wh); + size[0] = ww; + size[1] = wh; + wnd.window.setSize(Utils.debugOn ? ww * 2 : ww, Utils.debugOn ? wh * 2 : wh); } @Override @@ -93,7 +92,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi @Override public void repaint() { - if (d != null & r != null && r.gl != null) { + if (d != null & r != null && GPURenderer.gl != null) { d.refresh(); } } @@ -118,15 +117,15 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi try { do { Thread.sleep(500); - } while(initialized | created); - } catch (InterruptedException e) { - + } while (initialized | created); + } catch (final InterruptedException e) { + } } @Override public boolean isSupported() { - boolean available = GLProfile.isAvailable(GLProfile.GL2ES1); + final boolean available = GLProfile.isAvailable(GLProfile.GL2ES1); if (!available) { System.err.println(GLProfile.glAvailabilityToString()); } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java index 522192ba..d99a0da6 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUFont.java @@ -1,11 +1,8 @@ package org.warp.picalculator.gui.graphicengine.gpu; import java.awt.image.BufferedImage; -import java.io.File; import java.io.IOException; -import javax.imageio.ImageIO; - import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.cpu.CPUFont; @@ -44,7 +41,7 @@ public class GPUFont implements BinaryFont { tmpFont = font; font = null; } - + public int[] getCharIndexes(String txt) { final int l = txt.length(); final int[] indexes = new int[l]; @@ -54,7 +51,7 @@ public class GPUFont implements BinaryFont { } return indexes; } - + public int getCharIndex(char ch) { return (ch & 0xFFFF) - minCharIndex; } @@ -72,7 +69,7 @@ public class GPUFont implements BinaryFont { if (currentChar != null && currentChar.length > 0) { for (int charY = 0; charY < charH; charY++) { for (int charX = 0; charX < charW; charX++) { - if (currentChar[charY*charW+charX]) { + if (currentChar[charY * charW + charX]) { bfi.setRGB(indexX * charW + charX, indexY * charH + charY, 0xFFFFFFFF); } } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java index 1f10c170..1a859145 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPURenderer.java @@ -1,6 +1,5 @@ package org.warp.picalculator.gui.graphicengine.gpu; -import java.awt.FontMetrics; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -33,19 +32,19 @@ public class GPURenderer implements Renderer { int fbElements; float[] currentColor = new float[16]; - float[] currentClearColorARGBf = new float[]{1f, 197f/255f, 194f/255f, 175f/255f}; + float[] currentClearColorARGBf = new float[] { 1f, 197f / 255f, 194f / 255f, 175f / 255f }; boolean currentTexEnabled; Texture currentTex; float currentTexWidth; float currentTexHeight; - + GPUFont currentFont; @Override public void glColor3i(int r, int gg, int b) { - final float red = ((float)r) / 255f; - final float gre = ((float)gg) / 255f; - final float blu = ((float)b) / 255f; + final float red = (r) / 255f; + final float gre = (gg) / 255f; + final float blu = (b) / 255f; currentColor = new float[] { red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, }; } @@ -70,15 +69,15 @@ public class GPURenderer implements Renderer { @Override public int glGetClearColor() { - return (int)(currentClearColorARGBf[0] * 255) << 24 | (int)(currentClearColorARGBf[1] * 255) << 16 | (int)(currentClearColorARGBf[2] * 255) << 8 | (int)(currentClearColorARGBf[3] * 255); + return (int) (currentClearColorARGBf[0] * 255) << 24 | (int) (currentClearColorARGBf[1] * 255) << 16 | (int) (currentClearColorARGBf[2] * 255) << 8 | (int) (currentClearColorARGBf[3] * 255); } @Override public void glClearColor(int rgb) { - final float alpha = (float)((rgb >> 24) & 0xFF) / 255f; - final float red = (float)((rgb >> 16) & 0xFF) / 255f; - final float green = (float)((rgb >> 8) & 0xFF) / 255f; - final float blue = (float)(rgb & 0xFF) / 255f; + final float alpha = ((rgb >> 24) & 0xFF) / 255f; + final float red = ((rgb >> 16) & 0xFF) / 255f; + final float green = ((rgb >> 8) & 0xFF) / 255f; + final float blue = (rgb & 0xFF) / 255f; glClearColor4f(red, green, blue, alpha); } @@ -97,12 +96,12 @@ public class GPURenderer implements Renderer { final float gre = (green) / 255f; final float blu = (blue) / 255f; final float alp = (alpha) / 255f; - currentClearColorARGBf = new float[]{alp, ros, gre, blu}; + currentClearColorARGBf = new float[] { alp, ros, gre, blu }; } @Override public void glClearColor4f(float red, float green, float blue, float alpha) { - currentClearColorARGBf = new float[]{alpha, red, green, blue}; + currentClearColorARGBf = new float[] { alpha, red, green, blue }; } @Override @@ -113,16 +112,17 @@ public class GPURenderer implements Renderer { @Override public void glDrawLine(float x0, float y0, float x1, float y1) { - glFillColor(x0, y0, x1-x0+1, y1-y0+1); + glFillColor(x0, y0, x1 - x0 + 1, y1 - y0 + 1); } @Override - public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) { + public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, + float uvHeight) { enableTexture(); - uvWidth/=currentTexWidth; - uvX/=currentTexWidth; - uvHeight/=currentTexHeight; - uvY = 1 - uvY/currentTexHeight - uvHeight; + uvWidth /= currentTexWidth; + uvX /= currentTexWidth; + uvHeight /= currentTexHeight; + uvY = 1 - uvY / currentTexHeight - uvHeight; final float[] vertices = { x, y, 0.0f, x, y + height, 0.0f, x + width, y, 0.0f, x + width, y + height, 0.0f, }; final float[] tex_vertices = { uvX, uvY + uvHeight, uvX, uvY, uvX + uvWidth, uvY + uvHeight, uvX + uvWidth, uvY, }; fbElements++; @@ -145,13 +145,13 @@ public class GPURenderer implements Renderer { @Override public void glDrawStringLeft(float x, float y, String text) { final int txtLen = text.length(); - int[] txtArray = currentFont.getCharIndexes(text); + final int[] txtArray = currentFont.getCharIndexes(text); int tableIndexX; int tableIndexY; for (int currentCharIndex = 0; currentCharIndex < txtLen; currentCharIndex++) { tableIndexX = txtArray[currentCharIndex] % currentFont.memoryWidthOfEachColumn; tableIndexY = (txtArray[currentCharIndex] - tableIndexX) / currentFont.memoryWidthOfEachColumn; - glFillRect(x + ((float)currentCharIndex) * ((float)(currentFont.charW)), y, currentFont.charW, currentFont.charH, tableIndexX*currentFont.charW, tableIndexY*currentFont.charH, currentFont.charW, currentFont.charH); + glFillRect(x + ((float) currentCharIndex) * ((float) (currentFont.charW)), y, currentFont.charW, currentFont.charH, tableIndexX * currentFont.charW, tableIndexY * currentFont.charH, currentFont.charW, currentFont.charH); } } @@ -167,10 +167,10 @@ public class GPURenderer implements Renderer { @Override public void glDrawCharLeft(int x, int y, char ch) { - int index = currentFont.getCharIndex(ch); - int tableIndexX = index % currentFont.memoryWidthOfEachColumn; - int tableIndexY = (index - tableIndexX) / currentFont.memoryWidthOfEachColumn; - glFillRect(x, y, currentFont.charW, currentFont.charH, tableIndexX*currentFont.charW, tableIndexY*currentFont.charH, currentFont.charW, currentFont.charH); + final int index = currentFont.getCharIndex(ch); + final int tableIndexX = index % currentFont.memoryWidthOfEachColumn; + final int tableIndexY = (index - tableIndexX) / currentFont.memoryWidthOfEachColumn; + glFillRect(x, y, currentFont.charW, currentFont.charH, tableIndexX * currentFont.charW, tableIndexY * currentFont.charH, currentFont.charW, currentFont.charH); } @Override @@ -208,7 +208,7 @@ public class GPURenderer implements Renderer { final ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(img, "png", os); final InputStream fis = new ByteArrayInputStream(os.toByteArray()); - Texture tex = TextureIO.newTexture(fis, false, TextureIO.PNG); + final Texture tex = TextureIO.newTexture(fis, false, TextureIO.PNG); tex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); tex.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); return tex; @@ -234,7 +234,7 @@ public class GPURenderer implements Renderer { private boolean precTexEnabled; private Texture precTex; - + public void endDrawCycle() { fbVertices.rewind(); txVertices.rewind(); @@ -248,14 +248,14 @@ public class GPURenderer implements Renderer { precTexEnabled = currentTexEnabled; precTex = currentTex; if (currentTexEnabled) { - gl.glEnable(GL2ES1.GL_TEXTURE_2D); + gl.glEnable(GL.GL_TEXTURE_2D); currentTex.bind(gl); } else { - gl.glDisable(GL2ES1.GL_TEXTURE_2D); + gl.glDisable(GL.GL_TEXTURE_2D); } } - gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, fbElements*4); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, fbElements * 4); // deleteBuffer(fbVertices); // deleteBuffer(txVertices); diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUSkin.java b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUSkin.java index 531bdcfc..5806a918 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/GPUSkin.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/GPUSkin.java @@ -5,6 +5,7 @@ import java.io.IOException; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Skin; +import com.jogamp.opengl.GL; import com.jogamp.opengl.GL2ES1; import com.jogamp.opengl.GLException; import com.jogamp.opengl.util.texture.Texture; @@ -33,12 +34,12 @@ public class GPUSkin implements Skin { @Override public void initialize(GraphicEngine d) { try { - BufferedImage i = GPURenderer.openTexture(texturePath); - GL2ES1 gl = ((GPURenderer)d.getRenderer()).gl; + final BufferedImage i = GPURenderer.openTexture(texturePath); + final GL2ES1 gl = GPURenderer.gl; t = GPURenderer.importTexture(i); w = i.getWidth(); h = i.getHeight(); - t.setTexParameteri(gl, GL2ES1.GL_TEXTURE_MAG_FILTER, GL2ES1.GL_NEAREST); + t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); initialized = true; } catch (GLException | IOException e) { e.printStackTrace(); @@ -52,7 +53,7 @@ public class GPUSkin implements Skin { initialize(d); } final GPURenderer r = (GPURenderer) d.getRenderer(); - r.useTexture(t,w,h); + r.useTexture(t, w, h); } } diff --git a/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java b/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java index 663a6efc..ff143ecc 100644 --- a/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java +++ b/src/org/warp/picalculator/gui/graphicengine/gpu/NEWTWindow.java @@ -33,13 +33,10 @@ import com.jogamp.opengl.GL2ES1; import com.jogamp.opengl.GLAutoDrawable; import com.jogamp.opengl.GLEventListener; import com.jogamp.opengl.GLProfile; +import com.jogamp.opengl.fixedfunc.GLLightingFunc; import com.jogamp.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.opengl.fixedfunc.GLPointerFunc; import com.jogamp.opengl.GLCapabilities; -import com.jogamp.nativewindow.util.DimensionImmutable; -import com.jogamp.nativewindow.util.PixelFormat; -import com.jogamp.nativewindow.util.PixelRectangle; -import com.jogamp.newt.NewtFactory; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.event.KeyListener; import com.jogamp.newt.event.WindowEvent; @@ -49,16 +46,10 @@ import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.util.*; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.nio.ByteBuffer; -import java.util.Collection; - import org.warp.picalculator.Utils; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.GraphicEngine; /** * @@ -93,15 +84,15 @@ class NEWTWindow implements GLEventListener { caps.setSampleBuffers(false); final GLWindow glWindow = GLWindow.create(caps); window = glWindow; - + glWindow.setTitle("WarpPI Calculator by Andrea Cavalli (XDrake99)"); - + glWindow.addWindowListener(new WindowListener() { @Override public void windowDestroyNotify(WindowEvent e) { // TODO Auto-generated method stub - + } @Override @@ -112,32 +103,32 @@ class NEWTWindow implements GLEventListener { @Override public void windowGainedFocus(WindowEvent e) { // TODO Auto-generated method stub - + } @Override public void windowLostFocus(WindowEvent e) { // TODO Auto-generated method stub - + } @Override public void windowMoved(WindowEvent e) { // TODO Auto-generated method stub - + } @Override public void windowRepaint(WindowUpdateEvent e) { // TODO Auto-generated method stub - + } @Override public void windowResized(WindowEvent e) { - + } - + }); glWindow.addKeyListener(new KeyListener() { @Override @@ -272,15 +263,15 @@ class NEWTWindow implements GLEventListener { //Vsync gl.setSwapInterval(2); - + //Textures gl.glEnable(GL.GL_TEXTURE_2D); - + //Transparency - gl.glEnable(GL2ES1.GL_BLEND); - gl.glBlendFunc(GL2ES1.GL_SRC_ALPHA, GL2ES1.GL_ONE_MINUS_SRC_ALPHA); - gl.glShadeModel(GL2ES1.GL_FLAT); - + gl.glEnable(GL.GL_BLEND); + gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); + gl.glShadeModel(GLLightingFunc.GL_FLAT); + try { renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t; } catch (final Exception e) { @@ -296,8 +287,8 @@ class NEWTWindow implements GLEventListener { @Override public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { - disp.size[0] = Utils.debugOn?width/2:width; - disp.size[1] = Utils.debugOn?height/2:height; + disp.size[0] = Utils.debugOn ? width / 2 : width; + disp.size[1] = Utils.debugOn ? height / 2 : height; final GL2ES1 gl = glad.getGL().getGL2ES1(); float max_wh, min_wh; if (width == 0) { @@ -319,7 +310,7 @@ class NEWTWindow implements GLEventListener { gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); - gl.glOrtho(0.0, Utils.debugOn?width/2:width, Utils.debugOn?height/2:height, 0.0, -1, 1); + gl.glOrtho(0.0, Utils.debugOn ? width / 2 : width, Utils.debugOn ? height / 2 : height, 0.0, -1, 1); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); @@ -329,19 +320,19 @@ class NEWTWindow implements GLEventListener { public void display(GLAutoDrawable glad) { final GL2ES1 gl = glad.getGL().getGL2ES1(); - renderer.gl = gl; + GPURenderer.gl = gl; gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); renderer.startDrawCycle(); - + disp.repaint(); renderer.endDrawCycle(); - - renderer.gl = null; + + GPURenderer.gl = null; gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY); gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY); diff --git a/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java b/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java index 4c5a7fa0..014282fe 100644 --- a/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java +++ b/src/org/warp/picalculator/gui/screens/ChooseVariableValueScreen.java @@ -35,7 +35,7 @@ public class ChooseVariableValueScreen extends Screen { DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS."); DisplayManager.renderer.glColor3i(255, 0, 0); DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 - 20, "WORK IN PROGRESS."); - + Utils.getFont(false, false).use(DisplayManager.engine); DisplayManager.renderer.glColor4i(0, 0, 0, 64); DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); diff --git a/src/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java b/src/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java index a3a40e76..1ace33e3 100644 --- a/src/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java +++ b/src/org/warp/picalculator/gui/screens/KeyboardDebugScreen.java @@ -29,7 +29,7 @@ public class KeyboardDebugScreen extends Screen { @Override public void render() { - Renderer renderer = DisplayManager.renderer; + final Renderer renderer = DisplayManager.renderer; fonts[2].use(DisplayManager.engine); renderer.glColor4f(0.75f, 0.0f, 0.0f, 1.0f); renderer.glDrawStringRight(Main.screenSize[0] - 10, 30, "-" + keyevent.toUpperCase() + "-"); diff --git a/src/org/warp/picalculator/gui/screens/LoadingScreen.java b/src/org/warp/picalculator/gui/screens/LoadingScreen.java index 7a6d3cca..74400b0b 100644 --- a/src/org/warp/picalculator/gui/screens/LoadingScreen.java +++ b/src/org/warp/picalculator/gui/screens/LoadingScreen.java @@ -1,8 +1,5 @@ package org.warp.picalculator.gui.screens; -import static org.warp.picalculator.gui.DisplayManager.colore; -import static org.warp.picalculator.gui.DisplayManager.fonts; - import org.warp.picalculator.Main; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; @@ -45,11 +42,11 @@ public class LoadingScreen extends Screen { public void render() { DisplayManager.guiSkin.use(DisplayManager.engine); DisplayManager.renderer.glColor3i(255, 255, 255); - DisplayManager.renderer.glFillRect(Main.screenSize[0]/2f-80, Main.screenSize[1]/2f-64, 160, 48, 0, 32, 160, 48); - DisplayManager.renderer.glFillRect(Main.screenSize[0]/2f-24, Main.screenSize[1]/2f-loadingTextTranslation, 48, 48, 160, 32, 48, 48); + DisplayManager.renderer.glFillRect(Main.screenSize[0] / 2f - 80, Main.screenSize[1] / 2f - 64, 160, 48, 0, 32, 160, 48); + DisplayManager.renderer.glFillRect(Main.screenSize[0] / 2f - 24, Main.screenSize[1] / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48); - DisplayManager.renderer.glFillRect(Main.screenSize[0]-224, Main.screenSize[1]-48, 224, 48, 0, 80, 224, 48); - DisplayManager.renderer.glFillRect(Main.screenSize[0]-160-24-224, Main.screenSize[1]-48, 160, 48, 224, 80, 160, 48); + DisplayManager.renderer.glFillRect(Main.screenSize[0] - 224, Main.screenSize[1] - 48, 224, 48, 0, 80, 224, 48); + DisplayManager.renderer.glFillRect(Main.screenSize[0] - 160 - 24 - 224, Main.screenSize[1] - 48, 160, 48, 224, 80, 160, 48); } diff --git a/src/org/warp/picalculator/gui/screens/MarioScreen.java b/src/org/warp/picalculator/gui/screens/MarioScreen.java index 5ee417c1..cb0c3055 100644 --- a/src/org/warp/picalculator/gui/screens/MarioScreen.java +++ b/src/org/warp/picalculator/gui/screens/MarioScreen.java @@ -1,11 +1,7 @@ package org.warp.picalculator.gui.screens; -import java.awt.image.BufferedImage; import java.io.IOException; -import javax.imageio.ImageIO; - -import org.warp.picalculator.Main; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; @@ -37,7 +33,7 @@ public class MarioScreen extends Screen { try { skin = DisplayManager.engine.loadSkin("marioskin.png"); groundskin = DisplayManager.engine.loadSkin("marioground.png"); - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } @@ -45,7 +41,7 @@ public class MarioScreen extends Screen { @Override public void created() throws InterruptedException { if (!errored) { - + } } diff --git a/src/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/org/warp/picalculator/gui/screens/MathInputScreen.java index 995950ea..8a66e0a8 100644 --- a/src/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -4,19 +4,20 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; -import org.warp.picalculator.Main; import org.warp.picalculator.Utils; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; +import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.containers.InputContainer; import org.warp.picalculator.gui.expression.containers.NormalInputContainer; @@ -34,6 +35,8 @@ import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.functions.Variable; import org.warp.picalculator.math.functions.Variable.VariableValue; import org.warp.picalculator.math.functions.equations.Equation; +import org.warp.picalculator.math.parser.MathParser; +import org.warp.picalculator.math.functions.Expression; import org.warp.picalculator.math.functions.Number; public class MathInputScreen extends Screen { @@ -52,17 +55,17 @@ public class MathInputScreen extends Screen { @Override public void created() throws InterruptedException { calc = new MathContext(); - + try { BlockContainer.initializeFonts(DisplayManager.engine.loadFont("ex"), DisplayManager.engine.loadFont("big")); - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); System.exit(1); } - + userInput = new NormalInputContainer(); result = new NormalOutputContainer(); - + calc.init(); } @@ -70,7 +73,7 @@ public class MathInputScreen extends Screen { public void init() throws InterruptedException { /* Fine caricamento */ } - + @Override public void beforeRender(float dt) { @@ -88,7 +91,7 @@ public class MathInputScreen extends Screen { @Override public void renderStatusbar() { - Renderer renderer = DisplayManager.renderer; + final Renderer renderer = DisplayManager.renderer; renderer.glColor3f(1, 1, 1); final int pos = 2; final int spacersNumb = 1; @@ -107,11 +110,11 @@ public class MathInputScreen extends Screen { final int textColor = 0xFF000000; final int padding = 4; DisplayManager.renderer.glColor(textColor); - + userInput.draw(DisplayManager.engine, DisplayManager.renderer, padding, padding + 20); - + if (!result.root.getContent().isEmpty()) { - result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - 2, DisplayManager.engine.getHeight() - 2); + result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - result.getWidth() - 2, DisplayManager.engine.getHeight() - result.getHeight() - 2); } } @@ -127,6 +130,7 @@ public class MathInputScreen extends Screen { @Override public boolean keyPressed(Key k) { + Utils.debug.println(k.toString()); switch (k) { case STEP: // if (newExpression.length() > 0) { @@ -160,46 +164,51 @@ public class MathInputScreen extends Screen { // } // return true; case SIMPLIFY: -// if (DisplayManager.error != null) { -// Utils.debug.println("Resetting after error..."); -// DisplayManager.error = null; -// currentExpression = null; -// calc.f = null; -// calc.f2 = null; -// calc.resultsCount = 0; -// return true; -// } else { -// try { -// try { -// if (!firstStep) { -// step(); -// } else { -// if (newExpression != currentExpression && newExpression.length() > 0) { -// changeEquationScreen(); -// interpreta(true); -// showVariablesDialog(() -> { -// currentExpression = newExpression; -// simplify(); -// }); -// } -// } -// } catch (final Exception ex) { -// if (Utils.debugOn) { -// ex.printStackTrace(); -// } -// throw new Error(Errors.SYNTAX_ERROR); -// } -// } catch (final Error e) { -// final StringWriter sw = new StringWriter(); -// final PrintWriter pw = new PrintWriter(sw); -// e.printStackTrace(pw); -// d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n"); -// DisplayManager.error = e.id.toString(); -// System.err.println(e.id); -// } -// return true; -// } - return true; + if (DisplayManager.error != null) { + //TODO: make the error management a global API rather than being relegated to this screen. + Utils.debug.println("Resetting after error..."); + DisplayManager.error = null; + calc.f = null; + calc.f2 = null; + calc.resultsCount = 0; + return true; + } else { + try { + try { + if (!userInput.isAlreadyParsed() && !userInput.isEmpty()) { + Expression expr = MathParser.parseInput(calc, userInput); + if (calc.f == null | calc.f2 == null) { + calc.f = new ObjectArrayList<>(); + calc.f2 = new ObjectArrayList<>(); + } else { + calc.f.clear(); + calc.f2.clear(); + } + calc.f.add(expr); + ObjectArrayList resultExpression = expr.solve(); + ObjectArrayList resultBlocks = MathParser.parseOutput(calc, resultExpression); + result.setContent(resultBlocks); +// showVariablesDialog(() -> { +// currentExpression = newExpression; +// simplify(); +// }); + } + } catch (final Exception ex) { + if (Utils.debugOn) { + ex.printStackTrace(); + } + throw new Error(Errors.SYNTAX_ERROR); + } + } catch (final Error e) { + final StringWriter sw = new StringWriter(); + final PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n"); + DisplayManager.error = e.id.toString(); + System.err.println(e.id); + } + return true; + } case NUM0: typeChar('0'); return true; @@ -317,13 +326,13 @@ public class MathInputScreen extends Screen { } return true; case SURD_MODE: -// calc.exactMode = !calc.exactMode; -// if (calc.exactMode == false) { -// calc.f2 = solveExpression(calc.f2); -// } else { -// currentExpression = ""; -// Keyboard.keyPressed(Key.SIMPLIFY); -// } + calc.exactMode = !calc.exactMode; + if (calc.exactMode == false) { + calc.f2 = solveExpression(calc.f2); + } else { + result.clear(); + Keyboard.keyPressed(Key.SIMPLIFY); + } return true; case debug1: DisplayManager.INSTANCE.setScreen(new EmptyScreen()); @@ -436,9 +445,6 @@ public class MathInputScreen extends Screen { results.clear(); results.addAll(hs); calc.f2 = results; - for (final Function rf : calc.f2) { - rf.recomputeDimensions(null); - } } Utils.debug.println(calc.f2.toString()); } catch (final Exception ex) { @@ -479,9 +485,6 @@ public class MathInputScreen extends Screen { results.clear(); results.addAll(hs); calc.f2 = results; - for (final Function rf : calc.f2) { - rf.recomputeDimensions(null); - } } } catch (final Exception ex) { if (Utils.debugOn) { @@ -499,27 +502,26 @@ public class MathInputScreen extends Screen { } } + @SuppressWarnings("unused") + @Deprecated private void changeEquationScreen() { - if (currentExpression != null && currentExpression.length() > 0) { - final MathInputScreen cloned = clone(); - cloned.caretPos = cloned.currentExpression.length(); - cloned.newExpression = cloned.currentExpression; - cloned.scrollX = fontBig.getStringWidth(cloned.currentExpression); - try { - cloned.interpreta(true); - } catch (final Error e) {} - DisplayManager.INSTANCE.replaceScreen(cloned); - initialized = false; - DisplayManager.INSTANCE.setScreen(this); - - } + throw new NotImplementedException(); +// +// if (!userInput.isEmpty()) { +// final MathInputScreen cloned = clone(); +// cloned.userInput.setCaretPosition(cloned.userInput.getCaretMaxPosition()-1); +// DisplayManager.INSTANCE.replaceScreen(cloned); +// initialized = false; +// DisplayManager.INSTANCE.setScreen(this); +// +// } } public void typeChar(char chr) { userInput.typeChar(chr); mustRefresh = true; } - + @Override public boolean keyReleased(Key k) { return false; @@ -537,7 +539,7 @@ public class MathInputScreen extends Screen { knownVarsInFunctions.remove(f.v); } } - + boolean cancelled = false; for (final Function f : knownVarsInFunctions) { final ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(calc, 0))); @@ -583,7 +585,7 @@ public class MathInputScreen extends Screen { } else if (f instanceof FunctionSingle) { res.addAll(getKnownVariables(new Function[] { ((FunctionSingle) f).getParameter() })); } else if (f instanceof Variable) { - if (((Variable)f).getType() == Variable.V_TYPE.KNOWN) { + if (((Variable) f).getType() == Variable.V_TYPE.KNOWN) { if (!res.contains(f)) { res.add(f); } @@ -594,15 +596,17 @@ public class MathInputScreen extends Screen { } @Override + @Deprecated public MathInputScreen clone() { - final MathInputScreen es = this; - final MathInputScreen es2 = new MathInputScreen(); - es2.errorLevel = es.errorLevel; - es2.mustRefresh = es.mustRefresh; - es2.calc = Utils.cloner.deepClone(es.calc); - es2.userInput = Utils.cloner.deepClone(es.userInput); - es2.result = Utils.cloner.deepClone(es.result); - return es2; + throw new NotImplementedException(); +// final MathInputScreen es = this; +// final MathInputScreen es2 = new MathInputScreen(); +// es2.errorLevel = es.errorLevel; +// es2.mustRefresh = es.mustRefresh; +// es2.calc = Utils.cloner.deepClone(es.calc); +// es2.userInput = Utils.cloner.deepClone(es.userInput); +// es2.result = Utils.cloner.deepClone(es.result); +// return es2; } } diff --git a/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java b/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java index 2f5e8899..4eb1fa16 100644 --- a/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java +++ b/src/org/warp/picalculator/gui/screens/SolveEquationScreen.java @@ -1,10 +1,8 @@ package org.warp.picalculator.gui.screens; -import org.warp.picalculator.Error; import org.warp.picalculator.Main; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.math.MathContext; public class SolveEquationScreen extends Screen { diff --git a/src/org/warp/picalculator/math/Function.java b/src/org/warp/picalculator/math/Function.java index f49cd2d5..f2ab1832 100644 --- a/src/org/warp/picalculator/math/Function.java +++ b/src/org/warp/picalculator/math/Function.java @@ -8,6 +8,7 @@ public interface Function { /** * Returns this function and its children in a string form. + * * @return This function and its children in a string form. */ @Override @@ -15,30 +16,37 @@ public interface Function { @Override public boolean equals(Object o); - + /** * Deep clone this function. + * * @return A clone of this function. */ public Function clone(); - + /** * Generic method to change a parameter in a known position. - * @param index parameter index. - * @param var parameter. + * + * @param index + * parameter index. + * @param var + * parameter. * @return A new instance of this function. */ public Function setParameter(int index, Function var) throws IndexOutOfBoundsException; /** * Generic method to retrieve a parameter in a known position. - * @param index parameter index. + * + * @param index + * parameter index. * @return The requested parameter. */ public Function getParameter(int index) throws IndexOutOfBoundsException; /** * Retrieve the current Math Context used by this function + * * @return Calculator mathContext */ public MathContext getMathContext(); @@ -47,9 +55,10 @@ public interface Function { * Simplify the current function or it's children */ public List simplify() throws Error; - + /** * The current simplification status of this function and it's childrens + * * @return boolean */ public boolean isSimplified(); diff --git a/src/org/warp/picalculator/math/FunctionDynamic.java b/src/org/warp/picalculator/math/FunctionDynamic.java index 186ca418..e34948bc 100644 --- a/src/org/warp/picalculator/math/FunctionDynamic.java +++ b/src/org/warp/picalculator/math/FunctionDynamic.java @@ -7,8 +7,6 @@ import java.util.List; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; -import com.rits.cloning.Cloner; - public abstract class FunctionDynamic implements Function { public FunctionDynamic(MathContext root) { this.root = root; @@ -37,7 +35,7 @@ public abstract class FunctionDynamic implements Function { } public FunctionDynamic setParameters(final List value) { - FunctionDynamic f = this.clone(); + final FunctionDynamic f = clone(); final int vsize = value.size(); final Function[] tmp = new Function[vsize]; for (int i = 0; i < vsize; i++) { @@ -48,11 +46,11 @@ public abstract class FunctionDynamic implements Function { } public FunctionDynamic setParameters(final Function[] value) { - FunctionDynamic f = this.clone(); + final FunctionDynamic f = clone(); f.functions = value; return f; } - + @Override public Function getParameter(int index) { return functions[index]; @@ -60,13 +58,13 @@ public abstract class FunctionDynamic implements Function { @Override public FunctionDynamic setParameter(int index, Function value) { - FunctionDynamic f = this.clone(); + final FunctionDynamic f = clone(); f.functions[index] = value; return f; } public FunctionDynamic appendParameter(Function value) { - FunctionDynamic f = this.clone(); + final FunctionDynamic f = clone(); f.functions = Arrays.copyOf(f.functions, f.functions.length + 1); f.functions[f.functions.length - 1] = value; return f; @@ -74,6 +72,7 @@ public abstract class FunctionDynamic implements Function { /** * Retrieve the current number of parameters. + * * @return The number of parameters. */ public int getParametersLength() { @@ -81,11 +80,11 @@ public abstract class FunctionDynamic implements Function { } public FunctionDynamic setParametersLength(int length) { - FunctionDynamic f = this.clone(); + final FunctionDynamic f = clone(); f.functions = Arrays.copyOf(functions, length); return f; } - + @Override public boolean isSimplified() { for (final Function variable : functions) { @@ -95,18 +94,21 @@ public abstract class FunctionDynamic implements Function { } return !isSolvable(); } - + /** - * The current simplification status of this function, assuming that its children are already simplified. - * @return true if this function can be solved, otherwise false. + * The current simplification status of this function, assuming that its + * children are already simplified. + * + * @return true if this function can be solved, otherwise + * false. */ protected abstract boolean isSolvable(); @Override public final ObjectArrayList simplify() throws Error { boolean solved = true; - Function[] fncs = getParameters(); - for (Function f : fncs) { + final Function[] fncs = getParameters(); + for (final Function f : fncs) { if (f.isSimplified() == false) { solved = false; break; @@ -118,12 +120,12 @@ public abstract class FunctionDynamic implements Function { result = new ObjectArrayList<>(); final ObjectArrayList> ln = new ObjectArrayList<>(); - for (int i = 0; i < fncs.length; i++) { - ObjectArrayList l = new ObjectArrayList<>(); - if (fncs[i].isSimplified()) { - l.add(fncs[i]); + for (final Function fnc : fncs) { + final ObjectArrayList l = new ObjectArrayList<>(); + if (fnc.isSimplified()) { + l.add(fnc); } else { - l.addAll(fncs[i].simplify()); + l.addAll(fnc.simplify()); } ln.add(l); } @@ -137,14 +139,17 @@ public abstract class FunctionDynamic implements Function { return result; } - + /** - * Solves only this function, assuming that its children are already simplified and it can be solved. + * Solves only this function, assuming that its children are already + * simplified and it can be solved. + * * @return The solved function. - * @throws Error Errors during computation, like a/0 or similar. + * @throws Error + * Errors during computation, like a/0 or similar. */ protected abstract ObjectArrayList solve() throws Error; - + @Override public MathContext getMathContext() { return root; diff --git a/src/org/warp/picalculator/math/FunctionOperator.java b/src/org/warp/picalculator/math/FunctionOperator.java index 84368607..ef2f2d64 100644 --- a/src/org/warp/picalculator/math/FunctionOperator.java +++ b/src/org/warp/picalculator/math/FunctionOperator.java @@ -6,26 +6,34 @@ import org.warp.picalculator.Error; import org.warp.picalculator.Utils; public abstract class FunctionOperator implements Function { - + /** - * Create a new instance of FunctionOperator. The Math Context will be the same of value1's. - * @throws NullPointerException when value1 is null. - * @param value1 The parameter of this function. - * @param value2 The parameter of this function. + * Create a new instance of FunctionOperator. The Math Context will be the + * same of value1's. + * + * @throws NullPointerException + * when value1 is null. + * @param value1 + * The parameter of this function. + * @param value2 + * The parameter of this function. */ public FunctionOperator(Function value1, Function value2) throws NullPointerException { - this.mathContext = value1.getMathContext(); + mathContext = value1.getMathContext(); parameter1 = value1; parameter2 = value2; } - + /** * Create a new instance of FunctionOperator. - * @param value1 The parameter of this function. - * @param value2 The parameter of this function. + * + * @param value1 + * The parameter of this function. + * @param value2 + * The parameter of this function. */ public FunctionOperator(MathContext mc, Function value1, Function value2) { - this.mathContext = mc; + mathContext = mc; parameter1 = value1; parameter2 = value2; } @@ -53,33 +61,35 @@ public abstract class FunctionOperator implements Function { /** * - * @param var First parameter. + * @param var + * First parameter. * @return A new instance of this function. */ public FunctionOperator setParameter1(Function var) { - FunctionOperator s = this.clone(); + final FunctionOperator s = clone(); s.parameter1 = var; return s; } /** * - * @param var Second parameter. + * @param var + * Second parameter. * @return A new instance of this function. */ public FunctionOperator setParameter2(Function var) { - FunctionOperator s = this.clone(); + final FunctionOperator s = clone(); s.parameter2 = var; return s; } - + @Override public FunctionOperator setParameter(int index, Function var) throws IndexOutOfBoundsException { - switch(index) { + switch (index) { case 0: - return this.setParameter1(var); + return setParameter1(var); case 1: - return this.setParameter2(var); + return setParameter2(var); default: throw new IndexOutOfBoundsException(); } @@ -87,11 +97,11 @@ public abstract class FunctionOperator implements Function { @Override public Function getParameter(int index) throws IndexOutOfBoundsException { - switch(index) { + switch (index) { case 0: - return this.getParameter1(); + return getParameter1(); case 1: - return this.getParameter2(); + return getParameter2(); default: throw new IndexOutOfBoundsException(); } @@ -106,10 +116,13 @@ public abstract class FunctionOperator implements Function { public boolean isSimplified() { return (parameter1.isSimplified() & parameter2.isSimplified()) ? !isSolvable() : false; } - + /** - * The current simplification status of this function, assuming that its children are already simplified. - * @return true if this function can be solved, otherwise false. + * The current simplification status of this function, assuming that its + * children are already simplified. + * + * @return true if this function can be solved, otherwise + * false. */ protected abstract boolean isSolvable(); @@ -137,23 +150,26 @@ public abstract class FunctionOperator implements Function { final Function[][] results = Utils.joinFunctionsResults(l1, l2); for (final Function[] f : results) { - result.add(this.setParameter1(f[0]).setParameter2(f[1])); + result.add(setParameter1(f[0]).setParameter2(f[1])); } } return result; } - + /** - * Solves only this function, assuming that its children are already simplified and it can be solved. + * Solves only this function, assuming that its children are already + * simplified and it can be solved. + * * @return The solved function. - * @throws Error Errors during computation, like a/0 or similar. + * @throws Error + * Errors during computation, like a/0 or similar. */ protected abstract ObjectArrayList solve() throws Error; @Override public abstract FunctionOperator clone(); - + @Override public int hashCode() { return parameter1.hashCode() + 7 * parameter2.hashCode() + 883 * super.hashCode(); diff --git a/src/org/warp/picalculator/math/FunctionSingle.java b/src/org/warp/picalculator/math/FunctionSingle.java index 0eb9678d..65079291 100644 --- a/src/org/warp/picalculator/math/FunctionSingle.java +++ b/src/org/warp/picalculator/math/FunctionSingle.java @@ -5,29 +5,36 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; public abstract class FunctionSingle implements Function { - + /** - * Create a new instance of FunctionSingle. The Math Context will be the same of value's. - * @throws NullPointerException when value is null. - * @param value The parameter of this function. + * Create a new instance of FunctionSingle. The Math Context will be the + * same of value's. + * + * @throws NullPointerException + * when value is null. + * @param value + * The parameter of this function. */ public FunctionSingle(Function value) throws NullPointerException { mathContext = value.getMathContext(); parameter = value; } - + /** * Create a new instance of FunctionSingle. - * @param mathContext Math Context - * @param value The parameter of this function. + * + * @param mathContext + * Math Context + * @param value + * The parameter of this function. */ public FunctionSingle(MathContext mathContext, Function value) { this.mathContext = mathContext; parameter = value; } - + protected final MathContext mathContext; - + /** * Function parameter.
* MUST NOT BE MODIFIED IF ALREADY SET UP. @@ -41,13 +48,15 @@ public abstract class FunctionSingle implements Function { public Function getParameter() { return parameter; } + /** * - * @param var Parameter. + * @param var + * Parameter. * @return A new instance of this function. */ public FunctionSingle setParameter(Function value) { - FunctionSingle s = this.clone(); + final FunctionSingle s = clone(); s.parameter = value; return s; } @@ -69,7 +78,7 @@ public abstract class FunctionSingle implements Function { throw new IndexOutOfBoundsException(); } } - + @Override public MathContext getMathContext() { return mathContext; @@ -98,11 +107,13 @@ public abstract class FunctionSingle implements Function { return result; } - /** - * Solves only this function, assuming that its children are already simplified and it can be solved. + * Solves only this function, assuming that its children are already + * simplified and it can be solved. + * * @return The solved function. - * @throws Error Errors during computation, like a/0 or similar. + * @throws Error + * Errors during computation, like a/0 or similar. */ protected abstract ObjectArrayList solve() throws Error; @@ -112,14 +123,17 @@ public abstract class FunctionSingle implements Function { } /** - * The current simplification status of this function, assuming that its children are already simplified. - * @return true if this function can be solved, otherwise false. + * The current simplification status of this function, assuming that its + * children are already simplified. + * + * @return true if this function can be solved, otherwise + * false. */ protected abstract boolean isSolvable(); @Override public abstract FunctionSingle clone(); - + @Override public int hashCode() { return parameter.hashCode() + 883 * super.hashCode(); diff --git a/src/org/warp/picalculator/math/MathContext.java b/src/org/warp/picalculator/math/MathContext.java index ac8da5e2..e6fbb086 100644 --- a/src/org/warp/picalculator/math/MathContext.java +++ b/src/org/warp/picalculator/math/MathContext.java @@ -12,7 +12,7 @@ import org.warp.picalculator.math.functions.equations.Equation; import org.warp.picalculator.math.functions.equations.EquationsSystem; import it.unimi.dsi.fastutil.objects.ObjectArrayList; - +import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class MathContext { @@ -122,4 +122,17 @@ public class MathContext { } }*/ + @Override + @Deprecated + public MathContext clone() { +// MathContext mc = new MathContext(); +// mc.angleMode = this.angleMode; +// mc.exactMode = this.exactMode; +// mc.f = this.f; +// mc.f2 = this.f2; +// mc.variablesValues = this.variablesValues; +// mc.resultsCount = this.resultsCount; +// return mc; + throw new NotImplementedException(); + } } diff --git a/src/org/warp/picalculator/math/MathematicalSymbols.java b/src/org/warp/picalculator/math/MathematicalSymbols.java index 21c768fb..644e53ff 100644 --- a/src/org/warp/picalculator/math/MathematicalSymbols.java +++ b/src/org/warp/picalculator/math/MathematicalSymbols.java @@ -27,7 +27,6 @@ public class MathematicalSymbols { public static final char ARC_TANGENT = 'Ⓗ'; public static final char PI = 'π'; - public static final char[] functionsNSN = new char[] { NTH_ROOT, POWER }; public static final char[] functionsSN = new char[] { SQUARE_ROOT, POWER_OF_TWO, MINUS, SINE, COSINE, TANGENT, ARC_SINE, ARC_COSINE, ARC_TANGENT }; @@ -36,7 +35,7 @@ public class MathematicalSymbols { private static final char[] signumsWithoutMultiplication = new char[] { SUM, SUM_SUBTRACTION, SUBTRACTION, DIVISION }; private static final char[] signumsWithMultiplication = Utils.add(signumsWithoutMultiplication, MULTIPLICATION); - + public static final char[] signums(boolean withMultiplication) { if (withMultiplication) { return signumsWithMultiplication; @@ -54,5 +53,5 @@ public class MathematicalSymbols { return string.replace("Ⓑ", "^").replace("Ⓒ", "SIN").replace("Ⓓ", "COS").replace("Ⓔ", "TAN").replace("Ⓕ", "ASIN").replace("Ⓖ", "ACOS").replace("Ⓗ", "ATAN"); } - public static final char[] numbers = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + public static final char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; } diff --git a/src/org/warp/picalculator/math/functions/Division.java b/src/org/warp/picalculator/math/functions/Division.java index 01c84013..14f9cdcb 100644 --- a/src/org/warp/picalculator/math/functions/Division.java +++ b/src/org/warp/picalculator/math/functions/Division.java @@ -3,14 +3,9 @@ package org.warp.picalculator.math.functions; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.GraphicalElement; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.FractionsRule1; import org.warp.picalculator.math.rules.FractionsRule11; import org.warp.picalculator.math.rules.FractionsRule12; @@ -26,8 +21,8 @@ public class Division extends FunctionOperator { @Override protected boolean isSolvable() { - Function variable1 = getParameter1(); - Function variable2 = getParameter2(); + final Function variable1 = getParameter1(); + final Function variable2 = getParameter2(); if (FractionsRule1.compare(this)) { return true; } @@ -49,8 +44,8 @@ public class Division extends FunctionOperator { if (variable1 instanceof Number && variable2 instanceof Number) { if (getMathContext().exactMode) { try { - return ((Number)variable1).divide((Number)variable2).isInteger(); - } catch (Error e) { + return ((Number) variable1).divide((Number) variable2).isInteger(); + } catch (final Error e) { return false; } } else { @@ -62,8 +57,8 @@ public class Division extends FunctionOperator { @Override public ObjectArrayList solve() throws Error { - Function variable1 = getParameter1(); - Function variable2 = getParameter2(); + final Function variable1 = getParameter1(); + final Function variable2 = getParameter2(); ObjectArrayList result = new ObjectArrayList<>(); if (FractionsRule1.compare(this)) { result = FractionsRule1.execute(this); @@ -82,7 +77,7 @@ public class Division extends FunctionOperator { } return result; } - + @Override public boolean equals(Object o) { if (o instanceof Division) { @@ -94,11 +89,11 @@ public class Division extends FunctionOperator { @Override public FunctionOperator clone() { - return new Division(this.getMathContext(), this.getParameter1(), this.getParameter2()); + return new Division(getMathContext(), getParameter1(), getParameter2()); } - + @Override public String toString() { - return "("+this.getParameter1()+")/("+this.getParameter2()+")"; + return "(" + getParameter1() + ")/(" + getParameter2() + ")"; } } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/EmptyNumber.java b/src/org/warp/picalculator/math/functions/EmptyNumber.java index 805802bf..35e86b0b 100644 --- a/src/org/warp/picalculator/math/functions/EmptyNumber.java +++ b/src/org/warp/picalculator/math/functions/EmptyNumber.java @@ -1,12 +1,7 @@ package org.warp.picalculator.math.functions; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import java.util.List; - import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; @@ -18,7 +13,6 @@ public class EmptyNumber implements Function { private final MathContext root; - @Override public ObjectArrayList simplify() throws Error { // TODO Auto-generated method stub @@ -34,7 +28,7 @@ public class EmptyNumber implements Function { public MathContext getMathContext() { return root; } - + @Override public boolean equals(Object o) { return o instanceof EmptyNumber; @@ -54,5 +48,5 @@ public class EmptyNumber implements Function { public Function getParameter(int index) throws IndexOutOfBoundsException { throw new IndexOutOfBoundsException(); } - + } diff --git a/src/org/warp/picalculator/math/functions/Expression.java b/src/org/warp/picalculator/math/functions/Expression.java index 6aecf16c..1157d8e6 100644 --- a/src/org/warp/picalculator/math/functions/Expression.java +++ b/src/org/warp/picalculator/math/functions/Expression.java @@ -12,7 +12,6 @@ import java.util.regex.Pattern; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionDynamic; @@ -37,7 +36,7 @@ public class Expression extends FunctionDynamic { } public Expression(MathContext root, Function value) { - super(root, new Function[]{value}); + super(root, new Function[] { value }); } private boolean initialParenthesis = false; @@ -599,7 +598,7 @@ public class Expression extends FunctionDynamic { return ret; } } - + public boolean parenthesisNeeded() { boolean parenthesisneeded = true; if (initialParenthesis) { @@ -623,21 +622,21 @@ public class Expression extends FunctionDynamic { } return parenthesisneeded; } - + @Override public String toString() { String s = "("; if (functions.length > 0) { - for (Function f : functions) { + for (final Function f : functions) { if (f == null) { - s+="[null],"; + s += "[null],"; } else { - s+=f.toString()+","; + s += f.toString() + ","; } } - s = s.substring(0, s.length()-1); + s = s.substring(0, s.length() - 1); } - s+=")"; + s += ")"; return s; } diff --git a/src/org/warp/picalculator/math/functions/Joke.java b/src/org/warp/picalculator/math/functions/Joke.java index b828b4be..c58947d9 100644 --- a/src/org/warp/picalculator/math/functions/Joke.java +++ b/src/org/warp/picalculator/math/functions/Joke.java @@ -1,13 +1,7 @@ package org.warp.picalculator.math.functions; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import java.util.List; - import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.BinaryFont; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; diff --git a/src/org/warp/picalculator/math/functions/Multiplication.java b/src/org/warp/picalculator/math/functions/Multiplication.java index fc572f2b..b562f91b 100644 --- a/src/org/warp/picalculator/math/functions/Multiplication.java +++ b/src/org/warp/picalculator/math/functions/Multiplication.java @@ -5,9 +5,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; -import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExponentRule15; import org.warp.picalculator.math.rules.ExponentRule16; import org.warp.picalculator.math.rules.FractionsRule14; @@ -29,8 +27,8 @@ public class Multiplication extends FunctionOperator { @Override protected boolean isSolvable() { - Function variable1 = getParameter1(); - Function variable2 = getParameter2(); + final Function variable1 = getParameter1(); + final Function variable2 = getParameter2(); if (variable1 instanceof Number & variable2 instanceof Number) { return true; } @@ -103,9 +101,9 @@ public class Multiplication extends FunctionOperator { public Multiplication clone() { return new Multiplication(mathContext, parameter1, parameter2); } - + @Override public String toString() { - return "("+parameter1.toString()+")*("+parameter2.toString()+")"; + return "(" + parameter1.toString() + ")*(" + parameter2.toString() + ")"; } } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/Negative.java b/src/org/warp/picalculator/math/functions/Negative.java index 0605820f..d7574fd4 100644 --- a/src/org/warp/picalculator/math/functions/Negative.java +++ b/src/org/warp/picalculator/math/functions/Negative.java @@ -4,13 +4,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExpandRule1; import org.warp.picalculator.math.rules.ExpandRule5; diff --git a/src/org/warp/picalculator/math/functions/Number.java b/src/org/warp/picalculator/math/functions/Number.java index 2159920a..7d9e8cb2 100644 --- a/src/org/warp/picalculator/math/functions/Number.java +++ b/src/org/warp/picalculator/math/functions/Number.java @@ -7,16 +7,11 @@ import java.util.LinkedList; import java.util.List; import org.nevec.rjm.BigDecimalMath; -import org.nevec.rjm.BigIntegerMath; import org.warp.picalculator.Error; import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; -import com.rits.cloning.Cloner; - public class Number implements Function { private final MathContext root; @@ -109,7 +104,7 @@ public class Number implements Function { public Number clone() { return new Number(root, term); } - + @Override public boolean isSimplified() { if (root.exactMode) { @@ -123,20 +118,20 @@ public class Number implements Function { public List simplify() throws Error { final List result = new ObjectArrayList<>(); if (root.exactMode) { - Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces())); - Number numb = new Number(root, term.multiply(divisor.term)); - Division div = new Division(root, numb, divisor); + final Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces())); + final Number numb = new Number(root, term.multiply(divisor.term)); + final Division div = new Division(root, numb, divisor); result.add(div); } else { result.add(this); } return result; } - + public int getNumberOfDecimalPlaces() { - return Math.max(0, term.stripTrailingZeros().scale()); + return Math.max(0, term.stripTrailingZeros().scale()); } - + public boolean isInteger() { return getNumberOfDecimalPlaces() <= 0; } diff --git a/src/org/warp/picalculator/math/functions/Power.java b/src/org/warp/picalculator/math/functions/Power.java index b4b158ee..c921dc57 100644 --- a/src/org/warp/picalculator/math/functions/Power.java +++ b/src/org/warp/picalculator/math/functions/Power.java @@ -6,7 +6,6 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExponentRule1; import org.warp.picalculator.math.rules.ExponentRule2; import org.warp.picalculator.math.rules.ExponentRule3; @@ -78,7 +77,7 @@ public class Power extends FunctionOperator { } return result; } - + @Override public boolean equals(Object o) { if (o instanceof Power) { diff --git a/src/org/warp/picalculator/math/functions/Root.java b/src/org/warp/picalculator/math/functions/Root.java index 6cafb7ed..dfe91efa 100644 --- a/src/org/warp/picalculator/math/functions/Root.java +++ b/src/org/warp/picalculator/math/functions/Root.java @@ -5,11 +5,9 @@ import java.math.BigInteger; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; public class Root extends FunctionOperator { @@ -60,7 +58,7 @@ public class Root extends FunctionOperator { } return result; } - + @Override public boolean equals(Object o) { if (o instanceof Root) { @@ -74,5 +72,5 @@ public class Root extends FunctionOperator { public Root clone() { return new Root(mathContext, parameter1, parameter2); } - + } diff --git a/src/org/warp/picalculator/math/functions/RootSquare.java b/src/org/warp/picalculator/math/functions/RootSquare.java index aadc44b5..f8536031 100644 --- a/src/org/warp/picalculator/math/functions/RootSquare.java +++ b/src/org/warp/picalculator/math/functions/RootSquare.java @@ -4,11 +4,9 @@ import java.math.BigInteger; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class RootSquare extends FunctionSingle { diff --git a/src/org/warp/picalculator/math/functions/Subtraction.java b/src/org/warp/picalculator/math/functions/Subtraction.java index d5e08774..59643d8c 100644 --- a/src/org/warp/picalculator/math/functions/Subtraction.java +++ b/src/org/warp/picalculator/math/functions/Subtraction.java @@ -6,7 +6,6 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExpandRule1; import org.warp.picalculator.math.rules.ExpandRule5; import org.warp.picalculator.math.rules.NumberRule3; @@ -92,5 +91,5 @@ public class Subtraction extends FunctionOperator { public Subtraction clone() { return new Subtraction(mathContext, parameter1, parameter2); } - + } \ No newline at end of file diff --git a/src/org/warp/picalculator/math/functions/Sum.java b/src/org/warp/picalculator/math/functions/Sum.java index 749e2d9e..c982f756 100644 --- a/src/org/warp/picalculator/math/functions/Sum.java +++ b/src/org/warp/picalculator/math/functions/Sum.java @@ -5,12 +5,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.NumberRule3; import org.warp.picalculator.math.rules.NumberRule5; import org.warp.picalculator.math.rules.NumberRule7; @@ -115,5 +112,5 @@ public class Sum extends FunctionOperator { public Sum clone() { return new Sum(mathContext, parameter1, parameter2); } - + } diff --git a/src/org/warp/picalculator/math/functions/SumSubtraction.java b/src/org/warp/picalculator/math/functions/SumSubtraction.java index ab3d171b..bbca927d 100644 --- a/src/org/warp/picalculator/math/functions/SumSubtraction.java +++ b/src/org/warp/picalculator/math/functions/SumSubtraction.java @@ -4,13 +4,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.rules.ExpandRule1; import org.warp.picalculator.math.rules.NumberRule3; import org.warp.picalculator.math.rules.NumberRule4; @@ -76,5 +72,5 @@ public class SumSubtraction extends FunctionOperator { public SumSubtraction clone() { return new SumSubtraction(mathContext, parameter1, parameter2); } - + } diff --git a/src/org/warp/picalculator/math/functions/Undefined.java b/src/org/warp/picalculator/math/functions/Undefined.java index e68d742f..1da9514a 100644 --- a/src/org/warp/picalculator/math/functions/Undefined.java +++ b/src/org/warp/picalculator/math/functions/Undefined.java @@ -3,9 +3,6 @@ package org.warp.picalculator.math.functions; import java.util.List; import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; @@ -16,7 +13,7 @@ public class Undefined implements Function { public Undefined(MathContext root) { this.root = root; } - + @Override public List simplify() throws Error { return null; diff --git a/src/org/warp/picalculator/math/functions/Variable.java b/src/org/warp/picalculator/math/functions/Variable.java index 665e0098..83eba1f0 100644 --- a/src/org/warp/picalculator/math/functions/Variable.java +++ b/src/org/warp/picalculator/math/functions/Variable.java @@ -4,13 +4,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; -import org.warp.picalculator.Utils; -import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; -import com.rits.cloning.Cloner; - public class Variable implements Function { protected char var; @@ -47,7 +43,7 @@ public class Variable implements Function { public String toString() { return "" + getChar(); } - + public static class VariableValue { public final Variable v; public final Number n; @@ -87,16 +83,14 @@ public class Variable implements Function { public MathContext getMathContext() { return root; } - + @Override public Variable clone() { return new Variable(root, var, type); } - + public static enum V_TYPE { - KNOWN, - UNKNOWN, - SOLUTION + KNOWN, UNKNOWN, SOLUTION } @Override diff --git a/src/org/warp/picalculator/math/functions/equations/Equation.java b/src/org/warp/picalculator/math/functions/equations/Equation.java index b213b8c3..6cff460a 100644 --- a/src/org/warp/picalculator/math/functions/equations/Equation.java +++ b/src/org/warp/picalculator/math/functions/equations/Equation.java @@ -11,19 +11,16 @@ import org.warp.picalculator.Errors; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.SolveMethod; import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Subtraction; -import com.rits.cloning.Cloner; - public class Equation extends FunctionOperator { public Equation(MathContext root, Function value1, Function value2) { super(root, value1, value2); } - + @Override protected boolean isSolvable() { if (parameter1 instanceof Number & parameter2 instanceof Number) { @@ -81,8 +78,7 @@ public class Equation extends FunctionOperator { @Override public Equation clone() { - final Cloner cloner = new Cloner(); - return cloner.deepClone(this); + return new Equation(mathContext, parameter1, parameter2); } @Override diff --git a/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java b/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java index 2cb972d9..6f2cc413 100644 --- a/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java +++ b/src/org/warp/picalculator/math/functions/equations/EquationsSystem.java @@ -4,7 +4,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.List; import org.warp.picalculator.Error; -import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionDynamic; @@ -69,5 +68,5 @@ public class EquationsSystem extends FunctionDynamic { public EquationsSystem clone() { return new EquationsSystem(root, functions); } - + } diff --git a/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java b/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java index e69a1cb5..04faf15e 100644 --- a/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java +++ b/src/org/warp/picalculator/math/functions/equations/EquationsSystemPart.java @@ -1,14 +1,10 @@ package org.warp.picalculator.math.functions.equations; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import java.util.List; - import org.warp.picalculator.Error; -import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class EquationsSystemPart extends FunctionSingle { @@ -38,5 +34,5 @@ public class EquationsSystemPart extends FunctionSingle { public EquationsSystemPart clone() { return new EquationsSystemPart(mathContext, (Equation) parameter); } - + } diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java index 5f0f0eb3..13367a1a 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcCosine.java @@ -6,7 +6,6 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class ArcCosine extends FunctionSingle { diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java index 99d1dea4..ceadafae 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcSine.java @@ -6,7 +6,6 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class ArcSine extends FunctionSingle { diff --git a/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java b/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java index e7ba0e9f..fa11fd23 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/ArcTangent.java @@ -6,7 +6,6 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class ArcTangent extends FunctionSingle { diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java b/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java index 26a2c2d2..b8861884 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Cosine.java @@ -6,7 +6,6 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class Cosine extends FunctionSingle { diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Sine.java b/src/org/warp/picalculator/math/functions/trigonometry/Sine.java index 1b677ab5..4928f01c 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Sine.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Sine.java @@ -8,7 +8,6 @@ import org.warp.picalculator.math.AngleMode; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.functions.Number; public class Sine extends FunctionSingle { @@ -16,7 +15,7 @@ public class Sine extends FunctionSingle { public Sine(MathContext root, Function value) { super(root, value); } - + @Override protected boolean isSolvable() { if (parameter instanceof Number) { diff --git a/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java b/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java index 00dc62f9..e035747f 100644 --- a/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java +++ b/src/org/warp/picalculator/math/functions/trigonometry/Tangent.java @@ -6,14 +6,13 @@ import org.warp.picalculator.Error; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionSingle; -import org.warp.picalculator.math.MathematicalSymbols; public class Tangent extends FunctionSingle { public Tangent(MathContext root, Function value) { super(root, value); } - + @Override public ObjectArrayList solve() throws Error { // TODO Auto-generated method stub diff --git a/src/org/warp/picalculator/math/parser/MathParser.java b/src/org/warp/picalculator/math/parser/MathParser.java index 3a25e814..8bd44f50 100644 --- a/src/org/warp/picalculator/math/parser/MathParser.java +++ b/src/org/warp/picalculator/math/parser/MathParser.java @@ -1,11 +1,16 @@ package org.warp.picalculator.math.parser; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Arrays; + import org.warp.picalculator.Error; import org.warp.picalculator.Errors; import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockChar; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.BlockDivision; +import org.warp.picalculator.gui.expression.containers.InputContainer; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; import org.warp.picalculator.math.FunctionSingle; @@ -15,6 +20,8 @@ import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Subtraction; import org.warp.picalculator.math.functions.Sum; import org.warp.picalculator.math.functions.SumSubtraction; +import org.warp.picalculator.math.functions.Variable; +import org.warp.picalculator.math.functions.Variable.V_TYPE; import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Expression; import org.warp.picalculator.math.functions.Multiplication; @@ -23,6 +30,7 @@ import org.warp.picalculator.math.parser.features.FeatureDivision; import org.warp.picalculator.math.parser.features.FeatureMultiplication; import org.warp.picalculator.math.parser.features.FeatureNumber; import org.warp.picalculator.math.parser.features.FeatureSum; +import org.warp.picalculator.math.parser.features.FeatureVariable; import org.warp.picalculator.math.parser.features.interfaces.Feature; import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble; @@ -30,75 +38,115 @@ import com.sun.org.apache.xpath.internal.functions.Function2Args; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectListIterator; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class MathParser { - public static Expression parseInput(MathContext context, BlockContainer root) throws Error { + public static Expression parseInput(MathContext context, InputContainer c) throws Error { Expression result; - - Function resultFunction = parseContainer(context, root); - + + final Function resultFunction = parseContainer(context, c.getContent()); + result = new Expression(context, resultFunction); return result; } - - private static Function parseContainer(final MathContext context, final BlockContainer container) throws Error { - final ObjectArrayList blocks = container.getContent(); - final ObjectArrayList blockFeatures = new ObjectArrayList<>(); + + public static ObjectArrayList parseOutput(MathContext context, ObjectArrayList expr) { + final ObjectArrayList resultBlocks = new ObjectArrayList<>(); - for (final Block block : blocks) { - Feature blockFeature = parseBlock(context, block); - blockFeatures.add(blockFeature); + for (Function f : expr) { + resultBlocks.addAll(parseFunction(context, f)); } - Function result = joinFeatures(context, blockFeatures); - return result; + return resultBlocks; } + private static ObjectArrayList parseFunction(MathContext context, Function func) { + ObjectArrayList result = new ObjectArrayList<>(); + if (func instanceof FunctionOperator) { + ObjectArrayList sub1 = parseFunction(context, func.getParameter(0)); + ObjectArrayList sub2 = parseFunction(context, func.getParameter(1)); + if (func instanceof Sum) { + result.addAll(sub1); + result.add(new BlockChar(MathematicalSymbols.SUM)); + result.addAll(sub2); + return result; + } + } + if (func instanceof Number) { + Number numb = (Number) func; + BigDecimal decimal = numb.getTerm(); + String numberString; + if (numb.isInteger()) { + BigInteger integ = decimal.toBigInteger(); + numberString = integ.toString(); + } else { + numberString = decimal.toPlainString(); + } + for (char c : numberString.toCharArray()) { + result.add(new BlockChar(c)); + } + return result; + } + throw new UnsupportedOperationException("Unknown function " + func.getClass().getSimpleName()); + } + + private static Function parseContainer(final MathContext context, final Iterable blocks) throws Error { + final ObjectArrayList blockFeatures = new ObjectArrayList<>(); + + for (final Block block : blocks) { + final Feature blockFeature = parseBlock(context, block); + blockFeatures.add(blockFeature); + } + + final Function result = joinFeatures(context, blockFeatures); + return result; + } + private static Feature parseBlock(final MathContext context, final Block block) throws Error { - + Feature result; - - int blockType = block.getClassID(); + + final int blockType = block.getClassID(); switch (blockType) { case BlockChar.CLASS_ID: result = new FeatureChar(((BlockChar) block).getChar()); break; case BlockDivision.CLASS_ID: - BlockDivision bd = (BlockDivision) block; - Function upper = parseContainer(context, bd.getUpperContainer()); - Function lower = parseContainer(context, bd.getLowerContainer()); + final BlockDivision bd = (BlockDivision) block; + final Function upper = parseContainer(context, bd.getUpperContainer().getContent()); + final Function lower = parseContainer(context, bd.getLowerContainer().getContent()); result = new FeatureDivision(upper, lower); break; default: throw new Error(Errors.SYNTAX_ERROR); } - + return result; } private static Function joinFeatures(final MathContext context, ObjectArrayList features) throws Error { - + features = fixFeatures(context, features); - ObjectArrayList process = makeFunctions(context, features); - + final ObjectArrayList process = makeFunctions(context, features); + fixStack(context, process); - + if (process.size() > 1) { throw new Error(Errors.UNBALANCED_STACK, "The stack is unbalanced. Not all the functions are nested correctly"); } - + return process.get(0); } - + private static void fixStack(MathContext context, ObjectArrayList process) throws Error { //Phase 1 ObjectListIterator stackIterator = process.listIterator(process.size()); Function lastElement = null; while (stackIterator.hasPrevious()) { - Function f = stackIterator.previous(); - + final Function f = stackIterator.previous(); + if (f instanceof FunctionSingle) { if (((FunctionSingle) f).getParameter() == null) { if (lastElement == null) { @@ -115,19 +163,16 @@ public class MathParser { //Phase 2 stackIterator = process.listIterator(); while (stackIterator.hasNext()) { - Function f = stackIterator.next(); + final Function f = stackIterator.next(); final int curIndex = stackIterator.previousIndex(); - + if (f instanceof Multiplication || f instanceof Division) { - if (curIndex-1>=0 && stackIterator.hasNext()) { - Function next = process.get(curIndex+1); - Function prev = process.get(curIndex-1); - stackIterator.set( - f.setParameter(0, prev) - .setParameter(1, next) - ); - process.remove(curIndex+1); - process.remove(curIndex-1); + if (curIndex - 1 >= 0 && stackIterator.hasNext()) { + final Function next = process.get(curIndex + 1); + final Function prev = process.get(curIndex - 1); + stackIterator.set(f.setParameter(0, prev).setParameter(1, next)); + process.remove(curIndex + 1); + process.remove(curIndex - 1); } else { if (f.getParameter(0) == null || f.getParameter(1) == null) { throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); @@ -139,65 +184,88 @@ public class MathParser { //Phase 3 stackIterator = process.listIterator(); while (stackIterator.hasNext()) { - Function f = stackIterator.next(); - + final Function f = stackIterator.next(); + final int curIndex = stackIterator.previousIndex(); + if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) { - + if (curIndex - 1 >= 0 && stackIterator.hasNext()) { + final Function next = process.get(curIndex + 1); + final Function prev = process.get(curIndex - 1); + stackIterator.set(f.setParameter(0, prev).setParameter(1, next)); + process.remove(curIndex + 1); + process.remove(curIndex - 1); + } else { + if (f.getParameter(0) == null || f.getParameter(1) == null) { + throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + } + } } } //Phase 4 stackIterator = process.iterator(); while (stackIterator.hasNext()) { - Function f = stackIterator.next(); - + final Function f = stackIterator.next(); + if (f instanceof Function2Args) { - + } } } - private static ObjectArrayList makeFunctions(MathContext context, ObjectArrayList features) throws Error { - ObjectArrayList process = new ObjectArrayList<>(); - - for (Feature f : features) { + private static ObjectArrayList makeFunctions(MathContext context, ObjectArrayList features) + throws Error { + final ObjectArrayList process = new ObjectArrayList<>(); + + for (final Feature f : features) { if (f instanceof FeatureDivision) { process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); } else if (f instanceof FeatureMultiplication) { process.add(new Multiplication(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); + } else if (f instanceof FeatureVariable) { + process.add(new Variable(context, ((FeatureVariable) f).ch, ((FeatureVariable) f).varType)); + } else if (f instanceof FeatureSum) { + process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); +// } else if (f instanceof FeatureSubtraction) { +// process.add(new Subtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); +// } else if (f instanceof FeatureSumSubtraction) { +// process.add(new SumSubtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); } else if (f instanceof FeatureNumber) { process.add(new Number(context, ((FeatureNumber) f).getNumberString())); } else if (f instanceof FeatureChar) { //All the char features must have been changed already before - throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName().toString() + "\" can't be converted into a Function!"); + throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!"); } else { - throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName().toString() + "\" can't be converted into a Function!"); + throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!"); } } return process; } - private static ObjectArrayList fixFeatures(final MathContext context, ObjectArrayList features) throws Error { - + private static ObjectArrayList fixFeatures(final MathContext context, ObjectArrayList features) + throws Error { + features = fixMinuses(context, features); - + features = makeNumbers(context, features); - + features = convertFunctionChars(context, features); - + return features; } - + /** * Create function features from char features + * * @param context * @param features * @return */ - private static ObjectArrayList convertFunctionChars(MathContext context, ObjectArrayList features) throws Error { - ObjectArrayList process = new ObjectArrayList<>(); - - for (Feature f : features) { + private static ObjectArrayList convertFunctionChars(MathContext context, ObjectArrayList features) + throws Error { + final ObjectArrayList process = new ObjectArrayList<>(); + + for (final Feature f : features) { if (f instanceof FeatureChar) { final char featureChar = ((FeatureChar) f).ch; Feature result = null; @@ -210,35 +278,44 @@ public class MathParser { break; } + //TODO: Temporary solution. In near future Variables will be distint objects and they will have a color. So they will be no longer a BlockChar/FeatureChar + for (char var : MathematicalSymbols.variables) { + if ( featureChar == var) { + result = new FeatureVariable(featureChar, V_TYPE.UNKNOWN); + break; + } + } + if (result == null) { throw new Error(Errors.SYNTAX_ERROR, "Char " + featureChar + " isn't a known feature"); } - + process.add(result); } else { process.add(f); } } - + return process; } /** * Make numbers [-][1][2][+][-][3] => [-12] + * * @param context * @param features * @return */ private static ObjectArrayList makeNumbers(MathContext context, ObjectArrayList features) { - ObjectArrayList process = new ObjectArrayList<>(); - + final ObjectArrayList process = new ObjectArrayList<>(); + FeatureNumber numberBuffer = null; - for (Feature f : features) { + for (final Feature f : features) { if (f instanceof FeatureChar) { final FeatureChar bcf = (FeatureChar) f; final char[] numbers = MathematicalSymbols.numbers; boolean isNumber = false; - for (char n : numbers) { + for (final char n : numbers) { if (bcf.ch == n) { isNumber = true; break; @@ -264,29 +341,31 @@ public class MathParser { process.add(f); } } - + return process; } /** * Fix minuses [-][1][2][+][-][3][-][2] => [-][12][+][-][3][—][2] + * * @param context * @param features * @return * @throws Error */ - private static ObjectArrayList fixMinuses(final MathContext context, ObjectArrayList features) throws Error { - ObjectArrayList process = new ObjectArrayList<>(); + private static ObjectArrayList fixMinuses(final MathContext context, ObjectArrayList features) + throws Error { + final ObjectArrayList process = new ObjectArrayList<>(); Feature lastFeature = null; - for (Feature f : features) { - if (f instanceof FeatureChar && ((FeatureChar)f).ch == MathematicalSymbols.SUBTRACTION) { + for (final Feature f : features) { + if (f instanceof FeatureChar && ((FeatureChar) f).ch == MathematicalSymbols.SUBTRACTION) { boolean isNegativeOfNumber = false; if (lastFeature == null) { isNegativeOfNumber = true; } else if (lastFeature instanceof FeatureChar) { - FeatureChar lcf = (FeatureChar) lastFeature; + final FeatureChar lcf = (FeatureChar) lastFeature; final char[] operators = MathematicalSymbols.functionsNSN; - for (char operator : operators) { + for (final char operator : operators) { if (lcf.ch == operator) { isNegativeOfNumber = true; break; diff --git a/src/org/warp/picalculator/math/parser/features/FeatureChar.java b/src/org/warp/picalculator/math/parser/features/FeatureChar.java index 3797e3c8..8891de50 100644 --- a/src/org/warp/picalculator/math/parser/features/FeatureChar.java +++ b/src/org/warp/picalculator/math/parser/features/FeatureChar.java @@ -5,7 +5,7 @@ import org.warp.picalculator.math.parser.features.interfaces.Feature; public class FeatureChar implements Feature { public final char ch; - + public FeatureChar(char ch) { this.ch = ch; } diff --git a/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java b/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java index 86afd892..96dd95a7 100644 --- a/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java +++ b/src/org/warp/picalculator/math/parser/features/FeatureDoubleImpl.java @@ -5,12 +5,12 @@ import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble; public abstract class FeatureDoubleImpl implements FeatureDouble { private Object child_1; private Object child_2; - + public FeatureDoubleImpl(Object child1, Object child2) { child_1 = child1; child_2 = child2; } - + @Override public Object getChild1() { return child_1; diff --git a/src/org/warp/picalculator/math/parser/features/FeatureNumber.java b/src/org/warp/picalculator/math/parser/features/FeatureNumber.java index 4e8be142..80ece780 100644 --- a/src/org/warp/picalculator/math/parser/features/FeatureNumber.java +++ b/src/org/warp/picalculator/math/parser/features/FeatureNumber.java @@ -4,24 +4,24 @@ import org.warp.picalculator.math.parser.features.interfaces.FeatureBasic; public class FeatureNumber implements FeatureBasic { private String numberString; - - public FeatureNumber(char c){ - numberString = c+""; + + public FeatureNumber(char c) { + numberString = c + ""; } - + public FeatureNumber(String s) { numberString = s; } - + public FeatureNumber() { numberString = ""; } - + public String getNumberString() { return numberString; } public void append(char ch) { - numberString+=ch; + numberString += ch; } } diff --git a/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java b/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java index e3ea1312..9649b5de 100644 --- a/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java +++ b/src/org/warp/picalculator/math/parser/features/FeatureSingleImpl.java @@ -4,11 +4,11 @@ import org.warp.picalculator.math.parser.features.interfaces.FeatureSingle; public abstract class FeatureSingleImpl implements FeatureSingle { private Object child; - + public FeatureSingleImpl(Object child) { this.child = child; } - + @Override public Object getChild() { return child; diff --git a/src/org/warp/picalculator/math/parser/features/FeatureVariable.java b/src/org/warp/picalculator/math/parser/features/FeatureVariable.java new file mode 100644 index 00000000..c00cbe03 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureVariable.java @@ -0,0 +1,15 @@ +package org.warp.picalculator.math.parser.features; + +import org.warp.picalculator.math.functions.Variable.V_TYPE; +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +public class FeatureVariable extends FeatureChar { + + public V_TYPE varType; + + public FeatureVariable(char ch, V_TYPE varType) { + super(ch); + this.varType = varType; + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java b/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java index fa361356..add0f9f0 100644 --- a/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java +++ b/src/org/warp/picalculator/math/parser/features/interfaces/Feature.java @@ -1,5 +1,5 @@ package org.warp.picalculator.math.parser.features.interfaces; public abstract interface Feature { - + } diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java index cc19c77e..80e8569e 100644 --- a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureBasic.java @@ -1,4 +1,3 @@ package org.warp.picalculator.math.parser.features.interfaces; -public interface FeatureBasic extends Feature { -} +public interface FeatureBasic extends Feature {} diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java index 2c871f4e..86c4e6f0 100644 --- a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureDouble.java @@ -2,7 +2,10 @@ package org.warp.picalculator.math.parser.features.interfaces; public interface FeatureDouble extends Feature { public Object getChild1(); + public void setChild1(Object obj); + public Object getChild2(); + public void setChild2(Object obj); } diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java index 71f47049..c7807356 100644 --- a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureMultiple.java @@ -2,9 +2,14 @@ package org.warp.picalculator.math.parser.features.interfaces; public interface FeatureMultiple extends Feature { public Object[] getChildren(); + public Object getChild(int index); + public int getChildCount(); + public void setChild(int index, Object obj); + public void setChildren(Object[] objs); + public void addChild(Object obj); } diff --git a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java index 6c5e46b7..39895f44 100644 --- a/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java +++ b/src/org/warp/picalculator/math/parser/features/interfaces/FeatureSingle.java @@ -2,5 +2,6 @@ package org.warp.picalculator.math.parser.features.interfaces; public interface FeatureSingle extends Feature { public Object getChild(); + public void setChild(Object obj); } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule16.java b/src/org/warp/picalculator/math/rules/ExponentRule16.java index a71405ae..9e349946 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule16.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule16.java @@ -23,11 +23,11 @@ public class ExponentRule16 { public static boolean compare(Function f) { final Multiplication fnc = (Multiplication) f; if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) { - return ((Power)fnc.getParameter1()).getParameter1().equals(((Power)fnc.getParameter2()).getParameter1()); + return ((Power) fnc.getParameter1()).getParameter1().equals(((Power) fnc.getParameter2()).getParameter1()); } else if (fnc.getParameter1() instanceof Power) { - return ((Power)fnc.getParameter1()).getParameter1().equals(fnc.getParameter2()); + return ((Power) fnc.getParameter1()).getParameter1().equals(fnc.getParameter2()); } else if (fnc.getParameter2() instanceof Power) { - return ((Power)fnc.getParameter2()).getParameter1().equals(fnc.getParameter1()); + return ((Power) fnc.getParameter2()).getParameter1().equals(fnc.getParameter1()); } return false; } @@ -37,11 +37,11 @@ public class ExponentRule16 { final ObjectArrayList result = new ObjectArrayList<>(); final Multiplication fnc = (Multiplication) f; if (fnc.getParameter1() instanceof Power && fnc.getParameter2() instanceof Power) { - result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Expression(root, ((Power)fnc.getParameter2()).getParameter2())))); + result.add(new Power(root, ((Power) fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power) fnc.getParameter1()).getParameter2()), new Expression(root, ((Power) fnc.getParameter2()).getParameter2())))); } else if (fnc.getParameter1() instanceof Power) { - result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power)fnc.getParameter1()).getParameter2()), new Number(root, 1)))); + result.add(new Power(root, ((Power) fnc.getParameter1()).getParameter1(), new Sum(root, new Expression(root, ((Power) fnc.getParameter1()).getParameter2()), new Number(root, 1)))); } else if (fnc.getParameter2() instanceof Power) { - result.add(new Power(root, ((Power)fnc.getParameter1()).getParameter1(), new Sum(root, new Number(root, 1), new Expression(root, ((Power)fnc.getParameter2()).getParameter2())))); + result.add(new Power(root, ((Power) fnc.getParameter1()).getParameter1(), new Sum(root, new Number(root, 1), new Expression(root, ((Power) fnc.getParameter2()).getParameter2())))); } return result; } diff --git a/src/org/warp/picalculator/math/rules/ExponentRule9.java b/src/org/warp/picalculator/math/rules/ExponentRule9.java index 188fa867..396665cc 100644 --- a/src/org/warp/picalculator/math/rules/ExponentRule9.java +++ b/src/org/warp/picalculator/math/rules/ExponentRule9.java @@ -7,7 +7,6 @@ import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.functions.Expression; import org.warp.picalculator.math.functions.Multiplication; -import org.warp.picalculator.math.functions.Number; import org.warp.picalculator.math.functions.Power; /** diff --git a/src/org/warp/picalculator/math/rules/FractionsRule11.java b/src/org/warp/picalculator/math/rules/FractionsRule11.java index 5c888d62..201a3d5b 100644 --- a/src/org/warp/picalculator/math/rules/FractionsRule11.java +++ b/src/org/warp/picalculator/math/rules/FractionsRule11.java @@ -39,8 +39,8 @@ public class FractionsRule11 { Function b; Function c; - Division div2 = (Division) fnc.getParameter2(); - + final Division div2 = (Division) fnc.getParameter2(); + a = fnc.getParameter1(); b = div2.getParameter1(); c = div2.getParameter2(); diff --git a/src/org/warp/picalculator/math/rules/VariableRule2.java b/src/org/warp/picalculator/math/rules/VariableRule2.java index f22123a6..32c389ee 100644 --- a/src/org/warp/picalculator/math/rules/VariableRule2.java +++ b/src/org/warp/picalculator/math/rules/VariableRule2.java @@ -38,7 +38,6 @@ public class VariableRule2 { final Function a = m1.getParameter1(); final Function x = fnc.getParameter2(); - FunctionOperator rets; if (fnc instanceof Sum) { rets = new Sum(root, a, new Number(root, 1)); From 57fc8cfa44a8252b6044e22256bad9eebcba5a41 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Tue, 11 Apr 2017 22:04:44 +0200 Subject: [PATCH 07/10] Added new expression blocks, like parentheses and power of x --- res/draft unknown variable choice.png | Bin 0 -> 6019 bytes res/font_ex.rft | Bin 1667 -> 1735 bytes .../gui/expression/BlockContainer.java | 28 +- .../expression/BlockExponentialNotation.java | 8 + .../gui/expression/BlockParenthesis.java | 16 +- .../gui/expression/BlockPower.java | 97 ++++++ .../expression/containers/InputContainer.java | 4 + .../containers/NormalInputContainer.java | 15 +- .../picalculator/math/parser/MathParser.java | 303 ++++++++++++++---- .../parser/features/FeatureParenthesis.java | 9 + .../math/parser/features/FeaturePower.java | 11 + .../parser/features/FeatureSquareRoot.java | 9 + 12 files changed, 424 insertions(+), 76 deletions(-) create mode 100644 res/draft unknown variable choice.png create mode 100644 src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java create mode 100644 src/org/warp/picalculator/gui/expression/BlockPower.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureParenthesis.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeaturePower.java create mode 100644 src/org/warp/picalculator/math/parser/features/FeatureSquareRoot.java diff --git a/res/draft unknown variable choice.png b/res/draft unknown variable choice.png new file mode 100644 index 0000000000000000000000000000000000000000..973440c9c479ed6694ec4cd3e9b543b7a5af45ef GIT binary patch literal 6019 zcmbt&WmFVS)IPOKEul0^H`3j)Qj3%z-LV29B`mn~vI%rY zsoT}n6AVCp2hOdK@W~{m*BbWS#6RdcUw;He3LoL0bG&BIlospe?uT+1-Hfc?CJmMq z?@iB|&DQyxoewEvic7Z5&2BG`i<0+VZe=h3CSjvJoT%S?TNR*h)OC^hvtNq;N#VFhcx|6-AZ?e+F=I`7f#=He#B`AmCr`p z9;K=pPk-D_r6%0l7<}>o{eU_Zu}DKV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#j&u>4q&0Y={Xj?~^WjQK&h_(J=mp>xJnPKcl%T z^fQRmPhQ7p!h6#cfuA=)cerSIWZeBbx(Yn{fFS1zSfzf1do066#h4SehsE&X$pmUe=xyMxUy_0F3XKykA`bt{Cc^vt>4jfk50B#^wk>;h*h8x5qSRaKa3ino-* zG_;TW)&x+D*@tba5y-U5x)nDh{+hMZoG)DVn7U071?FjevPx9uRxyU0<=4-afkVu_ zXX-2K>S9t)HFTH-C-qSp@AFE}lNn0o+D9-|e^CR*;sd=w7_ao)2_@;>lUcJy35BpP zc64wbR-fv6rMR)PKUHo|-RcC6L|RyB;9!14!S0?WWA|0EI06Gkd5>2LA>4yELTm_c zN9c~VU3L@$o%01YTm=WmNCV@Je8^=6krLHR+Pe>fyk(4u5KZJGD#Zgf^$F z%LAVIr8{vHbuh2g@CIp(8veBuDnXPFFhxpUt2xYW>%W#n1!l%BpaNZ^$frKhiMqR) m*XL$gE&e|W?U}~2ThgD+p*~Ly;_p7r@pQEeHNQV}MEwsCdUrek literal 0 HcmV?d00001 diff --git a/res/font_ex.rft b/res/font_ex.rft index 18475d17b8a623898f8be31c5a89b29160dce17a..26f2257b236effc0bbdf561908fb75a29002ec0a 100644 GIT binary patch delta 76 zcmZqXJYOU@G#V42A>= H9*}MT{&@?N delta 7 OcmX@k+swP6nGFC7r2?J+ diff --git a/src/org/warp/picalculator/gui/expression/BlockContainer.java b/src/org/warp/picalculator/gui/expression/BlockContainer.java index bd553ab7..8f2af1b1 100644 --- a/src/org/warp/picalculator/gui/expression/BlockContainer.java +++ b/src/org/warp/picalculator/gui/expression/BlockContainer.java @@ -11,29 +11,34 @@ public class BlockContainer implements GraphicalElement { private static boolean initialized = false; - private final int minWidth; - private final int minHeight; + private int minWidth; + private int minHeight; private final ObjectArrayList content; private boolean small; private int width; private int height; private int line; public final boolean withBorder; + private boolean autoMinimums; public BlockContainer() { this(false, BlockContainer.getDefaultCharWidth(false), BlockContainer.getDefaultCharHeight(false), true); + autoMinimums = true; } public BlockContainer(boolean small) { this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), true); + autoMinimums = true; } public BlockContainer(boolean small, boolean withBorder) { this(small, BlockContainer.getDefaultCharWidth(small), BlockContainer.getDefaultCharHeight(small), withBorder); + autoMinimums = true; } public BlockContainer(boolean small, int minWidth, int minHeight, boolean withBorder) { this(small, minWidth, minHeight, new ObjectArrayList<>(), withBorder); + autoMinimums = false; } public BlockContainer(boolean small, int minWidth, int minHeight, ObjectArrayList content, boolean withBorder) { @@ -111,9 +116,9 @@ public class BlockContainer implements GraphicalElement { if (caret.getRemaining() == 0) { if (content.size() > 0) { - BlockContainer.drawCaret(ge, r, caret, x, y + line - content.get(0).line, content.get(0).height); + BlockContainer.drawCaret(ge, r, caret, small, x, y + line - content.get(0).line, content.get(0).height); } else { - BlockContainer.drawCaret(ge, r, caret, x, y, height); + BlockContainer.drawCaret(ge, r, caret, small, x, y, height); } } @@ -128,7 +133,7 @@ public class BlockContainer implements GraphicalElement { b.draw(ge, r, x + paddingX, y + line - b.line, caret); paddingX += b.getWidth(); if (caret.getRemaining() == 0) { - BlockContainer.drawCaret(ge, r, caret, x + paddingX, y + line - b.line, b.height); + BlockContainer.drawCaret(ge, r, caret, small, x + paddingX, y + line - b.line, b.height); } paddingX += 1; } @@ -271,17 +276,22 @@ public class BlockContainer implements GraphicalElement { return defFontSizes[b ? 3 : 1]; } - public static void drawCaret(GraphicEngine ge, Renderer r, Caret caret, int x, int y, int height) { + public static void drawCaret(GraphicEngine ge, Renderer r, Caret caret, boolean small, int x, int y, int height) { if (caret.getState() == CaretState.VISIBLE_ON) { r.glColor(getDefaultColor()); - r.glDrawLine(x, y, x, y - 1 + height); - r.glDrawLine(x + 1, y, x + 1, y - 1 + height); - r.glDrawLine(x + 2, y, x + 2, y - 1 + height); + r.glFillColor(x, y, small?2:3, height); } } public void setSmall(boolean small) { this.small = small; + if (this.autoMinimums) { + this.minWidth = BlockContainer.getDefaultCharWidth(small); + this.minHeight = BlockContainer.getDefaultCharHeight(small); + } + for (Block b : this.content) { + b.setSmall(small); + } recomputeDimensions(); } diff --git a/src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java b/src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java new file mode 100644 index 00000000..14511a5e --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java @@ -0,0 +1,8 @@ +package org.warp.picalculator.gui.expression; + +public class BlockExponentialNotation extends BlockPower { + @Override + protected int getSpacing() { + return -3; + } +} diff --git a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java b/src/org/warp/picalculator/gui/expression/BlockParenthesis.java index 91c89e27..104c8ee1 100644 --- a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java +++ b/src/org/warp/picalculator/gui/expression/BlockParenthesis.java @@ -1,5 +1,6 @@ package org.warp.picalculator.gui.expression; +import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; @@ -9,6 +10,9 @@ public class BlockParenthesis extends Block { private final BlockContainer containerNumber; + private int chw; + private int chh; + public BlockParenthesis() { containerNumber = new BlockContainer(false); recomputeDimensions(); @@ -18,7 +22,13 @@ public class BlockParenthesis extends Block { public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { BlockContainer.getDefaultFont(small).use(ge); r.glColor(BlockContainer.getDefaultColor()); - containerNumber.draw(ge, r, x + 7, y + 3, caret); + r.glDrawCharLeft(x, y, '╭'); + r.glDrawCharLeft(x, y+height-chh, '╰'); + r.glFillColor(x+3, y+6, 2, height-6*2); + r.glFillColor(x+width-5, y+6, 2, height-6*2); + r.glDrawCharLeft(x+width-chw, y, '╮'); + r.glDrawCharLeft(x+width-chw, y+height-chh, '╯'); + containerNumber.draw(ge, r, x+chw, y, caret); } @Override @@ -43,7 +53,9 @@ public class BlockParenthesis extends Block { @Override public void recomputeDimensions() { - width = containerNumber.getWidth() + BlockContainer.getDefaultCharWidth(small) * 2; + chw = BlockContainer.getDefaultCharWidth(small); + chh = BlockContainer.getDefaultCharHeight(small); + width = containerNumber.getWidth() + chw * 2 + 3; height = containerNumber.getHeight(); line = containerNumber.getLine(); } diff --git a/src/org/warp/picalculator/gui/expression/BlockPower.java b/src/org/warp/picalculator/gui/expression/BlockPower.java new file mode 100644 index 00000000..df8f5984 --- /dev/null +++ b/src/org/warp/picalculator/gui/expression/BlockPower.java @@ -0,0 +1,97 @@ +package org.warp.picalculator.gui.expression; + +import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.graphicengine.GraphicEngine; +import org.warp.picalculator.gui.graphicengine.Renderer; + +public class BlockPower extends Block { + + public static final int CLASS_ID = 0x00000005; + + private final BlockContainer containerNumber; + private final BlockContainer containerExponent; + + private int h1; + private int w1; + + public BlockPower() { + containerNumber = new BlockContainer(false); + containerExponent = new BlockContainer(true); + recomputeDimensions(); + } + + @Override + public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { + BlockContainer.getDefaultFont(small).use(ge); + r.glColor(BlockContainer.getDefaultColor()); + containerNumber.draw(ge, r, x, y+height-h1, caret); + BlockContainer.getDefaultFont(true).use(ge); + containerExponent.draw(ge, r, x+w1+getSpacing(), y, caret); + } + + @Override + public boolean putBlock(Caret caret, Block newBlock) { + boolean added = false; + added = added | containerNumber.putBlock(caret, newBlock); + added = added | containerExponent.putBlock(caret, newBlock); + if (added) { + recomputeDimensions(); + } + return added; + } + + @Override + public boolean delBlock(Caret caret) { + boolean removed = false; + removed = removed | containerNumber.delBlock(caret); + removed = removed | containerExponent.delBlock(caret); + if (removed) { + recomputeDimensions(); + } + return removed; + } + + @Override + public void recomputeDimensions() { + w1 = containerNumber.getWidth(); + final int w2 = containerExponent.getWidth(); + h1 = containerNumber.getHeight(); + final int h2 = containerExponent.getHeight(); + final int l1 = containerNumber.getLine(); + width = w1+getSpacing()+1+w2; + height = h1 + h2 - 3; + line = height-h1+l1; + } + + @Override + public void setSmall(boolean small) { + this.small = small; + containerNumber.setSmall(small); + containerExponent.setSmall(true); + recomputeDimensions(); + } + + public BlockContainer getNumberContainer() { + return containerNumber; + } + + public BlockContainer getExponentContainer() { + return containerExponent; + } + + @Override + public int getClassID() { + return CLASS_ID; + } + + @Override + public int computeCaretMaxBound() { + return containerNumber.computeCaretMaxBound() + containerExponent.computeCaretMaxBound(); + } + + protected int getSpacing() { + return 1; + } +} diff --git a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java index 6f734fb6..6e857f95 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java @@ -74,6 +74,8 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S final int curPos = caret.getPosition(); if (curPos > 0) { caret.setPosition(curPos - 1); + } else { + caret.setPosition(maxPosition-1); } caret.turnOn(); caretTime = 0; @@ -83,6 +85,8 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S final int curPos = caret.getPosition(); if (curPos + 1 < maxPosition) { caret.setPosition(curPos + 1); + } else { + caret.setPosition(0); } caret.turnOn(); caretTime = 0; diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java index ec6aadd8..9efe4cfb 100644 --- a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java @@ -4,6 +4,7 @@ import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockChar; import org.warp.picalculator.gui.expression.BlockDivision; import org.warp.picalculator.gui.expression.BlockParenthesis; +import org.warp.picalculator.gui.expression.BlockPower; import org.warp.picalculator.gui.expression.BlockSquareRoot; import org.warp.picalculator.math.MathematicalSymbols; @@ -29,8 +30,12 @@ public class NormalInputContainer extends InputContainer { case MathematicalSymbols.SQUARE_ROOT: return new BlockSquareRoot(); case MathematicalSymbols.PARENTHESIS_OPEN: - case MathematicalSymbols.PARENTHESIS_CLOSE: return new BlockParenthesis(); + case MathematicalSymbols.PARENTHESIS_CLOSE: + return null; + case MathematicalSymbols.POWER: + case MathematicalSymbols.POWER_OF_TWO: + return new BlockPower(); case MathematicalSymbols.MULTIPLICATION: case MathematicalSymbols.SUM: case MathematicalSymbols.SUM_SUBTRACTION: @@ -50,4 +55,12 @@ public class NormalInputContainer extends InputContainer { return new BlockChar(c); } } + + @Override + public void typeChar(char c) { + super.typeChar(c); + if (c == MathematicalSymbols.PARENTHESIS_CLOSE) { + this.moveRight(); + } + } } diff --git a/src/org/warp/picalculator/math/parser/MathParser.java b/src/org/warp/picalculator/math/parser/MathParser.java index 8bd44f50..4a4c7552 100644 --- a/src/org/warp/picalculator/math/parser/MathParser.java +++ b/src/org/warp/picalculator/math/parser/MathParser.java @@ -10,6 +10,10 @@ import org.warp.picalculator.gui.expression.Block; import org.warp.picalculator.gui.expression.BlockChar; import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.BlockDivision; +import org.warp.picalculator.gui.expression.BlockExponentialNotation; +import org.warp.picalculator.gui.expression.BlockParenthesis; +import org.warp.picalculator.gui.expression.BlockPower; +import org.warp.picalculator.gui.expression.BlockSquareRoot; import org.warp.picalculator.gui.expression.containers.InputContainer; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; @@ -17,6 +21,8 @@ import org.warp.picalculator.math.FunctionSingle; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.functions.Number; +import org.warp.picalculator.math.functions.Power; +import org.warp.picalculator.math.functions.RootSquare; import org.warp.picalculator.math.functions.Subtraction; import org.warp.picalculator.math.functions.Sum; import org.warp.picalculator.math.functions.SumSubtraction; @@ -29,12 +35,17 @@ import org.warp.picalculator.math.parser.features.FeatureChar; import org.warp.picalculator.math.parser.features.FeatureDivision; import org.warp.picalculator.math.parser.features.FeatureMultiplication; import org.warp.picalculator.math.parser.features.FeatureNumber; +import org.warp.picalculator.math.parser.features.FeatureParenthesis; +import org.warp.picalculator.math.parser.features.FeaturePower; +import org.warp.picalculator.math.parser.features.FeatureSquareRoot; import org.warp.picalculator.math.parser.features.FeatureSum; import org.warp.picalculator.math.parser.features.FeatureVariable; import org.warp.picalculator.math.parser.features.interfaces.Feature; import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble; +import org.warp.picalculator.math.parser.features.interfaces.FeatureSingle; import com.sun.org.apache.xpath.internal.functions.Function2Args; +import com.sun.org.apache.xpath.internal.operations.Mult; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectListIterator; @@ -50,7 +61,7 @@ public class MathParser { return result; } - public static ObjectArrayList parseOutput(MathContext context, ObjectArrayList expr) { + public static ObjectArrayList parseOutput(MathContext context, ObjectArrayList expr) throws Error { final ObjectArrayList resultBlocks = new ObjectArrayList<>(); for (Function f : expr) { @@ -60,7 +71,7 @@ public class MathParser { return resultBlocks; } - private static ObjectArrayList parseFunction(MathContext context, Function func) { + private static ObjectArrayList parseFunction(MathContext context, Function func) throws Error { ObjectArrayList result = new ObjectArrayList<>(); if (func instanceof FunctionOperator) { ObjectArrayList sub1 = parseFunction(context, func.getParameter(0)); @@ -71,23 +82,124 @@ public class MathParser { result.addAll(sub2); return result; } + if (func instanceof Subtraction) { + result.addAll(sub1); + result.add(new BlockChar(MathematicalSymbols.SUBTRACTION)); + result.addAll(sub2); + return result; + } + if (func instanceof SumSubtraction) { + result.addAll(sub1); + result.add(new BlockChar(MathematicalSymbols.SUM_SUBTRACTION)); + result.addAll(sub2); + return result; + } + if (func instanceof Multiplication) { + Block nearLeft = sub1.get(sub1.size()-1); + Block nearRight = sub2.get(0); + + result.addAll(sub1); + if (nearLeft instanceof BlockChar && nearRight instanceof BlockChar) { + + } else { + result.add(new BlockChar(MathematicalSymbols.MULTIPLICATION)); + } + result.addAll(sub2); + return result; + } + if (func instanceof Division) { + BlockDivision bd = new BlockDivision(); + BlockContainer uc = bd.getUpperContainer(); + BlockContainer lc = bd.getLowerContainer(); + for (Block b : sub1) { + uc.appendBlockUnsafe(b); + } + for (Block b : sub2) { + lc.appendBlockUnsafe(b); + } + uc.recomputeDimensions(); + lc.recomputeDimensions(); + bd.recomputeDimensions(); + result.add(bd); + return result; + } + if (func instanceof Power) { + BlockPower bp = new BlockPower(); + BlockContainer nc = bp.getNumberContainer(); + BlockContainer ec = bp.getExponentContainer(); + for (Block b : sub1) { + nc.appendBlockUnsafe(b); + } + for (Block b : sub2) { + ec.appendBlockUnsafe(b); + } + nc.recomputeDimensions(); + ec.recomputeDimensions(); + bp.recomputeDimensions(); + result.add(bp); + return result; + } + } + if (func instanceof FunctionSingle) { + ObjectArrayList sub = parseFunction(context, func.getParameter(0)); + if (func instanceof RootSquare) { + BlockSquareRoot bsqr = new BlockSquareRoot(); + BlockContainer bsqrc = bsqr.getNumberContainer(); + for (Block b : sub) { + bsqrc.appendBlockUnsafe(b); + } + bsqrc.recomputeDimensions(); + bsqr.recomputeDimensions(); + result.add((bsqr)); + return result; + } + + } + if (func instanceof Expression) { + ObjectArrayList sub = parseFunction(context, ((Expression) func).getParameter(0)); + BlockParenthesis bp = new BlockParenthesis(); + BlockContainer bpc = bp.getNumberContainer(); + for (Block b : sub) { + bpc.appendBlockUnsafe(b); + } + bpc.recomputeDimensions(); + bp.recomputeDimensions(); + result.add(bp); + return result; } if (func instanceof Number) { Number numb = (Number) func; - BigDecimal decimal = numb.getTerm(); - String numberString; - if (numb.isInteger()) { - BigInteger integ = decimal.toBigInteger(); - numberString = integ.toString(); + String numberString = numb.toString(); + if (numberString.contains("ℯ℮")) { + String[] numberParts = numberString.split("ℯ℮", 2); + numberParts[0]+="ℯ℮"; + BlockPower bp = new BlockExponentialNotation(); + BlockContainer bpnc = bp.getNumberContainer(); + BlockContainer bpec = bp.getExponentContainer(); + for (char c : numberParts[0].toCharArray()) { + bpnc.appendBlockUnsafe(new BlockChar(c)); + } + for (char c : numberParts[1].toCharArray()) { + bpec.appendBlockUnsafe(new BlockChar(c)); + } + bpnc.recomputeDimensions(); + bpec.recomputeDimensions(); + bp.recomputeDimensions(); + result.add(bp); + return result; } else { - numberString = decimal.toPlainString(); - } - for (char c : numberString.toCharArray()) { - result.add(new BlockChar(c)); + for (char c : numberString.toCharArray()) { + result.add(new BlockChar(c)); + } } return result; } - throw new UnsupportedOperationException("Unknown function " + func.getClass().getSimpleName()); + if (func instanceof Variable) { + //TODO: Temporary solution. In near future Variables will be distint objects and they will have a color. So they will be no longer a BlockChar/FeatureChar + result.add(new BlockChar(((Variable) func).getChar())); + return result; + } + throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + func.getClass().getSimpleName()); } private static Function parseContainer(final MathContext context, final Iterable blocks) throws Error { @@ -117,8 +229,24 @@ public class MathParser { final Function lower = parseContainer(context, bd.getLowerContainer().getContent()); result = new FeatureDivision(upper, lower); break; + case BlockSquareRoot.CLASS_ID: + final BlockSquareRoot bsqr = (BlockSquareRoot) block; + final Function contnt = parseContainer(context, bsqr.getNumberContainer().getContent()); + result = new FeatureSquareRoot(contnt); + break; + case BlockParenthesis.CLASS_ID: + final BlockParenthesis bp = (BlockParenthesis) block; + final Function cont = parseContainer(context, bp.getNumberContainer().getContent()); + result = new FeatureParenthesis(cont); + break; + case BlockPower.CLASS_ID: + final BlockPower blp = (BlockPower) block; + final Function nmb = parseContainer(context, blp.getNumberContainer().getContent()); + final Function exp = parseContainer(context, blp.getExponentContainer().getContent()); + result = new FeaturePower(nmb, exp); + break; default: - throw new Error(Errors.SYNTAX_ERROR); + throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known BLock"); } return result; @@ -141,76 +269,117 @@ public class MathParser { private static void fixStack(MathContext context, ObjectArrayList process) throws Error { - //Phase 1 - ObjectListIterator stackIterator = process.listIterator(process.size()); - Function lastElement = null; - while (stackIterator.hasPrevious()) { - final Function f = stackIterator.previous(); - - if (f instanceof FunctionSingle) { - if (((FunctionSingle) f).getParameter() == null) { - if (lastElement == null) { - throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); - } else { - ((FunctionSingle) f).setParameter(lastElement); - process.remove(stackIterator.nextIndex()); + boolean lastLoopDidSomething; + + ObjectListIterator stackIterator; + + //Phase 0: join number and variables ([2][x] => [[2]*[x]]) + do { + lastLoopDidSomething = false; + stackIterator = process.listIterator(process.size()); + Function lastElement = null; + while (stackIterator.hasPrevious()) { + final Function f = stackIterator.previous(); + final int curIndex = stackIterator.nextIndex(); + + if (f instanceof Number | f instanceof Variable) { + if (lastElement instanceof Variable) { + lastLoopDidSomething = true; + final Function var = process.get(curIndex + 1); + final Function numb = process.get(curIndex); + stackIterator.set(new Multiplication(context, numb, var)); + process.remove(curIndex + 1); } } + lastElement = f; } - lastElement = f; - } + } while (lastLoopDidSomething); + + //Phase 1 + do { + lastLoopDidSomething = false; + stackIterator = process.listIterator(process.size()); + Function lastElement = null; + while (stackIterator.hasPrevious()) { + final Function f = stackIterator.previous(); + + if (f instanceof FunctionSingle) { + if (((FunctionSingle) f).getParameter() == null) { + lastLoopDidSomething = true; + if (lastElement == null) { + throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + } else { + ((FunctionSingle) f).setParameter(lastElement); + process.remove(stackIterator.nextIndex()); + } + } + } + lastElement = f; + } + } while (lastLoopDidSomething); //Phase 2 - stackIterator = process.listIterator(); - while (stackIterator.hasNext()) { - final Function f = stackIterator.next(); - final int curIndex = stackIterator.previousIndex(); + do { + lastLoopDidSomething = false; + stackIterator = process.listIterator(); + while (stackIterator.hasNext()) { + final Function f = stackIterator.next(); + final int curIndex = stackIterator.previousIndex(); - if (f instanceof Multiplication || f instanceof Division) { - if (curIndex - 1 >= 0 && stackIterator.hasNext()) { - final Function next = process.get(curIndex + 1); - final Function prev = process.get(curIndex - 1); - stackIterator.set(f.setParameter(0, prev).setParameter(1, next)); - process.remove(curIndex + 1); - process.remove(curIndex - 1); - } else { - if (f.getParameter(0) == null || f.getParameter(1) == null) { - throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + if (f instanceof Multiplication || f instanceof Division) { + if (curIndex - 1 >= 0 && stackIterator.hasNext()) { + lastLoopDidSomething = true; + final Function next = process.get(curIndex + 1); + final Function prev = process.get(curIndex - 1); + stackIterator.set(f.setParameter(0, prev).setParameter(1, next)); + process.remove(curIndex + 1); + process.remove(curIndex - 1); + } else { + if (f.getParameter(0) == null || f.getParameter(1) == null) { + throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + } } } } - } + } while (lastLoopDidSomething); //Phase 3 - stackIterator = process.listIterator(); - while (stackIterator.hasNext()) { - final Function f = stackIterator.next(); - final int curIndex = stackIterator.previousIndex(); + do { + lastLoopDidSomething = false; + stackIterator = process.listIterator(); + while (stackIterator.hasNext()) { + final Function f = stackIterator.next(); + final int curIndex = stackIterator.previousIndex(); - if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) { - if (curIndex - 1 >= 0 && stackIterator.hasNext()) { - final Function next = process.get(curIndex + 1); - final Function prev = process.get(curIndex - 1); - stackIterator.set(f.setParameter(0, prev).setParameter(1, next)); - process.remove(curIndex + 1); - process.remove(curIndex - 1); - } else { - if (f.getParameter(0) == null || f.getParameter(1) == null) { - throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) { + if (curIndex - 1 >= 0 && stackIterator.hasNext()) { + lastLoopDidSomething = true; + final Function next = process.get(curIndex + 1); + final Function prev = process.get(curIndex - 1); + stackIterator.set(f.setParameter(0, prev).setParameter(1, next)); + process.remove(curIndex + 1); + process.remove(curIndex - 1); + } else { + if (f.getParameter(0) == null || f.getParameter(1) == null) { + throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified."); + } } } } - } + } while (lastLoopDidSomething); //Phase 4 - stackIterator = process.iterator(); - while (stackIterator.hasNext()) { - final Function f = stackIterator.next(); + do { + lastLoopDidSomething = false; + stackIterator = process.iterator(); + while (stackIterator.hasNext()) { + final Function f = stackIterator.next(); - if (f instanceof Function2Args) { + if (f instanceof Function2Args) { + } } - } + } while (lastLoopDidSomething); } private static ObjectArrayList makeFunctions(MathContext context, ObjectArrayList features) @@ -226,6 +395,12 @@ public class MathParser { process.add(new Variable(context, ((FeatureVariable) f).ch, ((FeatureVariable) f).varType)); } else if (f instanceof FeatureSum) { process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); + } else if (f instanceof FeaturePower) { + process.add(new Power(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); + } else if (f instanceof FeatureSquareRoot) { + process.add(new RootSquare(context, (Function) ((FeatureSingle) f).getChild())); + } else if (f instanceof FeatureParenthesis) { + process.add(new Expression(context, (Function) ((FeatureSingle) f).getChild())); // } else if (f instanceof FeatureSubtraction) { // process.add(new Subtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); // } else if (f instanceof FeatureSumSubtraction) { @@ -321,7 +496,7 @@ public class MathParser { break; } } - if (bcf.ch == '-') { + if (bcf.ch == '-' || bcf.ch == '.') { isNumber = true; } if (isNumber) { diff --git a/src/org/warp/picalculator/math/parser/features/FeatureParenthesis.java b/src/org/warp/picalculator/math/parser/features/FeatureParenthesis.java new file mode 100644 index 00000000..67e750eb --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureParenthesis.java @@ -0,0 +1,9 @@ +package org.warp.picalculator.math.parser.features; + +public class FeatureParenthesis extends FeatureSingleImpl { + + public FeatureParenthesis(Object child) { + super(child); + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/FeaturePower.java b/src/org/warp/picalculator/math/parser/features/FeaturePower.java new file mode 100644 index 00000000..5de97e33 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeaturePower.java @@ -0,0 +1,11 @@ +package org.warp.picalculator.math.parser.features; + +import org.warp.picalculator.math.parser.features.interfaces.Feature; + +public class FeaturePower extends FeatureDoubleImpl { + + public FeaturePower(Object child1, Object child2) { + super(child1, child2); + } + +} diff --git a/src/org/warp/picalculator/math/parser/features/FeatureSquareRoot.java b/src/org/warp/picalculator/math/parser/features/FeatureSquareRoot.java new file mode 100644 index 00000000..95cfd6c2 --- /dev/null +++ b/src/org/warp/picalculator/math/parser/features/FeatureSquareRoot.java @@ -0,0 +1,9 @@ +package org.warp.picalculator.math.parser.features; + +public class FeatureSquareRoot extends FeatureSingleImpl { + + public FeatureSquareRoot(Object child) { + super(child); + } + +} From 74dc027642630c40e244fa48e3ee4a1d562cf0e3 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Wed, 12 Apr 2017 13:04:35 +0200 Subject: [PATCH 08/10] Moved blocks to block package --- src/org/warp/picalculator/TestGPU.java | 2 +- .../gui/expression/{ => blocks}/Block.java | 3 ++- .../gui/expression/{ => blocks}/BlockChar.java | 3 ++- .../expression/{ => blocks}/BlockContainer.java | 4 +++- .../expression/{ => blocks}/BlockDivision.java | 3 ++- .../{ => blocks}/BlockExponentialNotation.java | 2 +- .../{ => blocks}/BlockParenthesis.java | 3 ++- .../gui/expression/{ => blocks}/BlockPower.java | 6 +++--- .../expression/{ => blocks}/BlockSquareRoot.java | 3 ++- .../containers/InlineInputContainer.java | 4 ++-- .../expression/containers/InputContainer.java | 4 ++-- .../containers/NormalInputContainer.java | 12 ++++++------ .../expression/containers/OutputContainer.java | 4 ++-- .../gui/expression/layouts/InputLayout.java | 2 +- .../gui/screens/MathInputScreen.java | 4 ++-- .../picalculator/math/parser/MathParser.java | 16 ++++++++-------- 16 files changed, 41 insertions(+), 34 deletions(-) rename src/org/warp/picalculator/gui/expression/{ => blocks}/Block.java (87%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockChar.java (87%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockContainer.java (94%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockDivision.java (92%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockExponentialNotation.java (66%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockParenthesis.java (91%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockPower.java (89%) rename src/org/warp/picalculator/gui/expression/{ => blocks}/BlockSquareRoot.java (92%) diff --git a/src/org/warp/picalculator/TestGPU.java b/src/org/warp/picalculator/TestGPU.java index 9c1a0f6b..3674a9bb 100644 --- a/src/org/warp/picalculator/TestGPU.java +++ b/src/org/warp/picalculator/TestGPU.java @@ -8,7 +8,7 @@ import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.KeyboardEventListener; -import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.blocks.BlockContainer; import org.warp.picalculator.gui.expression.containers.NormalInputContainer; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.Skin; diff --git a/src/org/warp/picalculator/gui/expression/Block.java b/src/org/warp/picalculator/gui/expression/blocks/Block.java similarity index 87% rename from src/org/warp/picalculator/gui/expression/Block.java rename to src/org/warp/picalculator/gui/expression/blocks/Block.java index b5a5be01..84fee202 100644 --- a/src/org/warp/picalculator/gui/expression/Block.java +++ b/src/org/warp/picalculator/gui/expression/blocks/Block.java @@ -1,6 +1,7 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; import org.warp.picalculator.gui.GraphicalElement; +import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/BlockChar.java b/src/org/warp/picalculator/gui/expression/blocks/BlockChar.java similarity index 87% rename from src/org/warp/picalculator/gui/expression/BlockChar.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockChar.java index fbce019d..deeffe7b 100644 --- a/src/org/warp/picalculator/gui/expression/BlockChar.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockChar.java @@ -1,5 +1,6 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; +import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/BlockContainer.java b/src/org/warp/picalculator/gui/expression/blocks/BlockContainer.java similarity index 94% rename from src/org/warp/picalculator/gui/expression/BlockContainer.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockContainer.java index 8f2af1b1..d16c6d8e 100644 --- a/src/org/warp/picalculator/gui/expression/BlockContainer.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockContainer.java @@ -1,8 +1,10 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.warp.picalculator.gui.GraphicalElement; +import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.expression.CaretState; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/BlockDivision.java b/src/org/warp/picalculator/gui/expression/blocks/BlockDivision.java similarity index 92% rename from src/org/warp/picalculator/gui/expression/BlockDivision.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockDivision.java index aa8f83eb..e3ddb4a2 100644 --- a/src/org/warp/picalculator/gui/expression/BlockDivision.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockDivision.java @@ -1,5 +1,6 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; +import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java b/src/org/warp/picalculator/gui/expression/blocks/BlockExponentialNotation.java similarity index 66% rename from src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockExponentialNotation.java index 14511a5e..ae6a9218 100644 --- a/src/org/warp/picalculator/gui/expression/BlockExponentialNotation.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockExponentialNotation.java @@ -1,4 +1,4 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; public class BlockExponentialNotation extends BlockPower { @Override diff --git a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java b/src/org/warp/picalculator/gui/expression/blocks/BlockParenthesis.java similarity index 91% rename from src/org/warp/picalculator/gui/expression/BlockParenthesis.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockParenthesis.java index 104c8ee1..5723120c 100644 --- a/src/org/warp/picalculator/gui/expression/BlockParenthesis.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockParenthesis.java @@ -1,5 +1,6 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; +import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.graphicengine.BinaryFont; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/BlockPower.java b/src/org/warp/picalculator/gui/expression/blocks/BlockPower.java similarity index 89% rename from src/org/warp/picalculator/gui/expression/BlockPower.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockPower.java index df8f5984..bf6b77a6 100644 --- a/src/org/warp/picalculator/gui/expression/BlockPower.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockPower.java @@ -1,8 +1,8 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.Caret; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockContainer; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java b/src/org/warp/picalculator/gui/expression/blocks/BlockSquareRoot.java similarity index 92% rename from src/org/warp/picalculator/gui/expression/BlockSquareRoot.java rename to src/org/warp/picalculator/gui/expression/blocks/BlockSquareRoot.java index 5889249c..6f2abea6 100644 --- a/src/org/warp/picalculator/gui/expression/BlockSquareRoot.java +++ b/src/org/warp/picalculator/gui/expression/blocks/BlockSquareRoot.java @@ -1,5 +1,6 @@ -package org.warp.picalculator.gui.expression; +package org.warp.picalculator.gui.expression.blocks; +import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java index 3dff2f57..5255ef35 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InlineInputContainer.java @@ -1,7 +1,7 @@ package org.warp.picalculator.gui.expression.containers; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockChar; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockChar; import org.warp.picalculator.math.MathematicalSymbols; public class InlineInputContainer extends InputContainer { diff --git a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java index 6e857f95..8629d103 100644 --- a/src/org/warp/picalculator/gui/expression/containers/InputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/InputContainer.java @@ -4,10 +4,10 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import org.warp.picalculator.gui.GraphicalElement; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.expression.CaretState; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockContainer; import org.warp.picalculator.gui.expression.layouts.InputLayout; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java index 9efe4cfb..0cece073 100644 --- a/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/NormalInputContainer.java @@ -1,11 +1,11 @@ package org.warp.picalculator.gui.expression.containers; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockChar; -import org.warp.picalculator.gui.expression.BlockDivision; -import org.warp.picalculator.gui.expression.BlockParenthesis; -import org.warp.picalculator.gui.expression.BlockPower; -import org.warp.picalculator.gui.expression.BlockSquareRoot; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockChar; +import org.warp.picalculator.gui.expression.blocks.BlockDivision; +import org.warp.picalculator.gui.expression.blocks.BlockParenthesis; +import org.warp.picalculator.gui.expression.blocks.BlockPower; +import org.warp.picalculator.gui.expression.blocks.BlockSquareRoot; import org.warp.picalculator.math.MathematicalSymbols; public class NormalInputContainer extends InputContainer { diff --git a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java index a751b256..5bb6004d 100644 --- a/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java +++ b/src/org/warp/picalculator/gui/expression/containers/OutputContainer.java @@ -3,10 +3,10 @@ package org.warp.picalculator.gui.expression.containers; import java.io.Serializable; import org.warp.picalculator.gui.GraphicalElement; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockContainer; import org.warp.picalculator.gui.expression.Caret; import org.warp.picalculator.gui.expression.CaretState; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockContainer; import org.warp.picalculator.gui.graphicengine.GraphicEngine; import org.warp.picalculator.gui.graphicengine.Renderer; diff --git a/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java b/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java index 04550bbe..ccc275ee 100644 --- a/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java +++ b/src/org/warp/picalculator/gui/expression/layouts/InputLayout.java @@ -1,6 +1,6 @@ package org.warp.picalculator.gui.expression.layouts; -import org.warp.picalculator.gui.expression.Block; +import org.warp.picalculator.gui.expression.blocks.Block; public interface InputLayout { public Block parseChar(char c); diff --git a/src/org/warp/picalculator/gui/screens/MathInputScreen.java b/src/org/warp/picalculator/gui/screens/MathInputScreen.java index 8a66e0a8..9ce2fdd9 100644 --- a/src/org/warp/picalculator/gui/screens/MathInputScreen.java +++ b/src/org/warp/picalculator/gui/screens/MathInputScreen.java @@ -17,8 +17,8 @@ import org.warp.picalculator.Utils; import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.gui.DisplayManager; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockContainer; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockContainer; import org.warp.picalculator.gui.expression.containers.InputContainer; import org.warp.picalculator.gui.expression.containers.NormalInputContainer; import org.warp.picalculator.gui.expression.containers.NormalOutputContainer; diff --git a/src/org/warp/picalculator/math/parser/MathParser.java b/src/org/warp/picalculator/math/parser/MathParser.java index 4a4c7552..b7d1cc2f 100644 --- a/src/org/warp/picalculator/math/parser/MathParser.java +++ b/src/org/warp/picalculator/math/parser/MathParser.java @@ -6,14 +6,14 @@ import java.util.Arrays; import org.warp.picalculator.Error; import org.warp.picalculator.Errors; -import org.warp.picalculator.gui.expression.Block; -import org.warp.picalculator.gui.expression.BlockChar; -import org.warp.picalculator.gui.expression.BlockContainer; -import org.warp.picalculator.gui.expression.BlockDivision; -import org.warp.picalculator.gui.expression.BlockExponentialNotation; -import org.warp.picalculator.gui.expression.BlockParenthesis; -import org.warp.picalculator.gui.expression.BlockPower; -import org.warp.picalculator.gui.expression.BlockSquareRoot; +import org.warp.picalculator.gui.expression.blocks.Block; +import org.warp.picalculator.gui.expression.blocks.BlockChar; +import org.warp.picalculator.gui.expression.blocks.BlockContainer; +import org.warp.picalculator.gui.expression.blocks.BlockDivision; +import org.warp.picalculator.gui.expression.blocks.BlockExponentialNotation; +import org.warp.picalculator.gui.expression.blocks.BlockParenthesis; +import org.warp.picalculator.gui.expression.blocks.BlockPower; +import org.warp.picalculator.gui.expression.blocks.BlockSquareRoot; import org.warp.picalculator.gui.expression.containers.InputContainer; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.FunctionOperator; From 3efb8f6c26ec4d2cbf1411e55a395991bda24c2a Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Sun, 23 Apr 2017 14:11:37 +0200 Subject: [PATCH 09/10] updated --- res/algebra_input.gif | Bin 0 -> 30765 bytes res/font_ex.rft | Bin 1735 -> 1735 bytes src/org/warp/picalculator/Utils.java | 1 + .../warp/picalculator/device/Keyboard.java | 2 +- .../gui/expression/blocks/Block.java | 2 +- .../blocks/BlockExponentialNotation.java | 22 ++++++++++-- .../gui/expression/blocks/BlockPower.java | 34 ++++-------------- .../gui/graphicengine/gpu/GPUEngine.java | 2 +- .../gui/graphicengine/gpu/NEWTWindow.java | 6 ++-- .../picalculator/gui/screens/MarioScreen.java | 1 + .../picalculator/math/parser/MathParser.java | 25 ++++++------- .../math/parser/features/FeaturePower.java | 8 ++--- 12 files changed, 49 insertions(+), 54 deletions(-) create mode 100644 res/algebra_input.gif diff --git a/res/algebra_input.gif b/res/algebra_input.gif new file mode 100644 index 0000000000000000000000000000000000000000..6aaebdfb84b8aac603bf95660c5c2730077b43da GIT binary patch literal 30765 zcmeHQ2|Seh*MDXVGuG_;GM4OH_EZ{6mYPH*D#?;HiBguf!Pq4`Aq^5*ED@4>Gl-F; zg=|SANp_K~Jnw_*cHj5D_r0I{zxVBSduBc#+h?BV`Tf4X-#OoN&hMPVz(`+Xy-hb_ zBVrZ+?pNgl01y{LjE^C<2YNSOiF@whfIt8M0(wI)1oT?|vijTdU*H#vz`q9pVUXT< z%kEve+9q3+;ipH!L8L12AmTmXw0@>R@Kkt*M5E z8TZ4vm0h|ig_(6hNE8ERz0ws5f@aIL-FtUd)+H+1JxDbwy4sY&f53%dKIRo68g~x4 zRfy3R8_Cp4J3_Cm?~{dup&Xelu+zyU)ZmToLd{|3E{@&1a>q ze#vo3>{1V}Tdcb!wxM9a(9d93o@`1cZO+<=YcN9P<1I?6mlKc#`W=U ztO4!C4Ae-x;+`TOzUx*^?$kSY-=K3jUvto2a0*?NvPr!R_|=L z>>h{P&m}JE>XqMd2*fX-x`Xvud>viXtJV)@M5HCYNWl2;RGOdIq#_P5T3hTUbc6j`!xr~OS-EDqk=Bb6_&6ze!uhE%y>tMO}9fuN+yzg|% zzWKh(wRH6TGxs{V*>2DFBeT!F2XD?U^_-p^oqa(-%g^-^x!mUZLL~C$UPh>o&Gkna z$j`ruGk2RGNOH`Zf1TtCDCnRC?`8_;q8smv4!D+I{C$s;&!*i(Xzq3 z#j%RnvBmL9w8Dpp8m^-sCMgp6AEp}B$3MJ#WT5bIy4C#X$C(bt{EzRuy~aPz_692~ z&Am!Ix-|bLJAY|mq;z~~aiUHE{4m{q6#O_hm=7*}m>mZ}fPn;{4J(nn69f#Ngyf=B z(r8ZjF-MS45{6{DeG~rNjU*a%3Yp1wA^^*fjxjK-VojbPO5)S$%qdlz1-ty1!2gcClKx1Ca}Rz7*&JtC8T(6COk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>GgCSEEdwt{_V#O=LXq~#MN)ghciqX`?YvV`C!D1zh&{JN?AbN9 zy=QM|sEt}iI_2*4Ofr8>Cak12uC!M={*{nI(}(5sZ`uR!ZU5m2tQ6Oxu(-;~03;O( zr%`~d_M;PGRgqjLq8rS?rByTcNJJ-+VUr*#)Wk+ROx!dKFNL#tK$M|MC5Ap8&`wY> zb7{=I<#-D;vGEri! zd91-!?E7OzYKlb~Zf#ohkZ<`^V6fU9@a$I!S^seS;Nigt{Cx=g&m$SAAp}%`^F=`Z rzDL7%h7tJZBk makeFunctions(MathContext context, ObjectArrayList features) throws Error { final ObjectArrayList process = new ObjectArrayList<>(); - + for (final Feature f : features) { if (f instanceof FeatureDivision) { process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); @@ -396,7 +388,12 @@ public class MathParser { } else if (f instanceof FeatureSum) { process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); } else if (f instanceof FeaturePower) { - process.add(new Power(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); + if (process.isEmpty()) { + throw new Error(Errors.SYNTAX_ERROR, "There is a power at the beginning of the expression!"); + } else { + Function prec = process.remove(process.size()-1); + process.add(new Power(context, prec, (Function) ((FeatureSingle) f).getChild())); + } } else if (f instanceof FeatureSquareRoot) { process.add(new RootSquare(context, (Function) ((FeatureSingle) f).getChild())); } else if (f instanceof FeatureParenthesis) { diff --git a/src/org/warp/picalculator/math/parser/features/FeaturePower.java b/src/org/warp/picalculator/math/parser/features/FeaturePower.java index 5de97e33..3eba66fb 100644 --- a/src/org/warp/picalculator/math/parser/features/FeaturePower.java +++ b/src/org/warp/picalculator/math/parser/features/FeaturePower.java @@ -1,11 +1,9 @@ package org.warp.picalculator.math.parser.features; -import org.warp.picalculator.math.parser.features.interfaces.Feature; +public class FeaturePower extends FeatureSingleImpl { -public class FeaturePower extends FeatureDoubleImpl { - - public FeaturePower(Object child1, Object child2) { - super(child1, child2); + public FeaturePower(Object child) { + super(child); } } From 15ea3edf8465b9f0c1a3c01e004e1fcdcff9c2a8 Mon Sep 17 00:00:00 2001 From: XDrake99 Date: Sun, 23 Apr 2017 14:13:57 +0200 Subject: [PATCH 10/10] updated example gif --- res/algebra_input.gif | Bin 30765 -> 6652 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/res/algebra_input.gif b/res/algebra_input.gif index 6aaebdfb84b8aac603bf95660c5c2730077b43da..fd788bb9540167eed7687b5597c7c41b5e7f3577 100644 GIT binary patch literal 6652 zcmeI0XIN87+s8vEgeD-pO0OavLC$0EkPgzp(0h^IBn41@K_Shv(B?@0T~ZPEK-WGUuK-|NA%pnLFyLGP35=IPy3$AP@%t(NxjX zy{)LFA|@h=hXcZ1I>yK6z@CM$2k5j~K}Tyj_G?l?NOD5Rc&O(_+LZd1iOH!iJW*V2QV~NOL?m=_j5-6A z&be<&M_zh*Paj|or$6Lb+w3qRh^T~Q2m^Afq>8;o5y?0#E#Z`$O1?bdcqux+q?m~V zasz|#kifK-ykYQ6H*+i(!nh}47!^`Ea0xAqxE%x{qMSAk)tVFx)1jZub-OcLouZZ~ z@c2?>4x8_;)fF+@hO(N3Yv;s^W4dIVv6zp zrOCkzdF+KUA87Wu(QE|wc(vW!biB7dj5LjrMKpr2xW9%H-|F&^DRbTLev&t@@-pK zz=UenyI>-nd`q;V1GY=i3L_CqG4k2Dmaz(ilOJN0XzjReWw5{t-R49aG~99 zu2jd}9=_M8-Cm*Eue*JsT|#>wCB_~1`eoKodjs-^U-v#K5DD*pR;F{>A5`Nl-5A{$>$JW8PS-3D}!Yb7XGim#}6f@;myM_7kv`hGK+HKtF zaK>}3^l;YqaO-d`fJo$MK7`KsXd!~P>}WAcdi!W8?vBXua?%6m>hz^7YA_e81V+5BVBo^LBaEckw8D{XXCH|XqX)76*_hF3V?Iau zne3khh3#WDGwzzY^DQ2v7d{9>*GF?t^-?mmH84&-D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