Started rewriting math screen and conversion logics
This commit is contained in:
parent
b89883147b
commit
c2df21d682
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry excluding="org/warp/picalculator/deprecatedmath/|org/warp/picalculator/device/PIDisplay.java|org/warp/picalculator/device/graphicengine/Display.java" kind="src" path="src"/>
|
||||
<classpathentry excluding="org/warp/picalculator/deprecatedmath/|org/warp/picalculator/device/PIDisplay.java|org/warp/picalculator/device/graphicengine/Display.java|com/rits/cloning/|com/rits/perspectives/|com/rits/|com/|org/warp/picalculator/TestCalcBenchmark.java" kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="res"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/JOGL"/>
|
||||
|
BIN
res/draft2.png
Normal file
BIN
res/draft2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
@ -116,8 +116,7 @@ public class BMPFile extends Component {
|
||||
final byte rgb[] = new byte[3];
|
||||
size = (biWidth * biHeight) - 1;
|
||||
pad = 4 - ((biWidth * 3) % 4);
|
||||
if (pad == 4)
|
||||
{
|
||||
if (pad == 4) {
|
||||
pad = 0; // <==== Bug correction
|
||||
}
|
||||
rowCount = 1;
|
||||
|
@ -14,6 +14,9 @@ public class Main {
|
||||
public static Main instance;
|
||||
public static boolean haxMode = true;
|
||||
public static String[] args;
|
||||
public static final String calculatorName = "WarpPI";
|
||||
public static final String calculatorNameLOWER = "warppi";
|
||||
public static final String calculatorNameUPPER = "WARPPI";
|
||||
|
||||
public Main(String[] args) throws InterruptedException {
|
||||
this(new LoadingScreen(), args);
|
||||
@ -23,7 +26,7 @@ public class Main {
|
||||
instance = this;
|
||||
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
|
||||
Thread.currentThread().setName("Main thread");
|
||||
this.args = args;
|
||||
Main.args = args;
|
||||
beforeStart();
|
||||
new DisplayManager(screen);
|
||||
Utils.debug.println("Shutdown...");
|
||||
|
@ -7,22 +7,22 @@ public class TestCalcBenchmark {
|
||||
|
||||
public static void main(String[] args) throws Error {
|
||||
Utils.debugOn = true;
|
||||
int times = 1;
|
||||
final int times = 1;
|
||||
|
||||
MathContext mc = new MathContext();
|
||||
long time1 = System.nanoTime();
|
||||
final MathContext mc = new MathContext();
|
||||
final long time1 = System.nanoTime();
|
||||
mc.parseInputString("5WABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHIWABCDEFGHI");
|
||||
long time2 = System.nanoTime();
|
||||
final long time2 = System.nanoTime();
|
||||
for (int i = 0; i < times; i++) {
|
||||
if (i == 1) {
|
||||
Utils.debugOn = false;
|
||||
}
|
||||
mc.f2 = mc.solveExpression(mc.f);
|
||||
}
|
||||
long time3 = System.nanoTime();
|
||||
final long time3 = System.nanoTime();
|
||||
// System.out.println(mc.f2.get(0).toString());
|
||||
System.out.println("PARSING\t"+((time2-time1) / 1000000d / ((double) times)) + " milliseconds");
|
||||
System.out.println("WORK\t"+((time3-time2) / 1000000d / ((double) times)) + " milliseconds");
|
||||
System.out.println("TOTAL\t"+((time3-time1) / 1000000d / ((double) times)) + " milliseconds");
|
||||
System.out.println("PARSING\t" + ((time2 - time1) / 1000000d / (times)) + " milliseconds");
|
||||
System.out.println("WORK\t" + ((time3 - time2) / 1000000d / (times)) + " milliseconds");
|
||||
System.out.println("TOTAL\t" + ((time3 - time1) / 1000000d / (times)) + " milliseconds");
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class TestDrivers {
|
||||
try {
|
||||
Class.forName(className);
|
||||
return true;
|
||||
} catch( ClassNotFoundException e ) {
|
||||
} catch (final ClassNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -8,17 +8,14 @@ import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.KeyboardEventListener;
|
||||
import org.warp.picalculator.gui.GUIErrorMessage;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.containers.NormalInputContainer;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Root;
|
||||
import org.warp.picalculator.math.parser.MathParser;
|
||||
|
||||
public class TestGPU {
|
||||
@ -107,9 +104,9 @@ public class TestGPU {
|
||||
case EQUAL:
|
||||
Expression expr;
|
||||
try {
|
||||
expr = MathParser.parseInput(new MathContext(), c.root);
|
||||
expr = MathParser.parseInput(new MathContext(), c);
|
||||
System.out.println("Parsed input:" + expr.toString());
|
||||
} catch (Error e) {
|
||||
} catch (final Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -131,7 +128,7 @@ public class TestGPU {
|
||||
|
||||
private static class Scene implements RenderingLoop {
|
||||
|
||||
private BinaryFont exampleFont;
|
||||
private final BinaryFont exampleFont;
|
||||
private final Skin exampleSkin;
|
||||
|
||||
private final Renderer r;
|
||||
@ -148,7 +145,6 @@ public class TestGPU {
|
||||
|
||||
BlockContainer.initializeFonts(d.loadFont("ex"), d.loadFont("big"));
|
||||
|
||||
|
||||
//New expression framework test
|
||||
c = new NormalInputContainer(false, 0, 200);
|
||||
c.typeChar(MathematicalSymbols.DIVISION);
|
||||
@ -209,7 +205,7 @@ public class TestGPU {
|
||||
if (lastTime == 0) {
|
||||
lastTime = System.currentTimeMillis();
|
||||
}
|
||||
double delta = System.currentTimeMillis()-lastTime;
|
||||
final double delta = System.currentTimeMillis() - lastTime;
|
||||
lastTime = System.currentTimeMillis();
|
||||
c.beforeRender((float) (delta / 1000d));
|
||||
c.draw(d, r, 10, 220);
|
||||
|
@ -37,8 +37,6 @@ import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.equations.EquationsSystemPart;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final int scale = 24;
|
||||
@ -52,8 +50,6 @@ public class Utils {
|
||||
public static boolean debugOn;
|
||||
public static boolean debugThirdScreen;
|
||||
|
||||
public static Cloner cloner = new Cloner();
|
||||
|
||||
public static final class DebugStream extends StringWriter {
|
||||
|
||||
public void println(String str) {
|
||||
@ -198,7 +194,8 @@ public class Utils {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ObjectArrayList<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) {
|
||||
@ -537,13 +534,12 @@ public class Utils {
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
int[] curs = new int[sizes.length];
|
||||
final int[] curs = new int[sizes.length];
|
||||
int total = 0;
|
||||
for (int i = 0; i < ln.size(); i++) {
|
||||
if (i == 0) {
|
||||
@ -615,27 +611,27 @@ public class Utils {
|
||||
|
||||
public static void printSystemResourcesUsage() {
|
||||
System.out.println("============");
|
||||
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
|
||||
final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
for (final Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
|
||||
method.setAccessible(true);
|
||||
if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
|
||||
Object value;
|
||||
try {
|
||||
value = method.invoke(operatingSystemMXBean);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
value = e;
|
||||
} // try
|
||||
boolean percent = false;
|
||||
boolean mb = false;
|
||||
String displayName = method.getName();
|
||||
String displayValue = value.toString();
|
||||
final String displayName = method.getName();
|
||||
final String displayValue = value.toString();
|
||||
if (displayName.endsWith("CpuLoad")) {
|
||||
percent = true;
|
||||
}
|
||||
if (displayName.endsWith("MemorySize")) {
|
||||
mb = true;
|
||||
}
|
||||
ObjectArrayList<String> arr = new ObjectArrayList<>();
|
||||
final ObjectArrayList<String> arr = new ObjectArrayList<>();
|
||||
arr.add("getFreePhysicalMemorySize");
|
||||
arr.add("getProcessCpuLoad");
|
||||
arr.add("getSystemCpuLoad");
|
||||
@ -644,13 +640,13 @@ public class Utils {
|
||||
if (percent) {
|
||||
try {
|
||||
System.out.println(displayName + " = " + (((int) (Float.parseFloat(displayValue) * 10000f)) / 100f) + "%");
|
||||
}catch(Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
System.out.println(displayName + " = " + displayValue);
|
||||
}
|
||||
} else if (mb) {
|
||||
try {
|
||||
System.out.println(displayName + " = " + (Long.parseLong(displayValue) / 1024L / 1024L) + " MB");
|
||||
}catch(Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
System.out.println(displayName + " = " + displayValue);
|
||||
}
|
||||
} else {
|
||||
@ -665,8 +661,7 @@ public class Utils {
|
||||
public static boolean isRunningOnRaspberry() {
|
||||
if (System.getProperty("os.name").equals("Linux")) {
|
||||
final File file = new File("/etc", "os-release");
|
||||
try (FileInputStream fis = new FileInputStream(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis))) {
|
||||
try (FileInputStream fis = new FileInputStream(file); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis))) {
|
||||
String string;
|
||||
while ((string = bufferedReader.readLine()) != null) {
|
||||
if (string.toLowerCase().contains("raspbian")) {
|
||||
|
88
src/org/warp/picalculator/device/CacheFile.java
Normal file
88
src/org/warp/picalculator/device/CacheFile.java
Normal file
@ -0,0 +1,88 @@
|
||||
package org.warp.picalculator.device;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
|
||||
public class CacheFile {
|
||||
private String path;
|
||||
private ObjectOutputStream lastOOS;
|
||||
private FileOutputStream lastFOS;
|
||||
private ObjectInputStream lastOIS;
|
||||
private FileInputStream lastFIS;
|
||||
|
||||
public CacheFile() {
|
||||
do {
|
||||
path = UUID.randomUUID().toString()+".ser";
|
||||
} while (Files.exists(Paths.get(path)));
|
||||
try {
|
||||
Files.createTempFile(Main.calculatorNameLOWER, "");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectOutputStream getObjectOutputStram() {
|
||||
if (lastOOS == null) {
|
||||
try {
|
||||
return new ObjectOutputStream(new FileOutputStream(path));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return lastOOS;
|
||||
}
|
||||
} else {
|
||||
return lastOOS;
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectInputStream getObjectInputStram() {
|
||||
if (lastOIS == null) {
|
||||
try {
|
||||
return new ObjectInputStream(new FileInputStream(path));
|
||||
} catch (IOException e) {
|
||||
return lastOIS;
|
||||
}
|
||||
} else {
|
||||
return lastOIS;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeStreams() {
|
||||
try {
|
||||
if (lastOOS != null) {
|
||||
lastOOS.close();
|
||||
lastOOS = null;
|
||||
}
|
||||
if (lastFOS != null) {
|
||||
lastFOS.close();
|
||||
lastFOS = null;
|
||||
}
|
||||
if (lastOIS != null) {
|
||||
lastOIS.close();
|
||||
lastOIS = null;
|
||||
}
|
||||
if (lastFIS != null) {
|
||||
lastFIS.close();
|
||||
lastFIS = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
closeStreams();
|
||||
try {
|
||||
Files.deleteIfExists(Paths.get(path));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -703,7 +703,7 @@ public class Keyboard {
|
||||
if (additionalListener != null) {
|
||||
try {
|
||||
done = additionalListener.keyPressed(k);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
new GUIErrorMessage(ex);
|
||||
}
|
||||
}
|
||||
@ -713,7 +713,7 @@ public class Keyboard {
|
||||
boolean scrdone = false;
|
||||
try {
|
||||
scrdone = scr.keyPressed(k);
|
||||
} catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
new GUIErrorMessage(ex);
|
||||
}
|
||||
if (scr != null && scr.initialized && scrdone) {
|
||||
|
@ -33,13 +33,13 @@ public class RAWFont {
|
||||
public void create(String name) {
|
||||
try {
|
||||
loadFont("/font_" + name + ".rft");
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
chars32 = new int[(maxBound - minBound) * charIntCount];
|
||||
for (int charIndex = 0; charIndex < maxBound - minBound; charIndex++) {
|
||||
boolean[] currentChar = rawchars[charIndex];
|
||||
final boolean[] currentChar = rawchars[charIndex];
|
||||
if (currentChar == null) {
|
||||
int currentInt = 0;
|
||||
int currentBit = 0;
|
||||
@ -66,7 +66,7 @@ public class RAWFont {
|
||||
}
|
||||
|
||||
Object obj = new Object();
|
||||
WeakReference<Object> ref = new WeakReference<>(obj);
|
||||
final WeakReference<Object> ref = new WeakReference<>(obj);
|
||||
obj = null;
|
||||
while (ref.get() != null) {
|
||||
System.gc();
|
||||
@ -74,9 +74,9 @@ public class RAWFont {
|
||||
}
|
||||
|
||||
private void loadFont(String string) throws IOException {
|
||||
URL res = Main.instance.getClass().getResource(string);
|
||||
int[] file = Utils.realBytes(Utils.convertStreamToByteArray(res.openStream(), res.getFile().length()));
|
||||
int filelength = file.length;
|
||||
final URL res = Main.instance.getClass().getResource(string);
|
||||
final int[] file = Utils.realBytes(Utils.convertStreamToByteArray(res.openStream(), res.getFile().length()));
|
||||
final int filelength = file.length;
|
||||
if (filelength >= 16) {
|
||||
if (file[0x0] == 114 && file[0x1] == 97 && file[0x2] == 119 && file[0x3] == 0xFF && file[0x8] == 0xFF && file[0xD] == 0xFF) {
|
||||
charW = file[0x4] << 8 | file[0x5];
|
||||
@ -92,8 +92,8 @@ public class RAWFont {
|
||||
int index = 0x12;
|
||||
while (index < filelength) {
|
||||
try {
|
||||
int charIndex = file[index] << 8 | file[index+1];
|
||||
boolean[] rawchar = new boolean[charS];
|
||||
final int charIndex = file[index] << 8 | file[index + 1];
|
||||
final boolean[] rawchar = new boolean[charS];
|
||||
int charbytescount = 0;
|
||||
while (charbytescount * 8 < charS) {
|
||||
charbytescount += 1;
|
||||
@ -110,8 +110,7 @@ public class RAWFont {
|
||||
}
|
||||
rawchars[charIndex - minBound] = rawchar;
|
||||
index += 2 + charbytescount;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println(string);
|
||||
System.exit(-1);
|
||||
@ -127,8 +126,8 @@ public class RAWFont {
|
||||
|
||||
public int[] getCharIndexes(String txt) {
|
||||
final int l = txt.length();
|
||||
int[] indexes = new int[l];
|
||||
char[] chars = txt.toCharArray();
|
||||
final int[] indexes = new int[l];
|
||||
final char[] chars = txt.toCharArray();
|
||||
for (int i = 0; i < l; i++) {
|
||||
indexes[i] = (chars[i] & 0xFFFF) - minBound;
|
||||
}
|
||||
@ -137,12 +136,12 @@ public class RAWFont {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void saveArray(int[] screen, String coutputpng) {
|
||||
BufferedImage bi = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB);
|
||||
final BufferedImage bi = new BufferedImage(300, 200, BufferedImage.TYPE_INT_RGB);
|
||||
final int[] a = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
|
||||
System.arraycopy(screen, 0, a, 0, screen.length);
|
||||
try {
|
||||
ImageIO.write(bi, "PNG", new File(coutputpng));
|
||||
} catch (IOException ex) {
|
||||
} catch (final IOException ex) {
|
||||
Logger.getLogger(RAWFont.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
@ -151,7 +150,6 @@ public class RAWFont {
|
||||
final int screenLength = screen.length;
|
||||
int screenPos = 0;
|
||||
|
||||
|
||||
int currentInt;
|
||||
int currentIntBitPosition;
|
||||
int bitData;
|
||||
@ -165,7 +163,7 @@ public class RAWFont {
|
||||
for (int dx = 0; dx < charW; dx++) {
|
||||
j = x + cpos + dx;
|
||||
if (j > 0 & j < screenSize[0]) {
|
||||
int bit = dx + dy * charW;
|
||||
final int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor(bit) / (intBits));
|
||||
currentIntBitPosition = bit - (currentInt * intBits);
|
||||
bitData = (chars32[charIndex * charIntCount + currentInt] >> currentIntBitPosition) & 1;
|
||||
|
@ -1,10 +1,6 @@
|
||||
package org.warp.picalculator.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
@ -373,7 +369,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
}
|
||||
|
||||
//Working thread
|
||||
Thread workThread = new Thread(() -> {
|
||||
final Thread workThread = new Thread(() -> {
|
||||
try {
|
||||
while (true) {
|
||||
float dt = 0;
|
||||
|
@ -6,25 +6,25 @@ import org.warp.picalculator.Error;
|
||||
|
||||
public class GUIErrorMessage {
|
||||
|
||||
private String err;
|
||||
private long creationTime;
|
||||
private final String err;
|
||||
private final long creationTime;
|
||||
|
||||
public GUIErrorMessage(Error e) {
|
||||
this.err = e.getLocalizedMessage();
|
||||
this.creationTime = System.currentTimeMillis();
|
||||
err = e.getLocalizedMessage();
|
||||
creationTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public GUIErrorMessage(Exception ex) {
|
||||
err = ex.getLocalizedMessage();
|
||||
this.creationTime = System.currentTimeMillis();
|
||||
creationTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void draw(GraphicEngine g, Renderer r, String msg) {
|
||||
int scrW = g.getWidth();
|
||||
int scrH = g.getHeight();
|
||||
int width = 200;
|
||||
int height = 20;
|
||||
int margin = 4;
|
||||
final int scrW = g.getWidth();
|
||||
final int scrH = g.getHeight();
|
||||
final int width = 200;
|
||||
final int height = 20;
|
||||
final int margin = 4;
|
||||
r.glClearSkin();
|
||||
r.glColor(0x00000000);
|
||||
r.glFillRect(scrW - width - margin, scrH - height - margin, width, height, 0, 0, 0, 0);
|
||||
|
@ -1,23 +1,19 @@
|
||||
package org.warp.picalculator.gui;
|
||||
|
||||
public class GraphicUtils {
|
||||
public static final float sin(float rad)
|
||||
{
|
||||
public static final float sin(float rad) {
|
||||
return sin[(int) (rad * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static final float cos(float rad)
|
||||
{
|
||||
public static final float cos(float rad) {
|
||||
return cos[(int) (rad * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static final float sinDeg(float deg)
|
||||
{
|
||||
public static final float sinDeg(float deg) {
|
||||
return sin[(int) (deg * degToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
public static final float cosDeg(float deg)
|
||||
{
|
||||
public static final float cosDeg(float deg) {
|
||||
return cos[(int) (deg * degToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
@ -27,8 +23,7 @@ public class GraphicUtils {
|
||||
private static final float degFull, degToIndex;
|
||||
private static final float[] sin, cos;
|
||||
|
||||
static
|
||||
{
|
||||
static {
|
||||
RAD = (float) Math.PI / 180.0f;
|
||||
DEG = 180.0f / (float) Math.PI;
|
||||
|
||||
@ -44,15 +39,13 @@ public class GraphicUtils {
|
||||
sin = new float[SIN_COUNT];
|
||||
cos = new float[SIN_COUNT];
|
||||
|
||||
for (int i = 0; i < SIN_COUNT; i++)
|
||||
{
|
||||
for (int i = 0; i < SIN_COUNT; i++) {
|
||||
sin[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull);
|
||||
cos[i] = (float) Math.cos((i + 0.5f) / SIN_COUNT * radFull);
|
||||
}
|
||||
|
||||
// Four cardinal directions (credits: Nate)
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
{
|
||||
for (int i = 0; i < 360; i += 90) {
|
||||
sin[(int) (i * degToIndex) & SIN_MASK] = (float) Math.sin(i * Math.PI / 180.0);
|
||||
cos[(int) (i * degToIndex) & SIN_MASK] = (float) Math.cos(i * Math.PI / 180.0);
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ package org.warp.picalculator.gui;
|
||||
public interface GraphicalElement {
|
||||
|
||||
/**
|
||||
* Recompute element's dimension parameters, like <strong>width</strong>, <strong>height</strong>, <strong>line</strong> or <strong>length</strong>.
|
||||
* Recompute element's dimension parameters, like <strong>width</strong>,
|
||||
* <strong>height</strong>, <strong>line</strong> or
|
||||
* <strong>length</strong>.
|
||||
*/
|
||||
public void recomputeDimensions();
|
||||
|
||||
@ -21,7 +23,8 @@ public interface GraphicalElement {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Position of the vertical alignment line of the element, relative to itself.
|
||||
* @return Position of the vertical alignment line of the element, relative
|
||||
* to itself.
|
||||
*/
|
||||
public int getLine();
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.warp.picalculator.gui.expression;
|
||||
import org.warp.picalculator.gui.GraphicalElement;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
public abstract class Block implements GraphicalElement {
|
||||
|
||||
@ -14,9 +13,12 @@ public abstract class Block implements GraphicalElement {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param r Graphic Renderer class.
|
||||
* @param x Position relative to the window.
|
||||
* @param y Position relative to the window.
|
||||
* @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);
|
||||
|
@ -2,8 +2,6 @@ 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 {
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class BlockContainer implements GraphicalElement {
|
||||
this.minWidth = minWidth;
|
||||
this.minHeight = minHeight;
|
||||
this.withBorder = withBorder;
|
||||
for (Block b: content) {
|
||||
for (final Block b : content) {
|
||||
if (b.isSmall() != small) {
|
||||
b.setSmall(small);
|
||||
}
|
||||
@ -63,11 +63,15 @@ public class BlockContainer implements GraphicalElement {
|
||||
}
|
||||
|
||||
public void appendBlock(Block b) {
|
||||
appendBlockUnsafe(b);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public void appendBlockUnsafe(Block b) {
|
||||
if (b.isSmall() != small) {
|
||||
b.setSmall(small);
|
||||
}
|
||||
content.add(b);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public void removeBlock(Block b) {
|
||||
@ -91,11 +95,16 @@ public class BlockContainer implements GraphicalElement {
|
||||
|
||||
/**
|
||||
*
|
||||
* @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.
|
||||
* @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 = 1;
|
||||
@ -114,11 +123,13 @@ public class BlockContainer implements GraphicalElement {
|
||||
r.glDrawLine(x + paddingX + width - 1, y, x + paddingX + width - 1, y + height - 1);
|
||||
r.glDrawLine(x + paddingX, y + height - 1, x + paddingX + width - 1, y + height - 1);
|
||||
} else {
|
||||
for (Block b : content) {
|
||||
for (final Block b : content) {
|
||||
caret.skip(1);
|
||||
b.draw(ge, r, x + paddingX, y + line - b.line, caret);
|
||||
paddingX += b.getWidth();
|
||||
if (caret.getRemaining() == 0) BlockContainer.drawCaret(ge, r, caret, x + paddingX, y+line-b.line, b.height);
|
||||
if (caret.getRemaining() == 0) {
|
||||
BlockContainer.drawCaret(ge, r, caret, x + paddingX, y + line - b.line, b.height);
|
||||
}
|
||||
paddingX += 1;
|
||||
}
|
||||
}
|
||||
@ -129,17 +140,17 @@ public class BlockContainer implements GraphicalElement {
|
||||
boolean added = false;
|
||||
|
||||
if (caret.getRemaining() == 0) {
|
||||
this.addBlock(0, newBlock);
|
||||
addBlock(0, newBlock);
|
||||
added = true;
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
for (Block b : content) {
|
||||
for (final Block b : content) {
|
||||
caret.skip(1);
|
||||
pos++;
|
||||
added = added | b.putBlock(caret, newBlock);
|
||||
if (caret.getRemaining() == 0) {
|
||||
this.addBlock(pos, newBlock);
|
||||
addBlock(pos, newBlock);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
@ -154,13 +165,13 @@ public class BlockContainer implements GraphicalElement {
|
||||
boolean removed = false;
|
||||
|
||||
int pos = 0;
|
||||
for (Block b : content) {
|
||||
for (final Block b : content) {
|
||||
caret.skip(1);
|
||||
pos++;
|
||||
int deltaCaret = caret.getRemaining();
|
||||
final int deltaCaret = caret.getRemaining();
|
||||
removed = removed | b.delBlock(caret);
|
||||
if (caret.getRemaining() == 0 || (removed == false && deltaCaret >= 0 && caret.getRemaining() < 0)) {
|
||||
this.removeAt(pos-1);
|
||||
removeAt(pos - 1);
|
||||
caret.setPosition(caret.getPosition() - deltaCaret);
|
||||
removed = true;
|
||||
}
|
||||
@ -172,7 +183,6 @@ public class BlockContainer implements GraphicalElement {
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
int l = 0; //Line
|
||||
@ -180,7 +190,7 @@ public class BlockContainer implements GraphicalElement {
|
||||
int h2 = 0; //Height under the line. h = h2 + l
|
||||
int h = 0; //Height
|
||||
|
||||
for (Block b : content) {
|
||||
for (final Block b : content) {
|
||||
w += b.getWidth() + 1;
|
||||
final int bl = b.getLine();
|
||||
final int bh = b.getHeight();
|
||||
@ -280,12 +290,14 @@ public class BlockContainer implements GraphicalElement {
|
||||
}
|
||||
|
||||
private static void checkInitialized() {
|
||||
if (!initialized) throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
|
||||
if (!initialized) {
|
||||
throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
|
||||
}
|
||||
}
|
||||
|
||||
public int computeCaretMaxBound() {
|
||||
int maxpos = 0;
|
||||
for (Block b : content) {
|
||||
for (final Block b : content) {
|
||||
maxpos += 1 + b.computeCaretMaxBound();
|
||||
}
|
||||
return maxpos + 1;
|
||||
|
@ -1,11 +1,7 @@
|
||||
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 {
|
||||
|
||||
@ -19,8 +15,8 @@ public class BlockDivision extends Block {
|
||||
private int h1;
|
||||
|
||||
public BlockDivision() {
|
||||
this.containerUp = new BlockContainer(false);
|
||||
this.containerDown = new BlockContainer(false);
|
||||
containerUp = new BlockContainer(false);
|
||||
containerDown = new BlockContainer(false);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
@ -82,8 +78,8 @@ public class BlockDivision extends Block {
|
||||
@Override
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
this.containerUp.setSmall(small);
|
||||
this.containerDown.setSmall(small);
|
||||
containerUp.setSmall(small);
|
||||
containerDown.setSmall(small);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ public class BlockParenthesis extends Block {
|
||||
private final BlockContainer containerNumber;
|
||||
|
||||
public BlockParenthesis() {
|
||||
this.containerNumber = new BlockContainer(false);
|
||||
containerNumber = new BlockContainer(false);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
@ -43,15 +43,15 @@ public class BlockParenthesis extends Block {
|
||||
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
this.width = containerNumber.getWidth()+BlockContainer.getDefaultCharWidth(small)*2;
|
||||
this.height = containerNumber.getHeight();
|
||||
this.line = containerNumber.getLine();
|
||||
width = containerNumber.getWidth() + BlockContainer.getDefaultCharWidth(small) * 2;
|
||||
height = containerNumber.getHeight();
|
||||
line = containerNumber.getLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
this.containerNumber.setSmall(small);
|
||||
containerNumber.setSmall(small);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,7 @@
|
||||
package org.warp.picalculator.gui.expression;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public class BlockSquareRoot extends Block {
|
||||
|
||||
@ -16,7 +12,7 @@ public class BlockSquareRoot extends Block {
|
||||
private int h1;
|
||||
|
||||
public BlockSquareRoot() {
|
||||
this.containerNumber = new BlockContainer(false);
|
||||
containerNumber = new BlockContainer(false);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
@ -72,7 +68,7 @@ public class BlockSquareRoot extends Block {
|
||||
@Override
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
this.containerNumber.setSmall(small);
|
||||
containerNumber.setSmall(small);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class Caret {
|
||||
public Caret(CaretState state, int pos) {
|
||||
this.state = state;
|
||||
this.pos = pos;
|
||||
this.remaining = pos;
|
||||
remaining = pos;
|
||||
}
|
||||
|
||||
public void skip(int i) {
|
||||
@ -29,21 +29,21 @@ public class Caret {
|
||||
}
|
||||
|
||||
public void flipState() {
|
||||
if (this.state == CaretState.VISIBLE_ON) {
|
||||
this.state = CaretState.VISIBLE_OFF;
|
||||
} else if (this.state == CaretState.VISIBLE_OFF) {
|
||||
this.state = CaretState.VISIBLE_ON;
|
||||
if (state == CaretState.VISIBLE_ON) {
|
||||
state = CaretState.VISIBLE_OFF;
|
||||
} else if (state == CaretState.VISIBLE_OFF) {
|
||||
state = CaretState.VISIBLE_ON;
|
||||
}
|
||||
}
|
||||
|
||||
public void turnOn() {
|
||||
if (this.state == CaretState.VISIBLE_OFF) {
|
||||
this.state = CaretState.VISIBLE_ON;
|
||||
if (state == CaretState.VISIBLE_OFF) {
|
||||
state = CaretState.VISIBLE_ON;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPosition(int i) {
|
||||
this.pos = i;
|
||||
pos = i;
|
||||
}
|
||||
|
||||
public void resetRemaining() {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.warp.picalculator.gui.expression;
|
||||
|
||||
public enum CaretState {
|
||||
VISIBLE_ON,
|
||||
VISIBLE_OFF,
|
||||
HIDDEN
|
||||
VISIBLE_ON, VISIBLE_OFF, HIDDEN
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package org.warp.picalculator.gui.expression.containers;
|
||||
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.warp.picalculator.gui.GraphicalElement;
|
||||
import org.warp.picalculator.gui.expression.Block;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
@ -9,12 +12,17 @@ import org.warp.picalculator.gui.expression.layouts.InputLayout;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
||||
public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
public final BlockContainer root;
|
||||
import it.unimi.dsi.fastutil.Arrays;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public abstract class InputContainer implements GraphicalElement, InputLayout, Serializable {
|
||||
private static final long serialVersionUID = 923589369317765667L;
|
||||
private final BlockContainer root;
|
||||
private Caret caret;
|
||||
private static final float CARET_DURATION = 0.5f;
|
||||
private float caretTime;
|
||||
private int maxPosition = 0;
|
||||
private boolean parsed = false;
|
||||
|
||||
public InputContainer() {
|
||||
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
||||
@ -32,7 +40,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
}
|
||||
|
||||
public void typeChar(char c) {
|
||||
Block b = parseChar(c);
|
||||
final Block b = parseChar(c);
|
||||
if (b != null) {
|
||||
caret.resetRemaining();
|
||||
if (root.putBlock(caret, b)) {
|
||||
@ -63,7 +71,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
}
|
||||
|
||||
public void moveLeft() {
|
||||
int curPos = caret.getPosition();
|
||||
final int curPos = caret.getPosition();
|
||||
if (curPos > 0) {
|
||||
caret.setPosition(curPos - 1);
|
||||
}
|
||||
@ -72,7 +80,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
}
|
||||
|
||||
public void moveRight() {
|
||||
int curPos = caret.getPosition();
|
||||
final int curPos = caret.getPosition();
|
||||
if (curPos + 1 < maxPosition) {
|
||||
caret.setPosition(curPos + 1);
|
||||
}
|
||||
@ -102,7 +110,8 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param delta Time, in seconds
|
||||
* @param delta
|
||||
* Time, in seconds
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean beforeRender(float delta) {
|
||||
@ -121,10 +130,14 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 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.
|
||||
*/
|
||||
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
|
||||
caret.resetRemaining();
|
||||
@ -137,4 +150,37 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
maxPosition = root.computeCaretMaxBound();
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return maxPosition <= 1;
|
||||
}
|
||||
|
||||
public int getCaretMaxPosition() {
|
||||
return maxPosition;
|
||||
}
|
||||
|
||||
public void setCaretPosition(int pos) {
|
||||
if (pos > 0 && pos < maxPosition) {
|
||||
caret.setPosition(pos);
|
||||
}
|
||||
caret.turnOn();
|
||||
caretTime = 0;
|
||||
}
|
||||
|
||||
public void setParsed(boolean parsed) {
|
||||
this.parsed = parsed;
|
||||
}
|
||||
|
||||
public boolean isAlreadyParsed() {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>WARNING! DO NOT MODIFY THIS ARRAY!!!</strong>
|
||||
*
|
||||
* @return an arraylist representing the content
|
||||
*/
|
||||
public ObjectArrayList<Block> getContent() {
|
||||
return root.getContent();
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,9 @@ package org.warp.picalculator.gui.expression.containers;
|
||||
|
||||
import org.warp.picalculator.gui.expression.Block;
|
||||
import org.warp.picalculator.gui.expression.BlockChar;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.BlockDivision;
|
||||
import org.warp.picalculator.gui.expression.BlockParenthesis;
|
||||
import org.warp.picalculator.gui.expression.BlockSquareRoot;
|
||||
import org.warp.picalculator.gui.expression.Caret;
|
||||
import org.warp.picalculator.gui.expression.CaretState;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class NormalInputContainer extends InputContainer {
|
||||
|
@ -1,15 +1,19 @@
|
||||
package org.warp.picalculator.gui.expression.containers;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.warp.picalculator.gui.GraphicalElement;
|
||||
import org.warp.picalculator.gui.expression.Block;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.Caret;
|
||||
import org.warp.picalculator.gui.expression.CaretState;
|
||||
import org.warp.picalculator.gui.expression.layouts.InputLayout;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
||||
public abstract class OutputContainer implements GraphicalElement, OutputLayout {
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public abstract class OutputContainer implements GraphicalElement, OutputLayout, Serializable {
|
||||
private static final long serialVersionUID = -5714825964892683571L;
|
||||
public final BlockContainer root;
|
||||
private final Caret caret = new Caret(CaretState.HIDDEN, 0);
|
||||
|
||||
@ -25,6 +29,14 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout
|
||||
root = new BlockContainer(small);
|
||||
}
|
||||
|
||||
public void setContent(ObjectArrayList<Block> blocks) {
|
||||
root.clear();
|
||||
for (Block b : blocks) {
|
||||
root.appendBlockUnsafe(b);
|
||||
}
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
root.recomputeDimensions();
|
||||
@ -47,7 +59,8 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout
|
||||
|
||||
/**
|
||||
*
|
||||
* @param delta Time, in seconds
|
||||
* @param delta
|
||||
* Time, in seconds
|
||||
*/
|
||||
public void beforeRender(double delta) {
|
||||
|
||||
@ -55,10 +68,14 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 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.
|
||||
*/
|
||||
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
|
||||
root.draw(ge, r, x, y, caret);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.warp.picalculator.gui.graphicengine;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
|
||||
public interface Renderer {
|
||||
public void glColor3i(int r, int gg, int b);
|
||||
|
||||
@ -25,7 +23,8 @@ public interface Renderer {
|
||||
|
||||
public void glDrawLine(float x0, float y0, float x1, float y1);
|
||||
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight);
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight);
|
||||
|
||||
public void glFillColor(float x, float y, float width, float height);
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class CPUEngine implements GraphicEngine {
|
||||
@Override
|
||||
public void start(RenderingLoop d) {
|
||||
INSTANCE.setRenderingLoop(d);
|
||||
Thread th = new Thread(() -> {
|
||||
final Thread th = new Thread(() -> {
|
||||
try {
|
||||
double extratime = 0;
|
||||
while (initialized) {
|
||||
@ -464,7 +464,7 @@ public class CPUEngine implements GraphicEngine {
|
||||
do {
|
||||
Thread.sleep(500);
|
||||
} while (initialized);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine.CPURenderer;
|
||||
|
@ -9,7 +9,6 @@ import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
|
||||
import com.jogamp.opengl.GLProfile;
|
||||
import com.jogamp.opengl.egl.EGL;
|
||||
|
||||
public class GPUEngine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
|
||||
|
||||
@ -47,8 +46,8 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
|
||||
|
||||
@Override
|
||||
public void setDisplayMode(int ww, int wh) {
|
||||
this.size[0] = ww;
|
||||
this.size[1] = wh;
|
||||
size[0] = ww;
|
||||
size[1] = wh;
|
||||
wnd.window.setSize(Utils.debugOn ? ww * 2 : ww, Utils.debugOn ? wh * 2 : wh);
|
||||
}
|
||||
|
||||
@ -93,7 +92,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
|
||||
|
||||
@Override
|
||||
public void repaint() {
|
||||
if (d != null & r != null && r.gl != null) {
|
||||
if (d != null & r != null && GPURenderer.gl != null) {
|
||||
d.refresh();
|
||||
}
|
||||
}
|
||||
@ -119,14 +118,14 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
|
||||
do {
|
||||
Thread.sleep(500);
|
||||
} while (initialized | created);
|
||||
} catch (InterruptedException e) {
|
||||
} catch (final InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
boolean available = GLProfile.isAvailable(GLProfile.GL2ES1);
|
||||
final boolean available = GLProfile.isAvailable(GLProfile.GL2ES1);
|
||||
if (!available) {
|
||||
System.err.println(GLProfile.glAvailabilityToString());
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package org.warp.picalculator.gui.graphicengine.gpu;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.warp.picalculator.gui.graphicengine.gpu;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -43,9 +42,9 @@ public class GPURenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
final float red = ((float)r) / 255f;
|
||||
final float gre = ((float)gg) / 255f;
|
||||
final float blu = ((float)b) / 255f;
|
||||
final float red = (r) / 255f;
|
||||
final float gre = (gg) / 255f;
|
||||
final float blu = (b) / 255f;
|
||||
currentColor = new float[] { red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, };
|
||||
}
|
||||
|
||||
@ -75,10 +74,10 @@ public class GPURenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glClearColor(int rgb) {
|
||||
final float alpha = (float)((rgb >> 24) & 0xFF) / 255f;
|
||||
final float red = (float)((rgb >> 16) & 0xFF) / 255f;
|
||||
final float green = (float)((rgb >> 8) & 0xFF) / 255f;
|
||||
final float blue = (float)(rgb & 0xFF) / 255f;
|
||||
final float alpha = ((rgb >> 24) & 0xFF) / 255f;
|
||||
final float red = ((rgb >> 16) & 0xFF) / 255f;
|
||||
final float green = ((rgb >> 8) & 0xFF) / 255f;
|
||||
final float blue = (rgb & 0xFF) / 255f;
|
||||
glClearColor4f(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@ -117,7 +116,8 @@ public class GPURenderer implements Renderer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
enableTexture();
|
||||
uvWidth /= currentTexWidth;
|
||||
uvX /= currentTexWidth;
|
||||
@ -145,7 +145,7 @@ public class GPURenderer implements Renderer {
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String text) {
|
||||
final int txtLen = text.length();
|
||||
int[] txtArray = currentFont.getCharIndexes(text);
|
||||
final int[] txtArray = currentFont.getCharIndexes(text);
|
||||
int tableIndexX;
|
||||
int tableIndexY;
|
||||
for (int currentCharIndex = 0; currentCharIndex < txtLen; currentCharIndex++) {
|
||||
@ -167,9 +167,9 @@ public class GPURenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
int index = currentFont.getCharIndex(ch);
|
||||
int tableIndexX = index % currentFont.memoryWidthOfEachColumn;
|
||||
int tableIndexY = (index - tableIndexX) / currentFont.memoryWidthOfEachColumn;
|
||||
final int index = currentFont.getCharIndex(ch);
|
||||
final int tableIndexX = index % currentFont.memoryWidthOfEachColumn;
|
||||
final int tableIndexY = (index - tableIndexX) / currentFont.memoryWidthOfEachColumn;
|
||||
glFillRect(x, y, currentFont.charW, currentFont.charH, tableIndexX * currentFont.charW, tableIndexY * currentFont.charH, currentFont.charW, currentFont.charH);
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ public class GPURenderer implements Renderer {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ImageIO.write(img, "png", os);
|
||||
final InputStream fis = new ByteArrayInputStream(os.toByteArray());
|
||||
Texture tex = TextureIO.newTexture(fis, false, TextureIO.PNG);
|
||||
final Texture tex = TextureIO.newTexture(fis, false, TextureIO.PNG);
|
||||
tex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
|
||||
tex.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
|
||||
return tex;
|
||||
@ -248,10 +248,10 @@ public class GPURenderer implements Renderer {
|
||||
precTexEnabled = currentTexEnabled;
|
||||
precTex = currentTex;
|
||||
if (currentTexEnabled) {
|
||||
gl.glEnable(GL2ES1.GL_TEXTURE_2D);
|
||||
gl.glEnable(GL.GL_TEXTURE_2D);
|
||||
currentTex.bind(gl);
|
||||
} else {
|
||||
gl.glDisable(GL2ES1.GL_TEXTURE_2D);
|
||||
gl.glDisable(GL.GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
|
||||
import com.jogamp.opengl.GL;
|
||||
import com.jogamp.opengl.GL2ES1;
|
||||
import com.jogamp.opengl.GLException;
|
||||
import com.jogamp.opengl.util.texture.Texture;
|
||||
@ -33,12 +34,12 @@ public class GPUSkin implements Skin {
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
try {
|
||||
BufferedImage i = GPURenderer.openTexture(texturePath);
|
||||
GL2ES1 gl = ((GPURenderer)d.getRenderer()).gl;
|
||||
final BufferedImage i = GPURenderer.openTexture(texturePath);
|
||||
final GL2ES1 gl = GPURenderer.gl;
|
||||
t = GPURenderer.importTexture(i);
|
||||
w = i.getWidth();
|
||||
h = i.getHeight();
|
||||
t.setTexParameteri(gl, GL2ES1.GL_TEXTURE_MAG_FILTER, GL2ES1.GL_NEAREST);
|
||||
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
|
||||
initialized = true;
|
||||
} catch (GLException | IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -33,13 +33,10 @@ import com.jogamp.opengl.GL2ES1;
|
||||
import com.jogamp.opengl.GLAutoDrawable;
|
||||
import com.jogamp.opengl.GLEventListener;
|
||||
import com.jogamp.opengl.GLProfile;
|
||||
import com.jogamp.opengl.fixedfunc.GLLightingFunc;
|
||||
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
|
||||
import com.jogamp.opengl.fixedfunc.GLPointerFunc;
|
||||
import com.jogamp.opengl.GLCapabilities;
|
||||
import com.jogamp.nativewindow.util.DimensionImmutable;
|
||||
import com.jogamp.nativewindow.util.PixelFormat;
|
||||
import com.jogamp.nativewindow.util.PixelRectangle;
|
||||
import com.jogamp.newt.NewtFactory;
|
||||
import com.jogamp.newt.event.KeyEvent;
|
||||
import com.jogamp.newt.event.KeyListener;
|
||||
import com.jogamp.newt.event.WindowEvent;
|
||||
@ -49,16 +46,10 @@ import com.jogamp.newt.opengl.GLWindow;
|
||||
|
||||
import com.jogamp.opengl.util.*;
|
||||
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -277,9 +268,9 @@ class NEWTWindow implements GLEventListener {
|
||||
gl.glEnable(GL.GL_TEXTURE_2D);
|
||||
|
||||
//Transparency
|
||||
gl.glEnable(GL2ES1.GL_BLEND);
|
||||
gl.glBlendFunc(GL2ES1.GL_SRC_ALPHA, GL2ES1.GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl.glShadeModel(GL2ES1.GL_FLAT);
|
||||
gl.glEnable(GL.GL_BLEND);
|
||||
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
|
||||
gl.glShadeModel(GLLightingFunc.GL_FLAT);
|
||||
|
||||
try {
|
||||
renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t;
|
||||
@ -329,7 +320,7 @@ class NEWTWindow implements GLEventListener {
|
||||
public void display(GLAutoDrawable glad) {
|
||||
final GL2ES1 gl = glad.getGL().getGL2ES1();
|
||||
|
||||
renderer.gl = gl;
|
||||
GPURenderer.gl = gl;
|
||||
|
||||
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
|
||||
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
|
||||
@ -341,7 +332,7 @@ class NEWTWindow implements GLEventListener {
|
||||
|
||||
renderer.endDrawCycle();
|
||||
|
||||
renderer.gl = null;
|
||||
GPURenderer.gl = null;
|
||||
|
||||
gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
|
||||
gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
|
||||
|
@ -29,7 +29,7 @@ public class KeyboardDebugScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Renderer renderer = DisplayManager.renderer;
|
||||
final Renderer renderer = DisplayManager.renderer;
|
||||
fonts[2].use(DisplayManager.engine);
|
||||
renderer.glColor4f(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glDrawStringRight(Main.screenSize[0] - 10, 30, "-" + keyevent.toUpperCase() + "-");
|
||||
|
@ -1,8 +1,5 @@
|
||||
package org.warp.picalculator.gui.screens;
|
||||
|
||||
import static org.warp.picalculator.gui.DisplayManager.colore;
|
||||
import static org.warp.picalculator.gui.DisplayManager.fonts;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
|
@ -1,11 +1,7 @@
|
||||
package org.warp.picalculator.gui.screens;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
@ -37,7 +33,7 @@ public class MarioScreen extends Screen {
|
||||
try {
|
||||
skin = DisplayManager.engine.loadSkin("marioskin.png");
|
||||
groundskin = DisplayManager.engine.loadSkin("marioground.png");
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -4,19 +4,20 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.expression.Block;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.containers.InputContainer;
|
||||
import org.warp.picalculator.gui.expression.containers.NormalInputContainer;
|
||||
@ -34,6 +35,8 @@ import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.parser.MathParser;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class MathInputScreen extends Screen {
|
||||
@ -55,7 +58,7 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
try {
|
||||
BlockContainer.initializeFonts(DisplayManager.engine.loadFont("ex"), DisplayManager.engine.loadFont("big"));
|
||||
} catch (IOException e) {
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
@ -88,7 +91,7 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void renderStatusbar() {
|
||||
Renderer renderer = DisplayManager.renderer;
|
||||
final Renderer renderer = DisplayManager.renderer;
|
||||
renderer.glColor3f(1, 1, 1);
|
||||
final int pos = 2;
|
||||
final int spacersNumb = 1;
|
||||
@ -111,7 +114,7 @@ public class MathInputScreen extends Screen {
|
||||
userInput.draw(DisplayManager.engine, DisplayManager.renderer, padding, padding + 20);
|
||||
|
||||
if (!result.root.getContent().isEmpty()) {
|
||||
result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - 2, DisplayManager.engine.getHeight() - 2);
|
||||
result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - result.getWidth() - 2, DisplayManager.engine.getHeight() - result.getHeight() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,6 +130,7 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(Key k) {
|
||||
Utils.debug.println(k.toString());
|
||||
switch (k) {
|
||||
case STEP:
|
||||
// if (newExpression.length() > 0) {
|
||||
@ -160,46 +164,51 @@ public class MathInputScreen extends Screen {
|
||||
// }
|
||||
// return true;
|
||||
case SIMPLIFY:
|
||||
// if (DisplayManager.error != null) {
|
||||
// Utils.debug.println("Resetting after error...");
|
||||
// DisplayManager.error = null;
|
||||
// currentExpression = null;
|
||||
// calc.f = null;
|
||||
// calc.f2 = null;
|
||||
// calc.resultsCount = 0;
|
||||
// return true;
|
||||
// } else {
|
||||
// try {
|
||||
// try {
|
||||
// if (!firstStep) {
|
||||
// step();
|
||||
// } else {
|
||||
// if (newExpression != currentExpression && newExpression.length() > 0) {
|
||||
// changeEquationScreen();
|
||||
// interpreta(true);
|
||||
if (DisplayManager.error != null) {
|
||||
//TODO: make the error management a global API rather than being relegated to this screen.
|
||||
Utils.debug.println("Resetting after error...");
|
||||
DisplayManager.error = null;
|
||||
calc.f = null;
|
||||
calc.f2 = null;
|
||||
calc.resultsCount = 0;
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
try {
|
||||
if (!userInput.isAlreadyParsed() && !userInput.isEmpty()) {
|
||||
Expression expr = MathParser.parseInput(calc, userInput);
|
||||
if (calc.f == null | calc.f2 == null) {
|
||||
calc.f = new ObjectArrayList<>();
|
||||
calc.f2 = new ObjectArrayList<>();
|
||||
} else {
|
||||
calc.f.clear();
|
||||
calc.f2.clear();
|
||||
}
|
||||
calc.f.add(expr);
|
||||
ObjectArrayList<Function> resultExpression = expr.solve();
|
||||
ObjectArrayList<Block> resultBlocks = MathParser.parseOutput(calc, resultExpression);
|
||||
result.setContent(resultBlocks);
|
||||
// showVariablesDialog(() -> {
|
||||
// currentExpression = newExpression;
|
||||
// simplify();
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } catch (final Exception ex) {
|
||||
// if (Utils.debugOn) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// throw new Error(Errors.SYNTAX_ERROR);
|
||||
// }
|
||||
// } catch (final Error e) {
|
||||
// final StringWriter sw = new StringWriter();
|
||||
// final PrintWriter pw = new PrintWriter(sw);
|
||||
// e.printStackTrace(pw);
|
||||
// d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
// DisplayManager.error = e.id.toString();
|
||||
// System.err.println(e.id);
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (final Error e) {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
DisplayManager.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case NUM0:
|
||||
typeChar('0');
|
||||
return true;
|
||||
@ -317,13 +326,13 @@ public class MathInputScreen extends Screen {
|
||||
}
|
||||
return true;
|
||||
case SURD_MODE:
|
||||
// calc.exactMode = !calc.exactMode;
|
||||
// if (calc.exactMode == false) {
|
||||
// calc.f2 = solveExpression(calc.f2);
|
||||
// } else {
|
||||
// currentExpression = "";
|
||||
// Keyboard.keyPressed(Key.SIMPLIFY);
|
||||
// }
|
||||
calc.exactMode = !calc.exactMode;
|
||||
if (calc.exactMode == false) {
|
||||
calc.f2 = solveExpression(calc.f2);
|
||||
} else {
|
||||
result.clear();
|
||||
Keyboard.keyPressed(Key.SIMPLIFY);
|
||||
}
|
||||
return true;
|
||||
case debug1:
|
||||
DisplayManager.INSTANCE.setScreen(new EmptyScreen());
|
||||
@ -436,9 +445,6 @@ public class MathInputScreen extends Screen {
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
calc.f2 = results;
|
||||
for (final Function rf : calc.f2) {
|
||||
rf.recomputeDimensions(null);
|
||||
}
|
||||
}
|
||||
Utils.debug.println(calc.f2.toString());
|
||||
} catch (final Exception ex) {
|
||||
@ -479,9 +485,6 @@ public class MathInputScreen extends Screen {
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
calc.f2 = results;
|
||||
for (final Function rf : calc.f2) {
|
||||
rf.recomputeDimensions(null);
|
||||
}
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
@ -499,20 +502,19 @@ public class MathInputScreen extends Screen {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
private void changeEquationScreen() {
|
||||
if (currentExpression != null && currentExpression.length() > 0) {
|
||||
final MathInputScreen cloned = clone();
|
||||
cloned.caretPos = cloned.currentExpression.length();
|
||||
cloned.newExpression = cloned.currentExpression;
|
||||
cloned.scrollX = fontBig.getStringWidth(cloned.currentExpression);
|
||||
try {
|
||||
cloned.interpreta(true);
|
||||
} catch (final Error e) {}
|
||||
DisplayManager.INSTANCE.replaceScreen(cloned);
|
||||
initialized = false;
|
||||
DisplayManager.INSTANCE.setScreen(this);
|
||||
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
//
|
||||
// if (!userInput.isEmpty()) {
|
||||
// final MathInputScreen cloned = clone();
|
||||
// cloned.userInput.setCaretPosition(cloned.userInput.getCaretMaxPosition()-1);
|
||||
// DisplayManager.INSTANCE.replaceScreen(cloned);
|
||||
// initialized = false;
|
||||
// DisplayManager.INSTANCE.setScreen(this);
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
public void typeChar(char chr) {
|
||||
@ -594,15 +596,17 @@ public class MathInputScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public MathInputScreen clone() {
|
||||
final MathInputScreen es = this;
|
||||
final MathInputScreen es2 = new MathInputScreen();
|
||||
es2.errorLevel = es.errorLevel;
|
||||
es2.mustRefresh = es.mustRefresh;
|
||||
es2.calc = Utils.cloner.deepClone(es.calc);
|
||||
es2.userInput = Utils.cloner.deepClone(es.userInput);
|
||||
es2.result = Utils.cloner.deepClone(es.result);
|
||||
return es2;
|
||||
throw new NotImplementedException();
|
||||
// final MathInputScreen es = this;
|
||||
// final MathInputScreen es2 = new MathInputScreen();
|
||||
// es2.errorLevel = es.errorLevel;
|
||||
// es2.mustRefresh = es.mustRefresh;
|
||||
// es2.calc = Utils.cloner.deepClone(es.calc);
|
||||
// es2.userInput = Utils.cloner.deepClone(es.userInput);
|
||||
// es2.result = Utils.cloner.deepClone(es.result);
|
||||
// return es2;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package org.warp.picalculator.gui.screens;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
|
||||
public class SolveEquationScreen extends Screen {
|
||||
|
||||
|
@ -8,6 +8,7 @@ public interface Function {
|
||||
|
||||
/**
|
||||
* Returns this function and its children in a string form.
|
||||
*
|
||||
* @return This function and its children in a string form.
|
||||
*/
|
||||
@Override
|
||||
@ -18,27 +19,34 @@ public interface Function {
|
||||
|
||||
/**
|
||||
* Deep clone this function.
|
||||
*
|
||||
* @return A clone of this function.
|
||||
*/
|
||||
public Function clone();
|
||||
|
||||
/**
|
||||
* Generic method to change a parameter in a known position.
|
||||
* @param index parameter index.
|
||||
* @param var parameter.
|
||||
*
|
||||
* @param index
|
||||
* parameter index.
|
||||
* @param var
|
||||
* parameter.
|
||||
* @return A new instance of this function.
|
||||
*/
|
||||
public Function setParameter(int index, Function var) throws IndexOutOfBoundsException;
|
||||
|
||||
/**
|
||||
* Generic method to retrieve a parameter in a known position.
|
||||
* @param index parameter index.
|
||||
*
|
||||
* @param index
|
||||
* parameter index.
|
||||
* @return The requested parameter.
|
||||
*/
|
||||
public Function getParameter(int index) throws IndexOutOfBoundsException;
|
||||
|
||||
/**
|
||||
* Retrieve the current Math Context used by this function
|
||||
*
|
||||
* @return Calculator mathContext
|
||||
*/
|
||||
public MathContext getMathContext();
|
||||
@ -50,6 +58,7 @@ public interface Function {
|
||||
|
||||
/**
|
||||
* The current simplification status of this function and it's childrens
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isSimplified();
|
||||
|
@ -7,8 +7,6 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class FunctionDynamic implements Function {
|
||||
public FunctionDynamic(MathContext root) {
|
||||
this.root = root;
|
||||
@ -37,7 +35,7 @@ public abstract class FunctionDynamic implements Function {
|
||||
}
|
||||
|
||||
public FunctionDynamic setParameters(final List<Function> value) {
|
||||
FunctionDynamic f = this.clone();
|
||||
final FunctionDynamic f = clone();
|
||||
final int vsize = value.size();
|
||||
final Function[] tmp = new Function[vsize];
|
||||
for (int i = 0; i < vsize; i++) {
|
||||
@ -48,7 +46,7 @@ public abstract class FunctionDynamic implements Function {
|
||||
}
|
||||
|
||||
public FunctionDynamic setParameters(final Function[] value) {
|
||||
FunctionDynamic f = this.clone();
|
||||
final FunctionDynamic f = clone();
|
||||
f.functions = value;
|
||||
return f;
|
||||
}
|
||||
@ -60,13 +58,13 @@ public abstract class FunctionDynamic implements Function {
|
||||
|
||||
@Override
|
||||
public FunctionDynamic setParameter(int index, Function value) {
|
||||
FunctionDynamic f = this.clone();
|
||||
final FunctionDynamic f = clone();
|
||||
f.functions[index] = value;
|
||||
return f;
|
||||
}
|
||||
|
||||
public FunctionDynamic appendParameter(Function value) {
|
||||
FunctionDynamic f = this.clone();
|
||||
final FunctionDynamic f = clone();
|
||||
f.functions = Arrays.copyOf(f.functions, f.functions.length + 1);
|
||||
f.functions[f.functions.length - 1] = value;
|
||||
return f;
|
||||
@ -74,6 +72,7 @@ public abstract class FunctionDynamic implements Function {
|
||||
|
||||
/**
|
||||
* Retrieve the current number of parameters.
|
||||
*
|
||||
* @return The number of parameters.
|
||||
*/
|
||||
public int getParametersLength() {
|
||||
@ -81,7 +80,7 @@ public abstract class FunctionDynamic implements Function {
|
||||
}
|
||||
|
||||
public FunctionDynamic setParametersLength(int length) {
|
||||
FunctionDynamic f = this.clone();
|
||||
final FunctionDynamic f = clone();
|
||||
f.functions = Arrays.copyOf(functions, length);
|
||||
return f;
|
||||
}
|
||||
@ -97,16 +96,19 @@ public abstract class FunctionDynamic implements Function {
|
||||
}
|
||||
|
||||
/**
|
||||
* The current simplification status of this function, assuming that its children are already simplified.
|
||||
* @return <strong>true</strong> if this function can be solved, otherwise <strong>false</strong>.
|
||||
* The current simplification status of this function, assuming that its
|
||||
* children are already simplified.
|
||||
*
|
||||
* @return <strong>true</strong> if this function can be solved, otherwise
|
||||
* <strong>false</strong>.
|
||||
*/
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
@Override
|
||||
public final ObjectArrayList<Function> simplify() throws Error {
|
||||
boolean solved = true;
|
||||
Function[] fncs = getParameters();
|
||||
for (Function f : fncs) {
|
||||
final Function[] fncs = getParameters();
|
||||
for (final Function f : fncs) {
|
||||
if (f.isSimplified() == false) {
|
||||
solved = false;
|
||||
break;
|
||||
@ -118,12 +120,12 @@ public abstract class FunctionDynamic implements Function {
|
||||
result = new ObjectArrayList<>();
|
||||
|
||||
final ObjectArrayList<ObjectArrayList<Function>> ln = new ObjectArrayList<>();
|
||||
for (int i = 0; i < fncs.length; i++) {
|
||||
ObjectArrayList<Function> l = new ObjectArrayList<>();
|
||||
if (fncs[i].isSimplified()) {
|
||||
l.add(fncs[i]);
|
||||
for (final Function fnc : fncs) {
|
||||
final ObjectArrayList<Function> l = new ObjectArrayList<>();
|
||||
if (fnc.isSimplified()) {
|
||||
l.add(fnc);
|
||||
} else {
|
||||
l.addAll(fncs[i].simplify());
|
||||
l.addAll(fnc.simplify());
|
||||
}
|
||||
ln.add(l);
|
||||
}
|
||||
@ -139,9 +141,12 @@ public abstract class FunctionDynamic implements Function {
|
||||
}
|
||||
|
||||
/**
|
||||
* Solves only this function, assuming that its children are already simplified and it can be solved.
|
||||
* Solves only this function, assuming that its children are already
|
||||
* simplified and it can be solved.
|
||||
*
|
||||
* @return The solved function.
|
||||
* @throws Error Errors during computation, like a/0 or similar.
|
||||
* @throws Error
|
||||
* Errors during computation, like a/0 or similar.
|
||||
*/
|
||||
protected abstract ObjectArrayList<Function> solve() throws Error;
|
||||
|
||||
|
@ -8,24 +8,32 @@ import org.warp.picalculator.Utils;
|
||||
public abstract class FunctionOperator implements Function {
|
||||
|
||||
/**
|
||||
* Create a new instance of FunctionOperator. The Math Context will be the same of <strong>value1</strong>'s.
|
||||
* @throws NullPointerException when value1 is null.
|
||||
* @param value1 The parameter of this function.
|
||||
* @param value2 The parameter of this function.
|
||||
* Create a new instance of FunctionOperator. The Math Context will be the
|
||||
* same of <strong>value1</strong>'s.
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* when value1 is null.
|
||||
* @param value1
|
||||
* The parameter of this function.
|
||||
* @param value2
|
||||
* The parameter of this function.
|
||||
*/
|
||||
public FunctionOperator(Function value1, Function value2) throws NullPointerException {
|
||||
this.mathContext = value1.getMathContext();
|
||||
mathContext = value1.getMathContext();
|
||||
parameter1 = value1;
|
||||
parameter2 = value2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of FunctionOperator.
|
||||
* @param value1 The parameter of this function.
|
||||
* @param value2 The parameter of this function.
|
||||
*
|
||||
* @param value1
|
||||
* The parameter of this function.
|
||||
* @param value2
|
||||
* The parameter of this function.
|
||||
*/
|
||||
public FunctionOperator(MathContext mc, Function value1, Function value2) {
|
||||
this.mathContext = mc;
|
||||
mathContext = mc;
|
||||
parameter1 = value1;
|
||||
parameter2 = value2;
|
||||
}
|
||||
@ -53,22 +61,24 @@ public abstract class FunctionOperator implements Function {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param var First parameter.
|
||||
* @param var
|
||||
* First parameter.
|
||||
* @return A new instance of this function.
|
||||
*/
|
||||
public FunctionOperator setParameter1(Function var) {
|
||||
FunctionOperator s = this.clone();
|
||||
final FunctionOperator s = clone();
|
||||
s.parameter1 = var;
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param var Second parameter.
|
||||
* @param var
|
||||
* Second parameter.
|
||||
* @return A new instance of this function.
|
||||
*/
|
||||
public FunctionOperator setParameter2(Function var) {
|
||||
FunctionOperator s = this.clone();
|
||||
final FunctionOperator s = clone();
|
||||
s.parameter2 = var;
|
||||
return s;
|
||||
}
|
||||
@ -77,9 +87,9 @@ public abstract class FunctionOperator implements Function {
|
||||
public FunctionOperator setParameter(int index, Function var) throws IndexOutOfBoundsException {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.setParameter1(var);
|
||||
return setParameter1(var);
|
||||
case 1:
|
||||
return this.setParameter2(var);
|
||||
return setParameter2(var);
|
||||
default:
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
@ -89,9 +99,9 @@ public abstract class FunctionOperator implements Function {
|
||||
public Function getParameter(int index) throws IndexOutOfBoundsException {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return this.getParameter1();
|
||||
return getParameter1();
|
||||
case 1:
|
||||
return this.getParameter2();
|
||||
return getParameter2();
|
||||
default:
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
@ -108,8 +118,11 @@ public abstract class FunctionOperator implements Function {
|
||||
}
|
||||
|
||||
/**
|
||||
* The current simplification status of this function, assuming that its children are already simplified.
|
||||
* @return <strong>true</strong> if this function can be solved, otherwise <strong>false</strong>.
|
||||
* The current simplification status of this function, assuming that its
|
||||
* children are already simplified.
|
||||
*
|
||||
* @return <strong>true</strong> if this function can be solved, otherwise
|
||||
* <strong>false</strong>.
|
||||
*/
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
@ -137,7 +150,7 @@ public abstract class FunctionOperator implements Function {
|
||||
final Function[][] results = Utils.joinFunctionsResults(l1, l2);
|
||||
|
||||
for (final Function[] f : results) {
|
||||
result.add(this.setParameter1(f[0]).setParameter2(f[1]));
|
||||
result.add(setParameter1(f[0]).setParameter2(f[1]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,9 +158,12 @@ public abstract class FunctionOperator implements Function {
|
||||
}
|
||||
|
||||
/**
|
||||
* Solves only this function, assuming that its children are already simplified and it can be solved.
|
||||
* Solves only this function, assuming that its children are already
|
||||
* simplified and it can be solved.
|
||||
*
|
||||
* @return The solved function.
|
||||
* @throws Error Errors during computation, like a/0 or similar.
|
||||
* @throws Error
|
||||
* Errors during computation, like a/0 or similar.
|
||||
*/
|
||||
protected abstract ObjectArrayList<Function> solve() throws Error;
|
||||
|
||||
|
@ -7,9 +7,13 @@ import org.warp.picalculator.Error;
|
||||
public abstract class FunctionSingle implements Function {
|
||||
|
||||
/**
|
||||
* Create a new instance of FunctionSingle. The Math Context will be the same of <strong>value</strong>'s.
|
||||
* @throws NullPointerException when value is null.
|
||||
* @param value The parameter of this function.
|
||||
* Create a new instance of FunctionSingle. The Math Context will be the
|
||||
* same of <strong>value</strong>'s.
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* when value is null.
|
||||
* @param value
|
||||
* The parameter of this function.
|
||||
*/
|
||||
public FunctionSingle(Function value) throws NullPointerException {
|
||||
mathContext = value.getMathContext();
|
||||
@ -18,8 +22,11 @@ public abstract class FunctionSingle implements Function {
|
||||
|
||||
/**
|
||||
* Create a new instance of FunctionSingle.
|
||||
* @param mathContext Math Context
|
||||
* @param value The parameter of this function.
|
||||
*
|
||||
* @param mathContext
|
||||
* Math Context
|
||||
* @param value
|
||||
* The parameter of this function.
|
||||
*/
|
||||
public FunctionSingle(MathContext mathContext, Function value) {
|
||||
this.mathContext = mathContext;
|
||||
@ -41,13 +48,15 @@ public abstract class FunctionSingle implements Function {
|
||||
public Function getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param var Parameter.
|
||||
* @param var
|
||||
* Parameter.
|
||||
* @return A new instance of this function.
|
||||
*/
|
||||
public FunctionSingle setParameter(Function value) {
|
||||
FunctionSingle s = this.clone();
|
||||
final FunctionSingle s = clone();
|
||||
s.parameter = value;
|
||||
return s;
|
||||
}
|
||||
@ -98,11 +107,13 @@ public abstract class FunctionSingle implements Function {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Solves only this function, assuming that its children are already simplified and it can be solved.
|
||||
* Solves only this function, assuming that its children are already
|
||||
* simplified and it can be solved.
|
||||
*
|
||||
* @return The solved function.
|
||||
* @throws Error Errors during computation, like a/0 or similar.
|
||||
* @throws Error
|
||||
* Errors during computation, like a/0 or similar.
|
||||
*/
|
||||
protected abstract ObjectArrayList<Function> solve() throws Error;
|
||||
|
||||
@ -112,8 +123,11 @@ public abstract class FunctionSingle implements Function {
|
||||
}
|
||||
|
||||
/**
|
||||
* The current simplification status of this function, assuming that its children are already simplified.
|
||||
* @return <strong>true</strong> if this function can be solved, otherwise <strong>false</strong>.
|
||||
* The current simplification status of this function, assuming that its
|
||||
* children are already simplified.
|
||||
*
|
||||
* @return <strong>true</strong> if this function can be solved, otherwise
|
||||
* <strong>false</strong>.
|
||||
*/
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
|
@ -12,7 +12,7 @@ import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.equations.EquationsSystem;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class MathContext {
|
||||
|
||||
@ -122,4 +122,17 @@ public class MathContext {
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public MathContext clone() {
|
||||
// MathContext mc = new MathContext();
|
||||
// mc.angleMode = this.angleMode;
|
||||
// mc.exactMode = this.exactMode;
|
||||
// mc.f = this.f;
|
||||
// mc.f2 = this.f2;
|
||||
// mc.variablesValues = this.variablesValues;
|
||||
// mc.resultsCount = this.resultsCount;
|
||||
// return mc;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ public class MathematicalSymbols {
|
||||
public static final char ARC_TANGENT = 'Ⓗ';
|
||||
public static final char PI = 'π';
|
||||
|
||||
|
||||
public static final char[] functionsNSN = new char[] { NTH_ROOT, POWER };
|
||||
|
||||
public static final char[] functionsSN = new char[] { SQUARE_ROOT, POWER_OF_TWO, MINUS, SINE, COSINE, TANGENT, ARC_SINE, ARC_COSINE, ARC_TANGENT };
|
||||
|
@ -3,14 +3,9 @@ package org.warp.picalculator.math.functions;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.GraphicalElement;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.FractionsRule1;
|
||||
import org.warp.picalculator.math.rules.FractionsRule11;
|
||||
import org.warp.picalculator.math.rules.FractionsRule12;
|
||||
@ -26,8 +21,8 @@ public class Division extends FunctionOperator {
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
Function variable1 = getParameter1();
|
||||
Function variable2 = getParameter2();
|
||||
final Function variable1 = getParameter1();
|
||||
final Function variable2 = getParameter2();
|
||||
if (FractionsRule1.compare(this)) {
|
||||
return true;
|
||||
}
|
||||
@ -50,7 +45,7 @@ public class Division extends FunctionOperator {
|
||||
if (getMathContext().exactMode) {
|
||||
try {
|
||||
return ((Number) variable1).divide((Number) variable2).isInteger();
|
||||
} catch (Error e) {
|
||||
} catch (final Error e) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@ -62,8 +57,8 @@ public class Division extends FunctionOperator {
|
||||
|
||||
@Override
|
||||
public ObjectArrayList<Function> solve() throws Error {
|
||||
Function variable1 = getParameter1();
|
||||
Function variable2 = getParameter2();
|
||||
final Function variable1 = getParameter1();
|
||||
final Function variable2 = getParameter2();
|
||||
ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
if (FractionsRule1.compare(this)) {
|
||||
result = FractionsRule1.execute(this);
|
||||
@ -94,11 +89,11 @@ public class Division extends FunctionOperator {
|
||||
|
||||
@Override
|
||||
public FunctionOperator clone() {
|
||||
return new Division(this.getMathContext(), this.getParameter1(), this.getParameter2());
|
||||
return new Division(getMathContext(), getParameter1(), getParameter2());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "("+this.getParameter1()+")/("+this.getParameter2()+")";
|
||||
return "(" + getParameter1() + ")/(" + getParameter2() + ")";
|
||||
}
|
||||
}
|
@ -1,12 +1,7 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
||||
@ -18,7 +13,6 @@ public class EmptyNumber implements Function {
|
||||
|
||||
private final MathContext root;
|
||||
|
||||
|
||||
@Override
|
||||
public ObjectArrayList<Function> simplify() throws Error {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -12,7 +12,6 @@ import java.util.regex.Pattern;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionDynamic;
|
||||
@ -628,7 +627,7 @@ public class Expression extends FunctionDynamic {
|
||||
public String toString() {
|
||||
String s = "(";
|
||||
if (functions.length > 0) {
|
||||
for (Function f : functions) {
|
||||
for (final Function f : functions) {
|
||||
if (f == null) {
|
||||
s += "[null],";
|
||||
} else {
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
||||
|
@ -5,9 +5,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule15;
|
||||
import org.warp.picalculator.math.rules.ExponentRule16;
|
||||
import org.warp.picalculator.math.rules.FractionsRule14;
|
||||
@ -29,8 +27,8 @@ public class Multiplication extends FunctionOperator {
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
Function variable1 = getParameter1();
|
||||
Function variable2 = getParameter2();
|
||||
final Function variable1 = getParameter1();
|
||||
final Function variable2 = getParameter2();
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
|
@ -4,13 +4,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
|
||||
|
@ -7,16 +7,11 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.BigDecimalMath;
|
||||
import org.nevec.rjm.BigIntegerMath;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Number implements Function {
|
||||
|
||||
private final MathContext root;
|
||||
@ -123,9 +118,9 @@ public class Number implements Function {
|
||||
public List<Function> simplify() throws Error {
|
||||
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));
|
||||
Division div = new Division(root, numb, divisor);
|
||||
final Number divisor = new Number(root, BigInteger.TEN.pow(getNumberOfDecimalPlaces()));
|
||||
final Number numb = new Number(root, term.multiply(divisor.term));
|
||||
final Division div = new Division(root, numb, divisor);
|
||||
result.add(div);
|
||||
} else {
|
||||
result.add(this);
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule1;
|
||||
import org.warp.picalculator.math.rules.ExponentRule2;
|
||||
import org.warp.picalculator.math.rules.ExponentRule3;
|
||||
|
@ -5,11 +5,9 @@ import java.math.BigInteger;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class Root extends FunctionOperator {
|
||||
|
||||
|
@ -4,11 +4,9 @@ import java.math.BigInteger;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class RootSquare extends FunctionSingle {
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
|
@ -5,12 +5,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule5;
|
||||
import org.warp.picalculator.math.rules.NumberRule7;
|
||||
|
@ -4,13 +4,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule4;
|
||||
|
@ -3,9 +3,6 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
||||
|
@ -4,13 +4,9 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Variable implements Function {
|
||||
|
||||
protected char var;
|
||||
@ -94,9 +90,7 @@ public class Variable implements Function {
|
||||
}
|
||||
|
||||
public static enum V_TYPE {
|
||||
KNOWN,
|
||||
UNKNOWN,
|
||||
SOLUTION
|
||||
KNOWN, UNKNOWN, SOLUTION
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,13 +11,10 @@ import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.SolveMethod;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Equation extends FunctionOperator {
|
||||
|
||||
public Equation(MathContext root, Function value1, Function value2) {
|
||||
@ -81,8 +78,7 @@ public class Equation extends FunctionOperator {
|
||||
|
||||
@Override
|
||||
public Equation clone() {
|
||||
final Cloner cloner = new Cloner();
|
||||
return cloner.deepClone(this);
|
||||
return new Equation(mathContext, parameter1, parameter2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,7 +4,6 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionDynamic;
|
||||
|
@ -1,14 +1,10 @@
|
||||
package org.warp.picalculator.math.functions.equations;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class EquationsSystemPart extends FunctionSingle {
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class ArcCosine extends FunctionSingle {
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class ArcSine extends FunctionSingle {
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class ArcTangent extends FunctionSingle {
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class Cosine extends FunctionSingle {
|
||||
|
||||
|
@ -8,7 +8,6 @@ import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class Sine extends FunctionSingle {
|
||||
|
@ -6,7 +6,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class Tangent extends FunctionSingle {
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
package org.warp.picalculator.math.parser;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.gui.expression.Block;
|
||||
import org.warp.picalculator.gui.expression.BlockChar;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.BlockDivision;
|
||||
import org.warp.picalculator.gui.expression.containers.InputContainer;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
@ -15,6 +20,8 @@ import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Variable.V_TYPE;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
@ -23,6 +30,7 @@ import org.warp.picalculator.math.parser.features.FeatureDivision;
|
||||
import org.warp.picalculator.math.parser.features.FeatureMultiplication;
|
||||
import org.warp.picalculator.math.parser.features.FeatureNumber;
|
||||
import org.warp.picalculator.math.parser.features.FeatureSum;
|
||||
import org.warp.picalculator.math.parser.features.FeatureVariable;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble;
|
||||
|
||||
@ -30,27 +38,67 @@ import com.sun.org.apache.xpath.internal.functions.Function2Args;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class MathParser {
|
||||
public static Expression parseInput(MathContext context, BlockContainer root) throws Error {
|
||||
public static Expression parseInput(MathContext context, InputContainer c) throws Error {
|
||||
Expression result;
|
||||
|
||||
Function resultFunction = parseContainer(context, root);
|
||||
final Function resultFunction = parseContainer(context, c.getContent());
|
||||
|
||||
result = new Expression(context, resultFunction);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Function parseContainer(final MathContext context, final BlockContainer container) throws Error {
|
||||
final ObjectArrayList<Block> blocks = container.getContent();
|
||||
public static ObjectArrayList<Block> parseOutput(MathContext context, ObjectArrayList<Function> expr) {
|
||||
final ObjectArrayList<Block> resultBlocks = new ObjectArrayList<>();
|
||||
|
||||
for (Function f : expr) {
|
||||
resultBlocks.addAll(parseFunction(context, f));
|
||||
}
|
||||
|
||||
return resultBlocks;
|
||||
}
|
||||
|
||||
private static ObjectArrayList<Block> parseFunction(MathContext context, Function func) {
|
||||
ObjectArrayList<Block> result = new ObjectArrayList<>();
|
||||
if (func instanceof FunctionOperator) {
|
||||
ObjectArrayList<Block> sub1 = parseFunction(context, func.getParameter(0));
|
||||
ObjectArrayList<Block> sub2 = parseFunction(context, func.getParameter(1));
|
||||
if (func instanceof Sum) {
|
||||
result.addAll(sub1);
|
||||
result.add(new BlockChar(MathematicalSymbols.SUM));
|
||||
result.addAll(sub2);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (func instanceof Number) {
|
||||
Number numb = (Number) func;
|
||||
BigDecimal decimal = numb.getTerm();
|
||||
String numberString;
|
||||
if (numb.isInteger()) {
|
||||
BigInteger integ = decimal.toBigInteger();
|
||||
numberString = integ.toString();
|
||||
} else {
|
||||
numberString = decimal.toPlainString();
|
||||
}
|
||||
for (char c : numberString.toCharArray()) {
|
||||
result.add(new BlockChar(c));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
throw new UnsupportedOperationException("Unknown function " + func.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
private static Function parseContainer(final MathContext context, final Iterable<Block> blocks) throws Error {
|
||||
final ObjectArrayList<Feature> blockFeatures = new ObjectArrayList<>();
|
||||
|
||||
for (final Block block : blocks) {
|
||||
Feature blockFeature = parseBlock(context, block);
|
||||
final Feature blockFeature = parseBlock(context, block);
|
||||
blockFeatures.add(blockFeature);
|
||||
}
|
||||
|
||||
Function result = joinFeatures(context, blockFeatures);
|
||||
final Function result = joinFeatures(context, blockFeatures);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -58,15 +106,15 @@ public class MathParser {
|
||||
|
||||
Feature result;
|
||||
|
||||
int blockType = block.getClassID();
|
||||
final int blockType = block.getClassID();
|
||||
switch (blockType) {
|
||||
case BlockChar.CLASS_ID:
|
||||
result = new FeatureChar(((BlockChar) block).getChar());
|
||||
break;
|
||||
case BlockDivision.CLASS_ID:
|
||||
BlockDivision bd = (BlockDivision) block;
|
||||
Function upper = parseContainer(context, bd.getUpperContainer());
|
||||
Function lower = parseContainer(context, bd.getLowerContainer());
|
||||
final BlockDivision bd = (BlockDivision) block;
|
||||
final Function upper = parseContainer(context, bd.getUpperContainer().getContent());
|
||||
final Function lower = parseContainer(context, bd.getLowerContainer().getContent());
|
||||
result = new FeatureDivision(upper, lower);
|
||||
break;
|
||||
default:
|
||||
@ -80,7 +128,7 @@ public class MathParser {
|
||||
|
||||
features = fixFeatures(context, features);
|
||||
|
||||
ObjectArrayList<Function> process = makeFunctions(context, features);
|
||||
final ObjectArrayList<Function> process = makeFunctions(context, features);
|
||||
|
||||
fixStack(context, process);
|
||||
|
||||
@ -97,7 +145,7 @@ public class MathParser {
|
||||
ObjectListIterator<Function> stackIterator = process.listIterator(process.size());
|
||||
Function lastElement = null;
|
||||
while (stackIterator.hasPrevious()) {
|
||||
Function f = stackIterator.previous();
|
||||
final Function f = stackIterator.previous();
|
||||
|
||||
if (f instanceof FunctionSingle) {
|
||||
if (((FunctionSingle) f).getParameter() == null) {
|
||||
@ -115,17 +163,14 @@ public class MathParser {
|
||||
//Phase 2
|
||||
stackIterator = process.listIterator();
|
||||
while (stackIterator.hasNext()) {
|
||||
Function f = stackIterator.next();
|
||||
final Function f = stackIterator.next();
|
||||
final int curIndex = stackIterator.previousIndex();
|
||||
|
||||
if (f instanceof Multiplication || f instanceof Division) {
|
||||
if (curIndex - 1 >= 0 && stackIterator.hasNext()) {
|
||||
Function next = process.get(curIndex+1);
|
||||
Function prev = process.get(curIndex-1);
|
||||
stackIterator.set(
|
||||
f.setParameter(0, prev)
|
||||
.setParameter(1, next)
|
||||
);
|
||||
final Function next = process.get(curIndex + 1);
|
||||
final Function prev = process.get(curIndex - 1);
|
||||
stackIterator.set(f.setParameter(0, prev).setParameter(1, next));
|
||||
process.remove(curIndex + 1);
|
||||
process.remove(curIndex - 1);
|
||||
} else {
|
||||
@ -139,17 +184,28 @@ public class MathParser {
|
||||
//Phase 3
|
||||
stackIterator = process.listIterator();
|
||||
while (stackIterator.hasNext()) {
|
||||
Function f = stackIterator.next();
|
||||
final Function f = stackIterator.next();
|
||||
final int curIndex = stackIterator.previousIndex();
|
||||
|
||||
if (f instanceof Sum || f instanceof Subtraction || f instanceof SumSubtraction) {
|
||||
|
||||
if (curIndex - 1 >= 0 && stackIterator.hasNext()) {
|
||||
final Function next = process.get(curIndex + 1);
|
||||
final Function prev = process.get(curIndex - 1);
|
||||
stackIterator.set(f.setParameter(0, prev).setParameter(1, next));
|
||||
process.remove(curIndex + 1);
|
||||
process.remove(curIndex - 1);
|
||||
} else {
|
||||
if (f.getParameter(0) == null || f.getParameter(1) == null) {
|
||||
throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Phase 4
|
||||
stackIterator = process.iterator();
|
||||
while (stackIterator.hasNext()) {
|
||||
Function f = stackIterator.next();
|
||||
final Function f = stackIterator.next();
|
||||
|
||||
if (f instanceof Function2Args) {
|
||||
|
||||
@ -157,27 +213,37 @@ public class MathParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static ObjectArrayList<Function> makeFunctions(MathContext context, ObjectArrayList<Feature> features) throws Error {
|
||||
ObjectArrayList<Function> process = new ObjectArrayList<>();
|
||||
private static ObjectArrayList<Function> makeFunctions(MathContext context, ObjectArrayList<Feature> features)
|
||||
throws Error {
|
||||
final ObjectArrayList<Function> process = new ObjectArrayList<>();
|
||||
|
||||
for (Feature f : features) {
|
||||
for (final Feature f : features) {
|
||||
if (f instanceof FeatureDivision) {
|
||||
process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
|
||||
} else if (f instanceof FeatureMultiplication) {
|
||||
process.add(new Multiplication(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
|
||||
} else if (f instanceof FeatureVariable) {
|
||||
process.add(new Variable(context, ((FeatureVariable) f).ch, ((FeatureVariable) f).varType));
|
||||
} else if (f instanceof FeatureSum) {
|
||||
process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
|
||||
// } else if (f instanceof FeatureSubtraction) {
|
||||
// process.add(new Subtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
|
||||
// } else if (f instanceof FeatureSumSubtraction) {
|
||||
// process.add(new SumSubtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
|
||||
} else if (f instanceof FeatureNumber) {
|
||||
process.add(new Number(context, ((FeatureNumber) f).getNumberString()));
|
||||
} else if (f instanceof FeatureChar) {
|
||||
//All the char features must have been changed already before
|
||||
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName().toString() + "\" can't be converted into a Function!");
|
||||
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
|
||||
} else {
|
||||
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName().toString() + "\" can't be converted into a Function!");
|
||||
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
|
||||
}
|
||||
}
|
||||
return process;
|
||||
}
|
||||
|
||||
private static ObjectArrayList<Feature> fixFeatures(final MathContext context, ObjectArrayList<Feature> features) throws Error {
|
||||
private static ObjectArrayList<Feature> fixFeatures(final MathContext context, ObjectArrayList<Feature> features)
|
||||
throws Error {
|
||||
|
||||
features = fixMinuses(context, features);
|
||||
|
||||
@ -190,14 +256,16 @@ public class MathParser {
|
||||
|
||||
/**
|
||||
* 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<>();
|
||||
private static ObjectArrayList<Feature> convertFunctionChars(MathContext context, ObjectArrayList<Feature> features)
|
||||
throws Error {
|
||||
final ObjectArrayList<Feature> process = new ObjectArrayList<>();
|
||||
|
||||
for (Feature f : features) {
|
||||
for (final Feature f : features) {
|
||||
if (f instanceof FeatureChar) {
|
||||
final char featureChar = ((FeatureChar) f).ch;
|
||||
Feature result = null;
|
||||
@ -210,6 +278,14 @@ public class MathParser {
|
||||
break;
|
||||
}
|
||||
|
||||
//TODO: Temporary solution. In near future Variables will be distint objects and they will have a color. So they will be no longer a BlockChar/FeatureChar
|
||||
for (char var : MathematicalSymbols.variables) {
|
||||
if ( featureChar == var) {
|
||||
result = new FeatureVariable(featureChar, V_TYPE.UNKNOWN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR, "Char " + featureChar + " isn't a known feature");
|
||||
}
|
||||
@ -225,20 +301,21 @@ public class MathParser {
|
||||
|
||||
/**
|
||||
* 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<>();
|
||||
final ObjectArrayList<Feature> process = new ObjectArrayList<>();
|
||||
|
||||
FeatureNumber numberBuffer = null;
|
||||
for (Feature f : features) {
|
||||
for (final Feature f : features) {
|
||||
if (f instanceof FeatureChar) {
|
||||
final FeatureChar bcf = (FeatureChar) f;
|
||||
final char[] numbers = MathematicalSymbols.numbers;
|
||||
boolean isNumber = false;
|
||||
for (char n : numbers) {
|
||||
for (final char n : numbers) {
|
||||
if (bcf.ch == n) {
|
||||
isNumber = true;
|
||||
break;
|
||||
@ -270,23 +347,25 @@ public class MathParser {
|
||||
|
||||
/**
|
||||
* 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<>();
|
||||
private static ObjectArrayList<Feature> fixMinuses(final MathContext context, ObjectArrayList<Feature> features)
|
||||
throws Error {
|
||||
final ObjectArrayList<Feature> process = new ObjectArrayList<>();
|
||||
Feature lastFeature = null;
|
||||
for (Feature f : features) {
|
||||
for (final Feature f : features) {
|
||||
if (f instanceof FeatureChar && ((FeatureChar) f).ch == MathematicalSymbols.SUBTRACTION) {
|
||||
boolean isNegativeOfNumber = false;
|
||||
if (lastFeature == null) {
|
||||
isNegativeOfNumber = true;
|
||||
} else if (lastFeature instanceof FeatureChar) {
|
||||
FeatureChar lcf = (FeatureChar) lastFeature;
|
||||
final FeatureChar lcf = (FeatureChar) lastFeature;
|
||||
final char[] operators = MathematicalSymbols.functionsNSN;
|
||||
for (char operator : operators) {
|
||||
for (final char operator : operators) {
|
||||
if (lcf.ch == operator) {
|
||||
isNegativeOfNumber = true;
|
||||
break;
|
||||
|
@ -0,0 +1,15 @@
|
||||
package org.warp.picalculator.math.parser.features;
|
||||
|
||||
import org.warp.picalculator.math.functions.Variable.V_TYPE;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
public class FeatureVariable extends FeatureChar {
|
||||
|
||||
public V_TYPE varType;
|
||||
|
||||
public FeatureVariable(char ch, V_TYPE varType) {
|
||||
super(ch);
|
||||
this.varType = varType;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
package org.warp.picalculator.math.parser.features.interfaces;
|
||||
|
||||
public interface FeatureBasic extends Feature {
|
||||
}
|
||||
public interface FeatureBasic extends Feature {}
|
||||
|
@ -2,7 +2,10 @@ package org.warp.picalculator.math.parser.features.interfaces;
|
||||
|
||||
public interface FeatureDouble extends Feature {
|
||||
public Object getChild1();
|
||||
|
||||
public void setChild1(Object obj);
|
||||
|
||||
public Object getChild2();
|
||||
|
||||
public void setChild2(Object obj);
|
||||
}
|
||||
|
@ -2,9 +2,14 @@ package org.warp.picalculator.math.parser.features.interfaces;
|
||||
|
||||
public interface FeatureMultiple extends Feature {
|
||||
public Object[] getChildren();
|
||||
|
||||
public Object getChild(int index);
|
||||
|
||||
public int getChildCount();
|
||||
|
||||
public void setChild(int index, Object obj);
|
||||
|
||||
public void setChildren(Object[] objs);
|
||||
|
||||
public void addChild(Object obj);
|
||||
}
|
||||
|
@ -2,5 +2,6 @@ package org.warp.picalculator.math.parser.features.interfaces;
|
||||
|
||||
public interface FeatureSingle extends Feature {
|
||||
public Object getChild();
|
||||
|
||||
public void setChild(Object obj);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,7 @@ public class FractionsRule11 {
|
||||
Function b;
|
||||
Function c;
|
||||
|
||||
Division div2 = (Division) fnc.getParameter2();
|
||||
final Division div2 = (Division) fnc.getParameter2();
|
||||
|
||||
a = fnc.getParameter1();
|
||||
b = div2.getParameter1();
|
||||
|
@ -38,7 +38,6 @@ public class VariableRule2 {
|
||||
final Function a = m1.getParameter1();
|
||||
final Function x = fnc.getParameter2();
|
||||
|
||||
|
||||
FunctionOperator rets;
|
||||
if (fnc instanceof Sum) {
|
||||
rets = new Sum(root, a, new Number(root, 1));
|
||||
|
Loading…
x
Reference in New Issue
Block a user