Some other updates to the new internal structure
This commit is contained in:
parent
baeb076b07
commit
86438bf618
@ -29,5 +29,10 @@
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/objenesis-2.4/objenesis-2.4-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="libs/fastutil/fastutil-7.1.0.jar" sourcepath="libs/fastutil/fastutil-7.1.0-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/PICalculator/libs/fastutil/fastutil-7.1.0-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> 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<Function> 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<Function> fl) {
|
||||
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereOnlySettedUpFunctionsAndSystems(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereOnlyEmptySNFunctions(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereOnlyEmptyNSNFunctions(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereEmptyMultiplications(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereEmptySums(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereEmptySystems(ObjectArrayList<Function> 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<Function> fl) {
|
||||
public static boolean areThereOtherSettedUpFunctions(ObjectArrayList<Function> 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<Variable> variables, ArrayList<Variable> variables2) {
|
||||
public static boolean equalsVariables(ObjectArrayList<Variable> variables, ObjectArrayList<Variable> 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<ArrayList<Function>> ln) {
|
||||
public static Function[][] joinFunctionsResults(ObjectArrayList<ObjectArrayList<Function>> 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<String> arr = new ArrayList<>();
|
||||
ObjectArrayList<String> arr = new ObjectArrayList<>();
|
||||
arr.add("getFreePhysicalMemorySize");
|
||||
arr.add("getProcessCpuLoad");
|
||||
arr.add("getSystemCpuLoad");
|
||||
|
@ -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<String> arr = new ArrayList<>();
|
||||
// ObjectArrayList<String> 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) {
|
||||
|
47
src/org/warp/picalculator/gui/expression/Block.java
Normal file
47
src/org/warp/picalculator/gui/expression/Block.java
Normal file
@ -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);
|
||||
|
||||
}
|
41
src/org/warp/picalculator/gui/expression/BlockChar.java
Normal file
41
src/org/warp/picalculator/gui/expression/BlockChar.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
193
src/org/warp/picalculator/gui/expression/BlockContainer.java
Normal file
193
src/org/warp/picalculator/gui/expression/BlockContainer.java
Normal file
@ -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<Block> 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<Block> 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 <b>ge</b>.
|
||||
* @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<Block> getContent() {
|
||||
return content.clone();
|
||||
}
|
||||
|
||||
}
|
70
src/org/warp/picalculator/gui/expression/BlockDivision.java
Normal file
70
src/org/warp/picalculator/gui/expression/BlockDivision.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
30
src/org/warp/picalculator/gui/expression/Caret.java
Normal file
30
src/org/warp/picalculator/gui/expression/Caret.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
7
src/org/warp/picalculator/gui/expression/CaretState.java
Normal file
7
src/org/warp/picalculator/gui/expression/CaretState.java
Normal file
@ -0,0 +1,7 @@
|
||||
package org.warp.picalculator.gui.expression;
|
||||
|
||||
public enum CaretState {
|
||||
VISIBLE_ON,
|
||||
VISIBLE_OFF,
|
||||
HIDDEN
|
||||
}
|
@ -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();
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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() };
|
||||
}
|
||||
|
@ -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<Double> mediaValori = new ArrayList<Double>();
|
||||
// private static ObjectArrayList<Double> mediaValori = new ObjectArrayList<Double>();
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Buffer> buffersToDelete = new ArrayList<>();
|
||||
final List<Buffer> 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<String> classnamesToRemove = new ArrayList<>();
|
||||
final List<String> 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<Class<?>> intermediaryClassWithoutBufferList = new ArrayList<>();
|
||||
final List<Class<?>> 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<Buffer> buffers = new ArrayList<>();
|
||||
final List<Buffer> buffers = new ObjectArrayList<>();
|
||||
buffers.add(slicedBigEndianReadOnlyDirectByteBuffer);
|
||||
buffers.add(slicedBigEndianReadWriteDirectByteBuffer);
|
||||
buffers.add(bigEndianReadOnlyDirectCharBuffer);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
@ -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<Block> 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<Block> 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 <code>caretPos - currentElementLength</code>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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<Function> solveExpression(ArrayList<Function> f22) {
|
||||
private ObjectArrayList<Function> solveExpression(ObjectArrayList<Function> f22) {
|
||||
try {
|
||||
try {
|
||||
return calc.solveExpression(f22);
|
||||
@ -550,8 +550,8 @@ public class MathInputScreen extends Screen {
|
||||
try {
|
||||
try {
|
||||
showVariablesDialog();
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
final ArrayList<Function> partialResults = new ArrayList<>();
|
||||
ObjectArrayList<Function> results = new ObjectArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> results = solveExpression(calc.f);
|
||||
final ObjectArrayList<Function> 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<Function> knownVarsInFunctions = getKnownVariables(calc.f.toArray(new Function[calc.f.size()]));
|
||||
final ObjectArrayList<Function> 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<Function> getKnownVariables(Function[] fncs) {
|
||||
final ArrayList<Function> res = new ArrayList<>();
|
||||
private ObjectArrayList<Function> getKnownVariables(Function[] fncs) {
|
||||
final ObjectArrayList<Function> res = new ObjectArrayList<>();
|
||||
for (final Function f : fncs) {
|
||||
if (f instanceof FunctionOperator) {
|
||||
res.addAll(getKnownVariables(new Function[] { ((FunctionOperator) f).getParameter1(), ((FunctionOperator) f).getParameter2() }));
|
||||
|
@ -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<Function> simplify() throws Error {
|
||||
public final ObjectArrayList<Function> 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<Function> result = solved ? solve() : null;
|
||||
ObjectArrayList<Function> result = solved ? solve() : null;
|
||||
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
result = new ObjectArrayList<>();
|
||||
|
||||
final ArrayList<ArrayList<Function>> ln = new ArrayList<>();
|
||||
final ObjectArrayList<ObjectArrayList<Function>> ln = new ObjectArrayList<>();
|
||||
for (int i = 0; i < fncs.length; i++) {
|
||||
ArrayList<Function> l = new ArrayList<>();
|
||||
ObjectArrayList<Function> 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<Function> solve() throws Error;
|
||||
protected abstract ObjectArrayList<Function> solve() throws Error;
|
||||
|
||||
@Override
|
||||
public MathContext getMathContext() {
|
||||
|
@ -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<Function> simplify() throws Error {
|
||||
public final ObjectArrayList<Function> simplify() throws Error {
|
||||
final boolean solved = parameter1.isSimplified() & parameter2.isSimplified();
|
||||
ArrayList<Function> result = solved ? solve() : null;;
|
||||
ObjectArrayList<Function> result = solved ? solve() : null;;
|
||||
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
result = new ObjectArrayList<>();
|
||||
|
||||
final ArrayList<Function> l1 = new ArrayList<>();
|
||||
final ArrayList<Function> l2 = new ArrayList<>();
|
||||
final ObjectArrayList<Function> l1 = new ObjectArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> solve() throws Error;
|
||||
protected abstract ObjectArrayList<Function> solve() throws Error;
|
||||
|
||||
@Override
|
||||
public abstract FunctionOperator clone();
|
||||
|
@ -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.<br>
|
||||
@ -76,14 +76,14 @@ public abstract class FunctionSingle implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ArrayList<Function> simplify() throws Error {
|
||||
public final ObjectArrayList<Function> simplify() throws Error {
|
||||
final boolean simplified = parameter.isSimplified();
|
||||
ArrayList<Function> result = simplified ? solve() : null;
|
||||
ObjectArrayList<Function> result = simplified ? solve() : null;
|
||||
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
result = new ObjectArrayList<>();
|
||||
|
||||
final ArrayList<Function> l1 = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> solve() throws Error;
|
||||
protected abstract ObjectArrayList<Function> solve() throws Error;
|
||||
|
||||
@Override
|
||||
public boolean isSimplified() {
|
||||
|
@ -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<Function> f;
|
||||
public ArrayList<Function> f2;
|
||||
public ArrayList<VariableValue> variablesValues;
|
||||
public ObjectArrayList<Function> f;
|
||||
public ObjectArrayList<Function> f2;
|
||||
public ObjectArrayList<VariableValue> 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<Function> solveExpression(ArrayList<Function> input) throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
final ArrayList<Function> partialResults = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solveExpression(ObjectArrayList<Function> input) throws Error {
|
||||
ObjectArrayList<Function> results = new ObjectArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> fncs = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> f = es.f;
|
||||
ObjectArrayList<Function> f = es.f;
|
||||
if (f instanceof Equation) {
|
||||
List<Function> results = ((Equation)f).solve(letter);
|
||||
Collections.reverse(results);
|
||||
|
@ -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'};
|
||||
}
|
||||
|
@ -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<Equation> solve(Equation equation);
|
||||
public abstract ObjectArrayList<Equation> solve(Equation equation);
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
Function variable1 = getParameter1();
|
||||
Function variable2 = getParameter2();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (FractionsRule1.compare(this)) {
|
||||
result = FractionsRule1.execute(this);
|
||||
} else if (FractionsRule2.compare(this)) {
|
||||
|
@ -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<Function> simplify() throws Error {
|
||||
public ObjectArrayList<Function> simplify() throws Error {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -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<Function> oldFunctionsList = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> solve() throws Error {
|
||||
final ArrayList<Function> ret = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
final ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
@ -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<Function> simplify() throws Error {
|
||||
public ObjectArrayList<Function> simplify() throws Error {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (SyntaxRule1.compare(this)) {
|
||||
result = SyntaxRule1.execute(this);
|
||||
} else if (NumberRule1.compare(this)) {
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
if (variable == null) {
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
if (parameter == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
ObjectArrayList<Function> 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<Function> l1 = new ArrayList<>();
|
||||
if (variable.isSimplified()) {
|
||||
l1.add(variable);
|
||||
final ObjectArrayList<Function> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Function> simplify() throws Error {
|
||||
final List<Function> result = new ArrayList<>();
|
||||
final List<Function> result = new ObjectArrayList<>();
|
||||
if (root.exactMode) {
|
||||
Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces()));
|
||||
Number numb = new Number(root, term.multiply(divisor.term));
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (UndefinedRule1.compare(this)) {
|
||||
result.addAll(UndefinedRule1.execute(this));
|
||||
} else if (ExponentRule1.compare(this)) {
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
final ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
final ObjectArrayList<Function> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
if (parameter1 == null || parameter2 == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (SyntaxRule2.compare(this)) {
|
||||
result = SyntaxRule2.execute(this);
|
||||
} else if (VariableRule1.compare(this)) {
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
if (parameter1 == null || parameter2 == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solveOneStep() throws Error {
|
||||
public List<Function> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> simplify() throws Error {
|
||||
final List<Function> result = new ArrayList<>();
|
||||
final List<Function> result = new ObjectArrayList<>();
|
||||
result.add(this);
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
if (parameter1 == null || parameter2 == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> solve(char variableCharacter) {
|
||||
@SuppressWarnings("unused")
|
||||
final ArrayList<Equation> e;
|
||||
final ObjectArrayList<Equation> 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<Equation> solveStep(char charIncognita) {
|
||||
ArrayList<Equation> result = new ArrayList<>();
|
||||
public ObjectArrayList<Equation> solveStep(char charIncognita) {
|
||||
ObjectArrayList<Equation> result = new ObjectArrayList<>();
|
||||
result.add(clone());
|
||||
for (final SolveMethod t : SolveMethod.techniques) {
|
||||
final ArrayList<Equation> newResults = new ArrayList<>();
|
||||
final ObjectArrayList<Equation> newResults = new ObjectArrayList<>();
|
||||
final int sz = result.size();
|
||||
for (int n = 0; n < sz; n++) {
|
||||
newResults.addAll(t.solve(result.get(n)));
|
||||
|
@ -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<Function> solveOneStep() throws Error {
|
||||
final List<Function> ret = new ArrayList<>();
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
final ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
protected ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
final ArrayList<Function> results = new ArrayList<>();
|
||||
if (variable instanceof Number) {
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
final ObjectArrayList<Function> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Function> solve() throws Error {
|
||||
public ObjectArrayList<Function> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
289
src/org/warp/picalculator/math/parser/InputParser.java
Normal file
289
src/org/warp/picalculator/math/parser/InputParser.java
Normal file
@ -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<Block> blocks = container.getContent();
|
||||
final ObjectArrayList<Feature> 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<Feature> features) throws Error {
|
||||
|
||||
features = fixFeatures(context, features);
|
||||
|
||||
ObjectArrayList<Function> 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<Function> process) throws Error {
|
||||
|
||||
//Phase 1
|
||||
ObjectListIterator<Function> 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<Function> makeFunctions(MathContext context, ObjectArrayList<Feature> features) throws Error {
|
||||
ObjectArrayList<Function> 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<Feature> fixFeatures(final MathContext context, ObjectArrayList<Feature> 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<Feature> convertFunctionChars(MathContext context, ObjectArrayList<Feature> features) throws Error {
|
||||
ObjectArrayList<Feature> 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<Feature> makeNumbers(MathContext context, ObjectArrayList<Feature> features) {
|
||||
ObjectArrayList<Feature> 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<Feature> fixMinuses(final MathContext context, ObjectArrayList<Feature> features) throws Error {
|
||||
ObjectArrayList<Feature> 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.warp.picalculator.math.parser.features.interfaces;
|
||||
|
||||
public abstract interface Feature {
|
||||
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package org.warp.picalculator.math.parser.features.interfaces;
|
||||
|
||||
public interface FeatureBasic extends Feature {
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final MathContext root = f.getMathContext();
|
||||
|
||||
Expression expr = null;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function a = null;
|
||||
|
||||
if (f instanceof Negative) {
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(root, 1));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication fnc = (Multiplication) f;
|
||||
final Function a = fnc.getParameter1();
|
||||
final Expression expr = new Expression(root, a);
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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()))));
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication fnc = (Multiplication) f;
|
||||
final Function a = fnc.getParameter1();
|
||||
final Expression expr = new Expression(root, a);
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(((Power) f).getParameter1());
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 1));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Power fnc = (Power) f;
|
||||
final Expression expr = (Expression) fnc.getParameter1();
|
||||
final Multiplication mult = (Multiplication) expr.getParameter(0);
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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())));
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 0));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Division fnc = (Division) f;
|
||||
Function a;
|
||||
Function b;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Division fnc = (Division) f;
|
||||
Function a;
|
||||
Function b;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication fnc = (Multiplication) f;
|
||||
Function a;
|
||||
Function b;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Division fnc = (Division) f;
|
||||
result.add(fnc.getParameter1());
|
||||
return result;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), 1));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Power fnc = (Power) f;
|
||||
final Function a = ((Division) fnc.getParameter1()).getParameter1();
|
||||
final Function b = ((Division) fnc.getParameter1()).getParameter2();
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Power fnc = (Power) f;
|
||||
final Function a = ((Division) fnc.getParameter1()).getParameter1();
|
||||
final Function b = ((Division) fnc.getParameter1()).getParameter2();
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Number(f.getMathContext(), "0"));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
Function a = null;
|
||||
boolean aFound = false;
|
||||
final Multiplication mult = (Multiplication) f;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (f instanceof SumSubtraction) {
|
||||
final Multiplication mul = new Multiplication(root, new Number(root, 2), f);
|
||||
result.add(mul);
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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()));
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final FunctionOperator fnc = (FunctionOperator) f;
|
||||
Function a = fnc.getParameter1();
|
||||
if (a.equals(new Number(root, 0))) {
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
Function a = null;
|
||||
boolean aFound = false;
|
||||
final Multiplication mult = (Multiplication) f;
|
||||
|
@ -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<Function> execute(Sum f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Sum f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication mult = new Multiplication(root, new Number(root, 2), f.getParameter1());
|
||||
result.add(mult);
|
||||
return result;
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
FunctionOperator mOut = (FunctionOperator) f;
|
||||
final Function a = ((FunctionOperator) mOut.getParameter1()).getParameter1();
|
||||
final Function b = ((FunctionOperator) mOut.getParameter1()).getParameter2();
|
||||
|
@ -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<Function> execute(Sum f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Sum f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Function a = f.getParameter1();
|
||||
Function b, c;
|
||||
if (f.getParameter2() instanceof Sum) {
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(Function f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
}
|
||||
|
@ -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<Function> execute(FunctionOperator fnc) throws Error {
|
||||
public static ObjectArrayList<Function> execute(FunctionOperator fnc) throws Error {
|
||||
final MathContext root = fnc.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication m1 = (Multiplication) fnc.getParameter1();
|
||||
final Multiplication m2 = (Multiplication) fnc.getParameter2();
|
||||
final Function a = m1.getParameter1();
|
||||
|
@ -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<Function> execute(FunctionOperator fnc) throws Error {
|
||||
public static ObjectArrayList<Function> execute(FunctionOperator fnc) throws Error {
|
||||
final MathContext root = fnc.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication m1 = (Multiplication) fnc.getParameter1();
|
||||
final Function a = m1.getParameter1();
|
||||
final Function x = fnc.getParameter2();
|
||||
|
@ -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<Function> execute(FunctionOperator fnc) throws Error {
|
||||
public static ObjectArrayList<Function> execute(FunctionOperator fnc) throws Error {
|
||||
final MathContext root = fnc.getMathContext();
|
||||
final ArrayList<Function> result = new ArrayList<>();
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
final Multiplication m2 = (Multiplication) fnc.getParameter2();
|
||||
final Function a = m2.getParameter1();
|
||||
final Function x = fnc.getParameter1();
|
||||
|
@ -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<Function> execute(Division f) throws Error {
|
||||
public static ObjectArrayList<Function> execute(Division f) throws Error {
|
||||
final MathContext root = f.getMathContext();
|
||||
Function result;
|
||||
final ArrayList<Function> elements = getDivisionElements(f);
|
||||
final ObjectArrayList<Function> 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<Function> results = new ArrayList<>();
|
||||
final ObjectArrayList<Function> results = new ObjectArrayList<>();
|
||||
results.add(result);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ArrayList<Function> getDivisionElements(Division division) {
|
||||
final ArrayList<Function> elementsNumerator = new ArrayList<>();
|
||||
private static ObjectArrayList<Function> getDivisionElements(Division division) {
|
||||
final ObjectArrayList<Function> 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<Function> elementsDenominator = new ArrayList<>();
|
||||
final ObjectArrayList<Function> 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<Function> elements) {
|
||||
private static int[] getFirstWorkingDivisionCouple(ObjectArrayList<Function> elements) {
|
||||
final int size = elements.size();
|
||||
Function a;
|
||||
Function b;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user