Fixed root.

This commit is contained in:
Gatecraft 2016-10-02 16:01:41 +02:00
parent 7aeb5e4749
commit 2f9d72191f
33 changed files with 709 additions and 590 deletions

Binary file not shown.

BIN
res/font_big_2x.rft Normal file

Binary file not shown.

Binary file not shown.

BIN
res/font_small_2x.rft Normal file

Binary file not shown.

View File

@ -2,7 +2,9 @@ package org.warp.picalculator;
import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.PIDisplay; import org.warp.picalculator.device.PIDisplay;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.screens.EquationScreen; import org.warp.picalculator.screens.EquationScreen;
import org.warp.picalculator.screens.LoadingScreen;
import com.pi4j.wiringpi.Gpio; import com.pi4j.wiringpi.Gpio;
@ -10,6 +12,7 @@ public class Main {
public static int[] screenPos = new int[] { 55, 0 }; public static int[] screenPos = new int[] { 55, 0 };
public static final int[] screenSize = new int[] { 480, 320 }; public static final int[] screenSize = new int[] { 480, 320 };
public static final int screenScale = 1; public static final int screenScale = 1;
public static final boolean zoomed = true;
public static PIDisplay d; public static PIDisplay d;
public static Main instance; public static Main instance;
@ -17,8 +20,8 @@ public class Main {
instance = this; instance = this;
Thread.currentThread().setPriority(Thread.MAX_PRIORITY); Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
beforeStart(); beforeStart();
d = new PIDisplay(new EquationScreen()); d = new PIDisplay(new LoadingScreen());
d.run("Calculator"); d.run("Raspberry PI Calculator by XDrake99 (Andrea Cavalli)");
Utils.debug.println("Shutdown..."); Utils.debug.println("Shutdown...");
beforeShutdown(); beforeShutdown();
Utils.debug.println(""); Utils.debug.println("");
@ -47,6 +50,13 @@ public class Main {
} }
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
if (test()) {
return;
}
new Main(); new Main();
} }
private static boolean test() {
return false;
}
} }

View File

@ -15,6 +15,8 @@ import java.util.List;
import org.nevec.rjm.BigDecimalMath; import org.nevec.rjm.BigDecimalMath;
import org.nevec.rjm.Rational; import org.nevec.rjm.Rational;
import org.warp.picalculator.device.PIDisplay;
import org.warp.picalculator.device.graphicengine.RAWFont;
import org.warp.picalculator.math.Variable; import org.warp.picalculator.math.Variable;
import org.warp.picalculator.math.functions.AnteriorFunction; import org.warp.picalculator.math.functions.AnteriorFunction;
import org.warp.picalculator.math.functions.Division; import org.warp.picalculator.math.functions.Division;
@ -33,7 +35,7 @@ import org.warp.picalculator.math.functions.equations.EquationsSystemPart;
public class Utils { public class Utils {
public static final int scale = 24; public static final int scale = 24;
public static final int resultScale = 8; public static final int resultScale = 8*5;
public static final int scaleMode = BigDecimal.ROUND_HALF_UP; public static final int scaleMode = BigDecimal.ROUND_HALF_UP;
public static final RoundingMode scaleMode2 = RoundingMode.HALF_UP; public static final RoundingMode scaleMode2 = RoundingMode.HALF_UP;
@ -351,19 +353,43 @@ public class Utils {
return getFontHeight(false); return getFontHeight(false);
} }
public static final int getFontHeight(boolean small) { public static final RAWFont getFont(boolean small) {
return getFont(small, Main.zoomed);
}
public static final RAWFont getFont(boolean small, boolean zoomed) {
if (small) { if (small) {
return 6; if (zoomed) {
return PIDisplay.fonts[3];
} else {
return PIDisplay.fonts[1];
}
} else { } else {
return 9; if (zoomed) {
return PIDisplay.fonts[2];
} else {
return PIDisplay.fonts[0];
}
} }
} }
public static int getFontHeight(Font font) { public static final int getFontHeight(boolean small) {
if (font.getFontName().contains("Big")) { return getFontHeight(small, Main.zoomed);
return 9; }
public static final int getFontHeight(boolean small, boolean zoomed) {
if (small) {
if (zoomed) {
return PIDisplay.glyphsHeight[3];
} else {
return PIDisplay.glyphsHeight[1];
}
} else { } else {
return 6; if (zoomed) {
return PIDisplay.glyphsHeight[2];
} else {
return PIDisplay.glyphsHeight[0];
}
} }
} }
@ -398,12 +424,33 @@ public class Utils {
return realbytes; return realbytes;
} }
public static boolean allSolved(List<Function> expressions) { public static boolean allSolved(List<Function> expressions) throws Error {
for (Function itm : expressions) { for (Function itm : expressions) {
if (itm.getStepsCount() > 0) { if (itm.isSolved() == false) {
return false; return false;
} }
} }
return true; return true;
} }
public static Function[][] joinFunctionsResults(List<Function> l1, List<Function> l2) {
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (i % size2 == 0) {
cur1+=1;
}
if (i % size1 == 0) {
cur2+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size2) cur2 = 0;
}
return results;
}
} }

View File

@ -33,14 +33,11 @@ public final class PIDisplay {
private int[] skin; private int[] skin;
private int[] skinSize; private int[] skinSize;
public static RAWFont[] fonts = new RAWFont[2]; public static RAWFont[] fonts = new RAWFont[4];
public static boolean loading = true;
public static String error = null; public static String error = null;
public String[] errorStackTrace = null; public String[] errorStackTrace = null;
public final int[] glyphsHeight = new int[] { 9, 6 }; public final static int[] glyphsHeight = new int[] { 9, 6, 18, 12 };
public float loadingTextTranslation = 0.0f;
public boolean loadingTextTranslationTopToBottom = true;
public static Screen screen; public static Screen screen;
public static String displayDebugString = ""; public static String displayDebugString = "";
@ -182,6 +179,10 @@ public final class PIDisplay {
fonts[0].create("big"); fonts[0].create("big");
fonts[1] = new RAWFont(); fonts[1] = new RAWFont();
fonts[1].create("small"); fonts[1].create("small");
fonts[2] = new RAWFont();
fonts[2].create("big_2x");
fonts[3] = new RAWFont();
fonts[3].create("small_2x");
setFont(fonts[0]); setFont(fonts[0]);
} }
@ -278,7 +279,7 @@ public final class PIDisplay {
glColor3f(255, 255, 255); glColor3f(255, 255, 255);
if (error != null) { if (error != null) {
setFont(fonts[1]); setFont(Utils.getFont(false, false));
glColor3f(129, 28, 22); glColor3f(129, 28, 22);
glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1]- this.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR"); glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1]- this.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR");
glColor3f(149, 32, 26); glColor3f(149, 32, 26);
@ -292,23 +293,6 @@ public final class PIDisplay {
setFont(fonts[0]); setFont(fonts[0]);
glColor3f(129, 28, 22); glColor3f(129, 28, 22);
glDrawStringCenter((Main.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION"); glDrawStringCenter((Main.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION");
} else if (loading) {
setFont(fonts[0]);
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2) - 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2) + 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 - 1 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + 1 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 0.5f, 0.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(0.0f, 0.0f, 0.0f, 0.75f);
glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 11, "LOADING");
setFont(fonts[1]);
colore(0.0f, 0.0f, 0.0f, 0.5f);
glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 22, "PLEASE WAIT...");
} else { } else {
draw_screen(); draw_screen();
draw_status(); draw_status();
@ -340,25 +324,9 @@ public final class PIDisplay {
*/ */
checkDisplayResized(); checkDisplayResized();
if (loading) {
if (loadingTextTranslation >= 10.0f) {
loadingTextTranslation = 10.0f;
loadingTextTranslationTopToBottom = false;
} else if (loadingTextTranslation <= -10.0f) {
loadingTextTranslation = -10.0f;
loadingTextTranslationTopToBottom = true;
}
if (loadingTextTranslationTopToBottom) {
loadingTextTranslation += dt * 15;
} else {
loadingTextTranslation -= dt * 15;
}
}
screen.beforeRender(dt); screen.beforeRender(dt);
if(forced==true || screen.mustBeRefreshed() || loading) { if(forced==true || screen.mustBeRefreshed()) {
draw(); draw();
} }
@ -380,7 +348,7 @@ public final class PIDisplay {
private void createWindow(String title) { private void createWindow(String title) {
Display.setTitle(title); Display.setTitle(title);
Display.setResizable(false); Display.setResizable(Utils.debugOn);
Display.setDisplayMode(Main.screenSize[0], Main.screenSize[1]); Display.setDisplayMode(Main.screenSize[0], Main.screenSize[1]);
Display.create(); Display.create();
} }
@ -458,8 +426,8 @@ public final class PIDisplay {
public float[] colore = new float[] { 0.0f, 0.0f, 0.0f, 1.0f }; public float[] colore = new float[] { 0.0f, 0.0f, 0.0f, 1.0f };
public void colore(float f1, float f2, float f3, float f4) { public static void colore(float f1, float f2, float f3, float f4) {
colore = new float[] { f1, f2, f3, f4 }; PIDisplay.INSTANCE.colore = new float[] { f1, f2, f3, f4 };
glColor4f((int) (f1 * 255), (int) (f2 * 255), (int) (f3 * 255), (int) (f4 * 255)); glColor4f((int) (f1 * 255), (int) (f2 * 255), (int) (f3 * 255), (int) (f4 * 255));
} }
} }

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.device; package org.warp.picalculator.device;
import java.awt.Cursor; import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Point; import java.awt.Point;
@ -14,6 +15,7 @@ import java.awt.image.BufferedImage;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.device.graphicengine.Display; import org.warp.picalculator.device.graphicengine.Display;
@ -26,16 +28,18 @@ public class PIFrame extends JFrame {
c = new CustomCanvas(); c = new CustomCanvas();
c.setDoubleBuffered(true); c.setDoubleBuffered(true);
this.add(c); this.add(c);
this.setExtendedState(Frame.MAXIMIZED_BOTH); // this.setExtendedState(Frame.MAXIMIZED_BOTH);
Toolkit.getDefaultToolkit().setDynamicLayout(false); Toolkit.getDefaultToolkit().setDynamicLayout(false);
// Transparent 16 x 16 pixel cursor image. // Transparent 16 x 16 pixel cursor image.
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB); BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
if (!Utils.debugOn) {
// Create a new blank cursor.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
// Create a new blank cursor. // Set the blank cursor to the JFrame.
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor"); getContentPane().setCursor(blankCursor);
}
// Set the blank cursor to the JFrame.
getContentPane().setCursor(blankCursor);
this.addComponentListener(new ComponentListener() { this.addComponentListener(new ComponentListener() {
@Override @Override
public void componentHidden(ComponentEvent e) { public void componentHidden(ComponentEvent e) {
@ -403,8 +407,24 @@ public class PIFrame extends JFrame {
@Override @Override
public void setSize(int width, int height) { public void setSize(int width, int height) {
super.setSize(width, height);
c.setSize(width, height); c.setSize(width, height);
super.getContentPane().setPreferredSize(new Dimension(width, height));
super.pack();
}
@Override
public Dimension getSize() {
return c.getSize();
}
@Override
public int getWidth() {
return c.getWidth();
}
@Override
public int getHeight() {
return c.getHeight();
} }
public static class CustomCanvas extends JPanel { public static class CustomCanvas extends JPanel {

View File

@ -77,7 +77,7 @@ public class Display {
@Deprecated() @Deprecated()
public static void refresh() { public static void refresh() {
if (PIDisplay.screen == null || PIDisplay.loading || (PIDisplay.error != null && PIDisplay.error.length() > 0) || PIDisplay.screen == null || PIDisplay.screen.mustBeRefreshed()) { if (PIDisplay.screen == null || (PIDisplay.error != null && PIDisplay.error.length() > 0) || PIDisplay.screen == null || PIDisplay.screen.mustBeRefreshed()) {
Display.INSTANCE.c.repaint(false); Display.INSTANCE.c.repaint(false);
} }
} }
@ -305,5 +305,9 @@ public class Display {
return fm.stringWidth(text); return fm.stringWidth(text);
} }
public static int getFontHeight() {
return currentFont.charH;
}
} }
} }

View File

@ -22,13 +22,13 @@ public class RAWFont {
public boolean[][] rawchars; public boolean[][] rawchars;
public int[] chars32; public int[] chars32;
public long[] chars64;
public static final boolean is64 = true;
public int minBound = 10; public int minBound = 10;
public int maxBound = 9599; public int maxBound = 0;
public int charW; public int charW;
public int charH; public int charH;
public int charS; public int charS;
public int charIntCount;
public static final int intBits = 31;
public void create(String name) { public void create(String name) {
try { try {
@ -37,39 +37,34 @@ public class RAWFont {
e.printStackTrace(); e.printStackTrace();
System.exit(1); System.exit(1);
} }
if (is64) { chars32 = new int[(maxBound-minBound)*charIntCount];
chars64 = new long[maxBound-minBound];
} else {
chars32 = new int[(maxBound-minBound)*2];
}
for (int charIndex = 0; charIndex < maxBound-minBound; charIndex++) { for (int charIndex = 0; charIndex < maxBound-minBound; charIndex++) {
if (is64) { boolean[] currentChar = rawchars[charIndex];
boolean[] currentChar = rawchars[charIndex]; if (currentChar == null) {
if (currentChar == null) { int currentInt = 0;
chars64[charIndex] = 0x1FFFFFFFFFFFL; int currentBit = 0;
} else { for (int i = 0; i < charS; i++) {
long result = 0, l = charS; if (currentInt*intBits+currentBit >= (currentInt+1)*intBits) {
for (int i = 0; i < l; ++i) { currentInt += 1;
result = (result << 1) | (currentChar[i] ? 1L : 0L); currentBit = 0;
} }
chars64[charIndex] = result; chars32[charIndex*charIntCount+currentInt] = (chars32[charIndex*charIntCount+currentInt] << 1) + 1;
} currentBit += 1;
}
} else { } else {
boolean[] currentChar = rawchars[charIndex]; if (charIndex == 65 && name == "big_2x") {
if (currentChar == null) { System.out.println("test");
chars32[charIndex*2] = 0x1FFFFFFF; }
chars32[(charIndex*2)+1] = 0xFFFF; int currentInt = 0;
} else { int currentBit = 0;
int result1 = 0, result2 = 0, l1 = 29, l2 = currentChar.length; for (int i = 0; i < charS; i++) {
for (int i = 0; i < l1; ++i) { if (currentBit >= intBits) {
result1 = (result1 << 1) + (currentChar[i] ? 1 : 0); currentInt += 1;
} currentBit = 0;
for (int i = l1; i < l2; ++i) { }
result2 = (result2 << 1) + (currentChar[i] ? 1 : 0); chars32[charIndex*charIntCount+currentInt] = (chars32[charIndex*charIntCount+currentInt]) | ((currentChar[i] ? 1 : 0) << currentBit);
} currentBit++;
chars32[charIndex*2] = result1; }
chars32[(charIndex*2)+1] = result2;
}
} }
} }
@ -90,29 +85,40 @@ public class RAWFont {
charW = file[0x4]; charW = file[0x4];
charH = file[0x5]; charH = file[0x5];
charS = charW*charH; charS = charW*charH;
charIntCount = (int) Math.ceil(((double)charS)/((double)intBits));
minBound = file[0x7] << 24 | file[0x8] << 16 | file[0x9] << 8 | file[0xA]; minBound = file[0x7] << 24 | file[0x8] << 16 | file[0x9] << 8 | file[0xA];
maxBound = file[0xC] << 24 | file[0xD] << 16 | file[0xE] << 8 | file[0xF]; maxBound = file[0xC] << 24 | file[0xD] << 16 | file[0xE] << 8 | file[0xF];
if (maxBound <= minBound) { if (maxBound <= minBound) {
maxBound = 9599; //TODO remove it: temp fix maxBound = 10000; //TODO remove it: temp fix
} }
rawchars = new boolean[maxBound-minBound][]; rawchars = new boolean[maxBound-minBound][];
int index = 0x10; int index = 0x10;
while (index < filelength) { while (index < filelength) {
int charIndex = file[index] << 8 | file[index+1]; try {
boolean[] rawchar = new boolean[charS]; int charIndex = file[index] << 8 | file[index+1];
int charbytescount = (int) Math.ceil(charS/8)+1; boolean[] rawchar = new boolean[charS];
int currentBit = 0; int charbytescount = 0;
for (int i = 0; i <= charbytescount; i++) { while (charbytescount*8 < charS) {
for (int bit = 0; bit < 8; bit++) { charbytescount+=1;
if (currentBit >= charS) { }
break; int currentBit = 0;
} for (int i = 0; i <= charbytescount; i++) {
rawchar[i*8+bit] = (((file[index + 2 + i] >> (7-bit)) & 0x1)>=1)?true:false; for (int bit = 0; bit < 8; bit++) {
currentBit++; if (currentBit >= charS) {
} break;
}
rawchar[currentBit] = (((file[index + 2 + i] >> (8-1-bit)) & 0x1)==1)?true:false;
currentBit++;
}
}
rawchars[charIndex - minBound] = rawchar;
index += 2 + charbytescount;
} }
rawchars[charIndex - minBound] = rawchar; catch (Exception ex) {
index += 2 + charbytescount; ex.printStackTrace();
System.out.println(string);
System.exit(-1);
}
} }
} else { } else {
throw new IOException(); throw new IOException();
@ -147,46 +153,23 @@ public class RAWFont {
public void drawText(int[] screen, int[] screenSize, int x, int y, int[] text, int color) { public void drawText(int[] screen, int[] screenSize, int x, int y, int[] text, int color) {
final int screenLength = screen.length; final int screenLength = screen.length;
int screenPos = 0; int screenPos = 0;
if (is64) {
long res = 0;
final int l = text.length; int currentInt;
for (int i = 0; i < l; i++) { int currentIntBitPosition;
long chr = chars64[text[i]]; int bitData;
int dx = 0; final int l = text.length;
int dy = 0; for (int i = 0; i < l; i++) {
for (int j = charS-1; j >= 0; j--) { final int charIndex = text[i];
res = (chr >> j) & 1; for (int dy = 0; dy < charH; dy++) {
screenPos = (x + dx) + (y + dy) * screenSize[0]; for (int dx = 0; dx < charW; dx++) {
if (res == 1 & screenLength > screenPos) { int bit = dx + dy * charW;
screen[screenPos] = color; currentInt = (int) (Math.floor((double)bit)/((double)intBits));
} currentIntBitPosition = bit-(currentInt*intBits);
dx++; bitData = (chars32[charIndex*charIntCount+currentInt] >> currentIntBitPosition) & 1;
if (dx >= charW) { screenPos = x + (i * (charW + 1)) + dx + (y + dy) * screenSize[0];
dx = 0; if (bitData == 1 & screenLength > screenPos) {
dy++; screen[screenPos] = color;
}
}
x+=charW+1;
}
} else {
int res = 0;
final int l = text.length;
for (int i = 0; i < l; i++) {
final int charIndex = text[i]*2;
int chrP1 = chars32[charIndex];
int chrP2 = chars32[charIndex+1];
for (int dx = 0; dx < charW; dx++) {
for (int dy = 0; dy < charH; dy++) {
int bit = dx + dy * charW;
if (bit < 29) {
res = chrP1 >> (28-bit) & 1;
} else {
res = chrP2 >> (12-bit) & 1;
}
screenPos = x + (i * (charW + 1)) + dx + (y + dy) * screenSize[0];
if (res == 1 & screenLength > res) {
screen[screenPos] = color;
}
} }
} }
} }

View File

@ -59,47 +59,48 @@ public class Calculator {
public static void solve() throws Error { public static void solve() throws Error {
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) { if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
EquationScreen es = (EquationScreen) Calculator.sessions[0]; EquationScreen es = (EquationScreen) Calculator.sessions[0];
Function f = es.f; List<Function> results = new ArrayList<>();
if (f instanceof Equation) { List<Function> partialResults = new ArrayList<>();
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es)); for (Function f : es.f) {
} else { if (f instanceof Equation) {
List<Function> results = new ArrayList<>(); PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
List<Function> partialResults = new ArrayList<>();
results.add(es.f);
while (Utils.allSolved(results) == false) {
for (Function itm : results) {
if (itm.getStepsCount() != 0) {
List<Function> dt = itm.solveOneStep();
partialResults.addAll(dt);
} else {
partialResults.add(itm);
}
}
results = new ArrayList<Function>(partialResults);
partialResults.clear();
}
if (results.size() == 0) {
} else { } else {
Collections.reverse(results); results.add(f);
// add elements to al, including duplicates while (Utils.allSolved(results) == false) {
Set<Function> hs = new LinkedHashSet<>(); for (Function itm : results) {
hs.addAll(results); if (itm.isSolved() == false) {
results.clear(); List<Function> dt = itm.solveOneStep();
results.addAll(hs); partialResults.addAll(dt);
es.f2 = results; } else {
for (Function rf : es.f2) { partialResults.add(itm);
rf.generateGraphics(); }
}
results = new ArrayList<Function>(partialResults);
partialResults.clear();
} }
} }
} }
if (results.size() == 0) {
} else {
Collections.reverse(results);
// // add elements to al, including duplicates
// Set<Function> hs = new LinkedHashSet<>();
// hs.addAll(results);
// results.clear();
// results.addAll(hs);
es.f2 = results;
for (Function rf : es.f2) {
rf.generateGraphics();
}
}
} }
} }
public static void solve(char letter) throws Error { public static void solve(char letter) throws Error {
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) { if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
EquationScreen es = (EquationScreen) Calculator.sessions[0]; EquationScreen es = (EquationScreen) Calculator.sessions[0];
Function f = es.f; List<Function> f = es.f;
if (f instanceof Equation) { if (f instanceof Equation) {
List<Function> results = ((Equation)f).solve(letter); List<Function> results = ((Equation)f).solve(letter);
Collections.reverse(results); Collections.reverse(results);

View File

@ -47,7 +47,7 @@ public class MathematicalSymbols {
} }
public static String[] variables() { public static String[] variables() {
return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ""};
} }
public static String[] genericSyntax() { public static String[] genericSyntax() {

View File

@ -37,16 +37,14 @@ public abstract class AnteriorFunction implements Function {
@Override @Override
public abstract List<Function> solveOneStep() throws Error; public abstract List<Function> solveOneStep() throws Error;
protected int stepsCount = -1;
@Override @Override
public int getStepsCount() { public boolean isSolved() throws Error {
if (stepsCount == -1) { return variable.isSolved() ? !isSolvable() : false;
stepsCount = variable.getStepsCount()+1;
}
return stepsCount;
} }
protected abstract boolean isSolvable() throws Error;
@Override @Override
public void generateGraphics() { public void generateGraphics() {
variable.setSmall(small); variable.setSmall(small);
@ -63,11 +61,7 @@ public abstract class AnteriorFunction implements Function {
int wsegno = getStringWidth(getSymbol()); int wsegno = getStringWidth(getSymbol());
float hsegno = Utils.getFontHeight(small); float hsegno = Utils.getFontHeight(small);
float maxh = getHeight(); float maxh = getHeight();
if (small) { Display.Render.setFont(Utils.getFont(small));
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[0]);
}
glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), getSymbol()); glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), getSymbol());
getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2)); getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2));

View File

@ -14,6 +14,7 @@ import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.device.PIDisplay; import org.warp.picalculator.device.PIDisplay;
import org.warp.picalculator.device.graphicengine.Display; import org.warp.picalculator.device.graphicengine.Display;
import org.warp.picalculator.device.graphicengine.Display.Render;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
public class Division extends FunctionTwoValues { public class Division extends FunctionTwoValues {
@ -27,53 +28,44 @@ public class Division extends FunctionTwoValues {
return MathematicalSymbols.DIVISION; return MathematicalSymbols.DIVISION;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
if (((Number)variable2).getTerm().compareTo(NumeroAvanzatoVec.ZERO) == 0) {
throw new Error(Errors.DIVISION_BY_ZERO);
} else {
return true;
}
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR);
}
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
if (variable2 instanceof Number && ((Number)variable2).getTerm().compareTo(NumeroAvanzatoVec.ZERO) == 0) {
throw new Error(Errors.DIVISION_BY_ZERO);
}
result.add(((Number) variable1).divide((Number)variable2)); result.add(((Number) variable1).divide((Number)variable2));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (size1 < size2 && cur2 % size1 == 0) {
cur2+=1;
}
if (size2 < size1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Division((Function)f[0], (Function)f[1])); result.add(new Division((Function)f[0], (Function)f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }
@ -125,9 +117,10 @@ public class Division extends FunctionTwoValues {
} }
int w1 = 0; int w1 = 0;
int h1 = 0; int h1 = 0;
Display.Render.setFont(Utils.getFont(small));
if (minus) { if (minus) {
w1 = getStringWidth(numerator); w1 = getStringWidth(numerator);
h1 = Utils.getFontHeight(small); h1 = Render.getFontHeight();
} else { } else {
w1 = ((Function) var1).getWidth(); w1 = ((Function) var1).getWidth();
h1 = ((Function) var1).getHeight(); h1 = ((Function) var1).getHeight();
@ -141,12 +134,7 @@ public class Division extends FunctionTwoValues {
} }
if (minus && drawMinus) { if (minus && drawMinus) {
minusw = getStringWidth("-") + 1; minusw = getStringWidth("-") + 1;
minush = Utils.getFontHeight(small); minush = Render.getFontHeight();
if (small) {
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[0]);
}
glDrawStringLeft(x+1, y + h1 + 1 + 1 - (minush / 2), "-"); glDrawStringLeft(x+1, y + h1 + 1 + 1 - (minush / 2), "-");
glDrawStringLeft((int) (x+1 + minusw + 1 + (maxw - w1) / 2d), y, numerator); glDrawStringLeft((int) (x+1 + minusw + 1 + (maxw - w1) / 2d), y, numerator);
} else { } else {

View File

@ -260,7 +260,10 @@ public class Expression extends FunctionMultipleValues {
// Fallback // Fallback
NumeroAvanzato na = NumeroAvanzato.ONE; NumeroAvanzato na = NumeroAvanzato.ONE;
Variables iy = na.getVariableY(); Variables iy = na.getVariableY();
iy.getVariablesList().add(new Variable(charI.charAt(0), 1, 1)); Variable var1 = new Variable(charI.charAt(0), 1, 1);
List<Variable> newVariableList = iy.getVariablesList();
newVariableList.add(var1);
iy = new Variables(newVariableList.toArray(new Variable[newVariableList.size()]));
na = na.setVariableY(iy); na = na.setVariableY(iy);
f = new Number(na); f = new Number(na);
} else { } else {
@ -556,14 +559,22 @@ public class Expression extends FunctionMultipleValues {
return "Parentesi"; return "Parentesi";
} }
@Override
protected boolean isSolvable() {
if (variables.length >= 1) {
return true;
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
List<Function> ret = new ArrayList<>(); List<Function> ret = new ArrayList<>();
if (variables.length == 0) { if (variables.length == 1) {
stepsCount = -1; if (variables[0].isSolved()) {
return ret; ret.add(variables[0]);
} else if (variables.length == 1) { return ret;
if (variables[0].getStepsCount() > 0) { } else {
List<Function> l = variables[0].solveOneStep(); List<Function> l = variables[0].solveOneStep();
for (Function f : l) { for (Function f : l) {
if (f instanceof Number) { if (f instanceof Number) {
@ -572,23 +583,17 @@ public class Expression extends FunctionMultipleValues {
ret.add(new Expression(new Function[]{(Function) f})); ret.add(new Expression(new Function[]{(Function) f}));
} }
} }
stepsCount = -1;
return ret;
} else {
ret.add(variables[0]);
stepsCount = -1;
return ret; return ret;
} }
} else { } else {
for (Function f : variables) { for (Function f : variables) {
if (f.getStepsCount() >= stepsCount - 1) { if (f.isSolved() == false) {
List<Function> partial = f.solveOneStep(); List<Function> partial = f.solveOneStep();
for (Function fnc : partial) { for (Function fnc : partial) {
ret.add(new Expression(new Function[]{(Function) fnc})); ret.add(new Expression(new Function[]{(Function) fnc}));
} }
} }
} }
stepsCount = -1;
return ret; return ret;
} }
} }

View File

@ -7,10 +7,10 @@ import org.warp.picalculator.Error;
public interface Function { public interface Function {
public String getSymbol(); public String getSymbol();
public int getStepsCount();
public List<Function> solveOneStep() throws Error; public List<Function> solveOneStep() throws Error;
public boolean isSolved() throws Error;
public void generateGraphics(); public void generateGraphics();
public void draw(int x, int y); public void draw(int x, int y);

View File

@ -3,6 +3,8 @@ package org.warp.picalculator.math.functions;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.warp.picalculator.Error;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunctionMultipleValues implements Function { public abstract class FunctionMultipleValues implements Function {
@ -62,23 +64,17 @@ public abstract class FunctionMultipleValues implements Function {
@Override @Override
public abstract String getSymbol(); public abstract String getSymbol();
protected int stepsCount = -1;
@Override @Override
public int getStepsCount() { public boolean isSolved() throws Error {
if (stepsCount == -1) { for (Function variable : variables) {
int max = 0; if (!variable.isSolved()) {
int cur = 0; return false;
for (Function f : variables) {
cur = f.getStepsCount();
if (max < cur) {
max = cur;
}
} }
return max+1;
} else {
return stepsCount;
} }
return !isSolvable();
} }
protected abstract boolean isSolvable() throws Error;
@Override @Override
public abstract void generateGraphics(); public abstract void generateGraphics();

View File

@ -46,21 +46,13 @@ public abstract class FunctionTwoValues implements Function {
@Override @Override
public abstract String getSymbol(); public abstract String getSymbol();
protected int stepsCount = -1;
@Override @Override
public int getStepsCount() { public boolean isSolved() throws Error {
if (stepsCount == -1) { return (variable1.isSolved() & variable2.isSolved()) ? !isSolvable() : false;
int val1 = variable1.getStepsCount();
int val2 = variable2.getStepsCount();
if (val1 > val2) {
stepsCount = val1+1;
} else {
stepsCount = val2+1;
}
}
return stepsCount;
} }
protected abstract boolean isSolvable() throws Error;
@Override @Override
public abstract List<Function> solveOneStep() throws Error; public abstract List<Function> solveOneStep() throws Error;
@ -84,11 +76,7 @@ public abstract class FunctionTwoValues implements Function {
variable1.draw(dx + x, ln - variable1.getLine() + y); variable1.draw(dx + x, ln - variable1.getLine() + y);
dx += 1+variable1.getWidth(); dx += 1+variable1.getWidth();
if (drawSignum()) { if (drawSignum()) {
if (small) { Display.Render.setFont(Utils.getFont(small));
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[1]);
}
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol()); glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
dx += getStringWidth(getSymbol()); dx += getStringWidth(getSymbol());
} }

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.Variable; import org.warp.picalculator.math.Variable;
@ -21,48 +22,38 @@ public class Multiplication extends FunctionTwoValues {
} }
@Override @Override
public List<Function> solveOneStep() throws Error { protected boolean isSolvable() throws Error {
if (variable1 == null || variable2 == null) { if (variable1 instanceof Number & variable2 instanceof Number) {
throw new Error(Errors.SYNTAX_ERROR); return true;
} }
return false;
}
@Override
public List<Function> solveOneStep() throws Error {
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
result.add(((Number)variable1).multiply((Number)variable2)); result.add(((Number)variable1).multiply((Number)variable2));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Multiplication(f[0], f[1])); result.add(new Multiplication(f[0], f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }

View File

@ -130,11 +130,7 @@ public class Number implements Function {
public void draw(int x, int y) { public void draw(int x, int y) {
if (getTerm().isBigInteger(false)) { if (getTerm().isBigInteger(false)) {
if (small) { Display.Render.setFont(Utils.getFont(small));
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[0]);
}
String t = toString(); String t = toString();
if (t.startsWith("-")) { if (t.startsWith("-")) {
@ -147,7 +143,7 @@ public class Number implements Function {
glDrawStringLeft(x+1, y, t); glDrawStringLeft(x+1, y, t);
} else if (getTerm().isRational(false)) { } else if (getTerm().isRational(false)) {
small = true; small = true;
Display.Render.setFont(PIDisplay.fonts[1]); Display.Render.setFont(Utils.getFont(true));
Rational r = getTerm().toRational(false); Rational r = getTerm().toRational(false);
boolean minus = false; boolean minus = false;
int minusw = 0; int minusw = 0;
@ -180,7 +176,7 @@ public class Number implements Function {
glFillRect(x + minusw + 1, y + h1 + 1, maxw, 1); glFillRect(x + minusw + 1, y + h1 + 1, maxw, 1);
} else if (getTerm().toFancyString().contains("/")) { } else if (getTerm().toFancyString().contains("/")) {
small = true; small = true;
Display.Render.setFont(PIDisplay.fonts[1]); Display.Render.setFont(Utils.getFont(true));
String r = getTerm().toFancyString(); String r = getTerm().toFancyString();
String numer = r.substring(0, r.lastIndexOf("/")); String numer = r.substring(0, r.lastIndexOf("/"));
String denom = r.substring(numer.length() + 1, r.length()); String denom = r.substring(numer.length() + 1, r.length());
@ -216,11 +212,7 @@ public class Number implements Function {
glColor3f(0, 0, 0); glColor3f(0, 0, 0);
glFillRect(x + minusw + 1, y + h1 + 1, maxw, 1); glFillRect(x + minusw + 1, y + h1 + 1, maxw, 1);
} else { } else {
if (small) { Display.Render.setFont(Utils.getFont(small));
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[0]);
}
String r = getTerm().toFancyString(); String r = getTerm().toFancyString();
if (r.startsWith("-")) { if (r.startsWith("-")) {
@ -387,8 +379,8 @@ public class Number implements Function {
} }
@Override @Override
public int getStepsCount() { public boolean isSolved() {
return 0; return true;
} }
@Override @Override

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
public class Power extends FunctionTwoValues { public class Power extends FunctionTwoValues {
@ -18,6 +19,14 @@ public class Power extends FunctionTwoValues {
return MathematicalSymbols.POWER; return MathematicalSymbols.POWER;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
return false;
}
@Override @Override
public void generateGraphics() { public void generateGraphics() {
variable1.setSmall(small); variable1.setSmall(small);
@ -33,47 +42,29 @@ public class Power extends FunctionTwoValues {
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR);
}
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
result.add((Function) ((Number)variable1).pow((Number)variable2)); result.add((Function) ((Number)variable1).pow((Number)variable2));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Power((Function)f[0], (Function)f[1])); result.add(new Power((Function)f[0], (Function)f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }

View File

@ -5,6 +5,7 @@ import java.util.List;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
public class PrioritaryMultiplication extends FunctionTwoValues { public class PrioritaryMultiplication extends FunctionTwoValues {
@ -18,49 +19,42 @@ public class PrioritaryMultiplication extends FunctionTwoValues {
return MathematicalSymbols.PRIORITARY_MULTIPLICATION; return MathematicalSymbols.PRIORITARY_MULTIPLICATION;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) { if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
result.add(((Number)variable1).multiply((Number)variable2)); result.add(((Number)variable1).multiply((Number)variable2));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new PrioritaryMultiplication((Function)f[0], (Function)f[1])); result.add(new PrioritaryMultiplication((Function)f[0], (Function)f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }

View File

@ -8,6 +8,7 @@ import java.util.List;
import org.nevec.rjm.NumeroAvanzatoVec; import org.nevec.rjm.NumeroAvanzatoVec;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
public class Root extends FunctionTwoValues { public class Root extends FunctionTwoValues {
@ -33,52 +34,44 @@ public class Root extends FunctionTwoValues {
height = variable1.getHeight() + variable2.getHeight() - 2; height = variable1.getHeight() + variable2.getHeight() - 2;
line = variable1.getHeight() + variable2.getLine() - 2; line = variable1.getHeight() + variable2.getLine() - 2;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
if ((((Number)variable2).pow(new Number(NumeroAvanzatoVec.ONE).divide((Number) variable1)).getTerm().isBigInteger(true))) {
return true;
}
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR);
}
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
Number exponent = new Number(NumeroAvanzatoVec.ONE); Number exponent = new Number(NumeroAvanzatoVec.ONE);
exponent = exponent.divide((Number) getVariable1()); exponent = exponent.divide((Number) variable1);
result.add(((Number)variable1).pow(exponent)); result.add(((Number)variable2).pow(exponent));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Root((Function)f[0], (Function)f[1])); result.add(new Root((Function)f[0], (Function)f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }

View File

@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.nevec.rjm.NumeroAvanzatoVec;
import org.nevec.rjm.Rational; import org.nevec.rjm.Rational;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
@ -29,6 +30,16 @@ public class RootSquare extends AnteriorFunction {
width = 1 + 4 + getVariable().getWidth() + 1; width = 1 + 4 + getVariable().getWidth() + 1;
line = getVariable().getLine() + 2; line = getVariable().getLine() + 2;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable instanceof Number) {
if ((((Number)variable).pow(new Number(new Rational(1, 2))).getTerm().isBigInteger(true))) {
return true;
}
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
@ -36,7 +47,7 @@ public class RootSquare extends AnteriorFunction {
throw new Error(Errors.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable.isSolved()) {
try { try {
Number var = (Number) getVariable(); Number var = (Number) getVariable();
result.add(var.pow(new Number(new Rational(1, 2)))); result.add(var.pow(new Number(new Rational(1, 2))));
@ -49,17 +60,16 @@ public class RootSquare extends AnteriorFunction {
} }
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
if (variable.getStepsCount() >= stepsCount - 1) { if (variable.isSolved()) {
l1.addAll(variable.solveOneStep());
} else {
l1.add(variable); l1.add(variable);
} else {
l1.addAll(variable.solveOneStep());
} }
for (Function f : l1) { for (Function f : l1) {
result.add(new RootSquare((Function)f)); result.add(new RootSquare((Function)f));
} }
} }
stepsCount=-1;
return result; return result;
} }

View File

@ -1,11 +1,16 @@
package org.warp.picalculator.math.functions; package org.warp.picalculator.math.functions;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.nevec.rjm.NumeroAvanzato;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.Variable;
import org.warp.picalculator.math.Variables;
public class Subtraction extends FunctionTwoValues { public class Subtraction extends FunctionTwoValues {
@ -18,49 +23,54 @@ public class Subtraction extends FunctionTwoValues {
return MathematicalSymbols.SUBTRACTION; return MathematicalSymbols.SUBTRACTION;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) { if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number("-1")))); if (((Number)variable1).term.isBigInteger(false) & ((Number)variable2).term.isBigInteger(false)) {
if (((Number)variable1).term.toBigInteger(false).compareTo(new BigInteger("2")) == 0 && ((Number)variable2).term.toBigInteger(false).compareTo(new BigInteger("2")) == 0) {
NumeroAvanzato na = NumeroAvanzato.ONE;
Variables iy = na.getVariableY();
List<Variable> newVariableList = iy.getVariablesList();
newVariableList.add(new Variable('♓', 1, 1));
iy = new Variables(newVariableList.toArray(new Variable[newVariableList.size()]));
na = na.setVariableY(iy);
result.add(new Number(na));
return result;
}
}
result.add(((Number)variable1).add((Number)variable2).multiply(new Number("-1")));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Subtraction((Function)f[0], (Function)f[1])); result.add(new Sum((Function)f[0], (Function)f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }

View File

@ -3,15 +3,19 @@ package org.warp.picalculator.math.functions;
import static org.warp.picalculator.device.graphicengine.Display.Render.getStringWidth; import static org.warp.picalculator.device.graphicengine.Display.Render.getStringWidth;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft; import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.nevec.rjm.NumeroAvanzato;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.Errors; import org.warp.picalculator.Errors;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
import org.warp.picalculator.device.PIDisplay; import org.warp.picalculator.device.PIDisplay;
import org.warp.picalculator.device.graphicengine.Display; import org.warp.picalculator.device.graphicengine.Display;
import org.warp.picalculator.math.MathematicalSymbols; import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.Variable;
import org.warp.picalculator.math.Variables;
public class Sum extends FunctionTwoValues { public class Sum extends FunctionTwoValues {
@ -23,6 +27,14 @@ public class Sum extends FunctionTwoValues {
public String getSymbol() { public String getSymbol() {
return MathematicalSymbols.SUM; return MathematicalSymbols.SUM;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
@ -30,43 +42,40 @@ public class Sum extends FunctionTwoValues {
throw new Error(Errors.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
if (((Number)variable1).term.isBigInteger(false) & ((Number)variable2).term.isBigInteger(false)) {
if (((Number)variable1).term.toBigInteger(false).compareTo(new BigInteger("2")) == 0 && ((Number)variable2).term.toBigInteger(false).compareTo(new BigInteger("2")) == 0) {
NumeroAvanzato na = NumeroAvanzato.ONE;
Variables iy = na.getVariableY();
List<Variable> newVariableList = iy.getVariablesList();
newVariableList.add(new Variable('♓', 1, 1));
iy = new Variables(newVariableList.toArray(new Variable[newVariableList.size()]));
na = na.setVariableY(iy);
result.add(new Number(na));
return result;
}
}
result.add(((Number)variable1).add((Number)variable2)); result.add(((Number)variable1).add((Number)variable2));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size1 = l1.size();
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Sum((Function)f[0], (Function)f[1])); result.add(new Sum((Function)f[0], (Function)f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }
@ -93,11 +102,7 @@ public class Sum extends FunctionTwoValues {
int dx = 0; int dx = 0;
variable1.draw(dx + x, ln - variable1.getLine() + y); variable1.draw(dx + x, ln - variable1.getLine() + y);
dx += variable1.getWidth(); dx += variable1.getWidth();
if (small) { Display.Render.setFont(Utils.getFont(small));
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[0]);
}
dx += 1; dx += 1;
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol()); glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
dx += getStringWidth(getSymbol()); dx += getStringWidth(getSymbol());

View File

@ -24,50 +24,43 @@ public class SumSubtraction extends FunctionTwoValues {
return MathematicalSymbols.SUM_SUBTRACTION; return MathematicalSymbols.SUM_SUBTRACTION;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) { if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
result.add(((Number)variable1).add((Number)variable2)); result.add(((Number)variable1).add((Number)variable2));
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number("-1")))); result.add(((Number)variable1).add(((Number)variable2).multiply(new Number("-1"))));
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved()) {
l1.addAll(variable1.solveOneStep());
} else {
l1.add(variable1); l1.add(variable1);
}
if (variable2.getStepsCount() >= stepsCount - 1) {
l2.addAll(variable2.solveOneStep());
} else { } else {
l1.addAll(variable1.solveOneStep());
}
if (variable2.isSolved()) {
l2.add(variable2); l2.add(variable2);
} else {
l2.addAll(variable2.solveOneStep());
} }
int size1 = l1.size(); Function[][] results = Utils.joinFunctionsResults(l1, l2);
int size2 = l2.size();
int cur1 = 0;
int cur2 = 0;
int total = l1.size()*l2.size();
Function[][] results = new Function[total][2];
for (int i = 0; i < total; i++) {
results[i] = new Function[]{l1.get(cur1), l2.get(cur2)};
if (cur1 < cur2 && cur2 % size1 == 0) {
cur2+=1;
} else if (cur2 < cur1 && cur1 % size2 == 0) {
cur1+=1;
}
if (cur1 >= size1) cur1 = 0;
if (cur2 >= size1) cur2 = 0;
}
for (Function[] f : results) { for (Function[] f : results) {
result.add(new SumSubtraction(f[0], f[1])); result.add(new SumSubtraction(f[0], f[1]));
} }
} }
stepsCount=-1;
return result; return result;
} }
@ -94,11 +87,7 @@ public class SumSubtraction extends FunctionTwoValues {
int dx = 0; int dx = 0;
variable1.draw(dx + x, ln - variable1.getLine() + y); variable1.draw(dx + x, ln - variable1.getLine() + y);
dx += variable1.getWidth(); dx += variable1.getWidth();
if (small) { Display.Render.setFont(Utils.getFont(small));
Display.Render.setFont(PIDisplay.fonts[1]);
} else {
Display.Render.setFont(PIDisplay.fonts[0]);
}
dx += 1; dx += 1;
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol()); glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
dx += getStringWidth(getSymbol()); dx += getStringWidth(getSymbol());

View File

@ -28,13 +28,21 @@ public class Equation extends FunctionTwoValues {
return MathematicalSymbols.EQUATION; return MathematicalSymbols.EQUATION;
} }
@Override
protected boolean isSolvable() throws Error {
if (variable1 instanceof Number & variable2 instanceof Number) {
return true;
}
return false;
}
@Override @Override
public List<Function> solveOneStep() throws Error { public List<Function> solveOneStep() throws Error {
if (variable1 == null || variable2 == null) { if (variable1 == null || variable2 == null) {
throw new Error(Errors.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
ArrayList<Function> result = new ArrayList<>(); ArrayList<Function> result = new ArrayList<>();
if (stepsCount == 1) { if (variable1.isSolved() & variable2.isSolved()) {
if (((Number)variable2).getTerm().isBigInteger(false) && ((Number)variable2).getTerm().toBigInteger(false).compareTo(new BigInteger("0")) == 0) { if (((Number)variable2).getTerm().isBigInteger(false) && ((Number)variable2).getTerm().toBigInteger(false).compareTo(new BigInteger("0")) == 0) {
result.add(this); result.add(this);
} else { } else {
@ -43,12 +51,12 @@ public class Equation extends FunctionTwoValues {
} else { } else {
List<Function> l1 = new ArrayList<Function>(); List<Function> l1 = new ArrayList<Function>();
List<Function> l2 = new ArrayList<Function>(); List<Function> l2 = new ArrayList<Function>();
if (variable1.getStepsCount() >= stepsCount - 1) { if (variable1.isSolved() == false) {
l1.addAll(variable1.solveOneStep()); l1.addAll(variable1.solveOneStep());
} else { } else {
l1.add(variable1); l1.add(variable1);
} }
if (variable2.getStepsCount() >= stepsCount - 1) { if (variable2.isSolved() == false) {
l2.addAll(variable2.solveOneStep()); l2.addAll(variable2.solveOneStep());
} else { } else {
l2.add(variable2); l2.add(variable2);
@ -73,25 +81,9 @@ public class Equation extends FunctionTwoValues {
for (Function[] f : results) { for (Function[] f : results) {
result.add(new Equation(f[0], f[1])); result.add(new Equation(f[0], f[1]));
} }
stepsCount=-1;
} }
return result; return result;
} }
private int stepsCount = -1;
@Override
public int getStepsCount() {
if (stepsCount == -1) {
int val1 = variable1.getStepsCount();
int val2 = variable2.getStepsCount();
if (val1 > val2) {
stepsCount = val1+1;
} else {
stepsCount = val2+1;
}
}
return stepsCount;
}
public List<Function> solve(char variableCharacter) { public List<Function> solve(char variableCharacter) {
@SuppressWarnings("unused") @SuppressWarnings("unused")

View File

@ -6,8 +6,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
import org.warp.picalculator.math.functions.Expression;
import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Function;
import org.warp.picalculator.math.functions.FunctionMultipleValues; import org.warp.picalculator.math.functions.FunctionMultipleValues;
import org.warp.picalculator.math.functions.Number;
public class EquationsSystem extends FunctionMultipleValues { public class EquationsSystem extends FunctionMultipleValues {
static final int spacing = 2; static final int spacing = 2;
@ -30,14 +32,42 @@ public class EquationsSystem extends FunctionMultipleValues {
} }
@Override @Override
public List<Function> solveOneStep() throws NumberFormatException, Error { protected boolean isSolvable() {
// TODO implementare il calcolo dei sistemi if (variables.length >= 1) {
if (stepsCount == 1) { return true;
List<Function> l = new ArrayList<Function>(); }
l.add(variables[0]); return false;
return l; }
@Override
public List<Function> solveOneStep() throws Error {
List<Function> ret = new ArrayList<>();
if (variables.length == 1) {
if (variables[0].isSolved()) {
ret.add(variables[0]);
return ret;
} else {
List<Function> l = variables[0].solveOneStep();
for (Function f : l) {
if (f instanceof Number) {
ret.add(f);
} else {
ret.add(new Expression(new Function[]{(Function) f}));
}
}
return ret;
}
} else {
for (Function f : variables) {
if (f.isSolved() == false) {
List<Function> partial = f.solveOneStep();
for (Function fnc : partial) {
ret.add(new Expression(new Function[]{(Function) fnc}));
}
}
}
return ret;
} }
return variables[0].solveOneStep();
} }
@Override @Override

View File

@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions.equations;
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3f; import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3f;
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine; import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
@ -21,9 +22,19 @@ public class EquationsSystemPart extends AnteriorFunction {
return MathematicalSymbols.SYSTEM; return MathematicalSymbols.SYSTEM;
} }
@Override
protected boolean isSolvable() throws Error {
return variable.isSolved()==false;
}
@Override @Override
public List<Function> solveOneStep() throws NumberFormatException, Error { public List<Function> solveOneStep() throws NumberFormatException, Error {
// TODO implementare il calcolo dei sistemi // TODO implementare il calcolo dei sistemi
if (variable.isSolved()) {
List<Function> ret = new ArrayList<>();
ret.add(variable);
return ret;
}
return variable.solveOneStep(); return variable.solveOneStep();
} }

View File

@ -29,10 +29,7 @@ public class EmptyScreen extends Screen {
@Override @Override
public void beforeRender(float dt) { public void beforeRender(float dt) {
endLoading += dt;
if (PIDisplay.loading & endLoading >= 2.5) {
PIDisplay.loading = false;
}
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.*;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.warp.picalculator.Error; import org.warp.picalculator.Error;
@ -12,6 +13,7 @@ import org.warp.picalculator.Utils;
import org.warp.picalculator.device.PIDisplay; import org.warp.picalculator.device.PIDisplay;
import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.device.graphicengine.Display; import org.warp.picalculator.device.graphicengine.Display;
import org.warp.picalculator.device.graphicengine.Display.Render;
import org.warp.picalculator.device.graphicengine.Screen; import org.warp.picalculator.device.graphicengine.Screen;
import org.warp.picalculator.math.Calculator; import org.warp.picalculator.math.Calculator;
import org.warp.picalculator.math.functions.Function; import org.warp.picalculator.math.functions.Function;
@ -24,7 +26,7 @@ public class EquationScreen extends Screen {
public volatile int caretPos = 0; public volatile int caretPos = 0;
public volatile boolean showCaret = true; public volatile boolean showCaret = true;
public volatile float showCaretDelta = 0f; public volatile float showCaretDelta = 0f;
public Function f; public List<Function> f;
public List<Function> f2; public List<Function> f2;
public int ew1; public int ew1;
public int ew2; public int ew2;
@ -52,77 +54,71 @@ public class EquationScreen extends Screen {
@Override @Override
public void init() throws InterruptedException { public void init() throws InterruptedException {
try { /* Fine caricamento */
/* Fine caricamento */
// Parentesi f = new // Parentesi f = new
// Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)=19XZ"); // Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)=19XZ");
// PARENTESI CON CALCOLI // PARENTESI CON CALCOLI
// Funzione f = new Sottrazione(new Somma(new Parentesi("Ⓐ9/2+Ⓐ7/2", // Funzione f = new Sottrazione(new Somma(new Parentesi("Ⓐ9/2+Ⓐ7/2",
// "").calcola(), new Termine("3.5")), new // "").calcola(), new Termine("3.5")), new
// Parentesi("3*2√14","").calcola()); // Parentesi("3*2√14","").calcola());
// PARENTESI CON DUE NUMERI FRAZIONALI COMPLETI CON INCOGNITE: // PARENTESI CON DUE NUMERI FRAZIONALI COMPLETI CON INCOGNITE:
// Funzione f = new // Funzione f = new
// Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)", ""); // Parentesi("(Ⓐ(2X)*3Y)/(5Z^2)+(Ⓐ(11A)*13B)/(7CZ)", "");
// PARENTESI CON DUE NUMERI FRAZIONALI DISALLINEATI GRAFICAMENTE: // PARENTESI CON DUE NUMERI FRAZIONALI DISALLINEATI GRAFICAMENTE:
// Funzione f = new Parentesi("((5^2-1)/2)/5-5/(5/2)=2", ""); // Funzione f = new Parentesi("((5^2-1)/2)/5-5/(5/2)=2", "");
// TERMINE DI PROVA COMPLETO: // TERMINE DI PROVA COMPLETO:
// Funzione f = new Termine(new NumeroAvanzato(new Rational(3, 2), // Funzione f = new Termine(new NumeroAvanzato(new Rational(3, 2),
// new Rational(7, 1), new Incognite(new Incognita('X', // new Rational(7, 1), new Incognite(new Incognita('X',
// Rational.ONE)), new Incognite(new Incognita('Y', Rational.ONE)), // Rational.ONE)), new Incognite(new Incognita('Y', Rational.ONE)),
// new Incognite(new Incognita('z', Rational.ONE)))); // new Incognite(new Incognita('z', Rational.ONE))));
// PARENTESI REALISTICA CON INCOGNITE: // PARENTESI REALISTICA CON INCOGNITE:
// Funzione f = new Equazione(new // Funzione f = new Equazione(new
// Parentesi("X^2+(MX-M+4)^2-4X-4(MX-M+4)^2+7", ""), new // Parentesi("X^2+(MX-M+4)^2-4X-4(MX-M+4)^2+7", ""), new
// Termine("0")); // Termine("0"));
// POTENZA: // POTENZA:
// Funzione f = new Parentesi("(MX-M+4)^2", ""); // Funzione f = new Parentesi("(MX-M+4)^2", "");
// NUMERO SEMPLICE LUNGO: // NUMERO SEMPLICE LUNGO:
// Funzione f = new Parentesi("-1219999799999996934.42229", ""); // Funzione f = new Parentesi("-1219999799999996934.42229", "");
// : // :
// Funzione f = new Parentesi("5Y+XY=2", "") // Funzione f = new Parentesi("5Y+XY=2", "")
// calcola("((5^2+3√(100/0.1))+Ⓐ(7)+9/15*2√(26/2))/21"); // calcola("((5^2+3√(100/0.1))+Ⓐ(7)+9/15*2√(26/2))/21");
interpreta("0"); f = new ArrayList<Function>();
f2 = new ArrayList<Function>();
// interpreta("{(5X*(15X/3X))+(25X/(5X*(15X/3X)))=15{X=5"); //TODO RIMUOVERE // interpreta("{(5X*(15X/3X))+(25X/(5X*(15X/3X)))=15{X=5"); //TODO RIMUOVERE
// long start = System.nanoTime(); // long start = System.nanoTime();
// Termine result = // Termine result =
// Calculator.calcolarisultato("((5Ⓑ2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21"); // Calculator.calcolarisultato("((5Ⓑ2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21");
// long end = System.nanoTime(); // long end = System.nanoTime();
// long timeElapsed = end-start; // long timeElapsed = end-start;
// System.out.println("RESULT: " + result); // System.out.println("RESULT: " + result);
// System.out.println("DECIMAl RESULT: " + // System.out.println("DECIMAl RESULT: " +
// result.getTerm().toBigDecimal()); // result.getTerm().toBigDecimal());
// System.out.println("Time elapsed: " + (double) timeElapsed / // System.out.println("Time elapsed: " + (double) timeElapsed /
// 1000000 + " milliseconds\n"); // 1000000 + " milliseconds\n");
// //
// //
// start = System.nanoTime(); // start = System.nanoTime();
// RisultatoEquazione eresult = // RisultatoEquazione eresult =
// Calculator.calcolaequazione("((5Ⓑ2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21=(175*(2√7)+3*(2√13))/105"); // Calculator.calcolaequazione("((5Ⓑ2+3√(100/0.1))*Ⓐ7+9/15*2√(26/2))/21=(175*(2√7)+3*(2√13))/105");
// end = System.nanoTime(); // end = System.nanoTime();
// timeElapsed = end-start; // timeElapsed = end-start;
// System.out.println("Is an equation: " + eresult.isAnEquation); // System.out.println("Is an equation: " + eresult.isAnEquation);
// System.out.println("L-R: " + eresult.LR); // System.out.println("L-R: " + eresult.LR);
// System.out.println("Time elapsed: " + (double) timeElapsed / // System.out.println("Time elapsed: " + (double) timeElapsed /
// 1000000 + " milliseconds\n"); // 1000000 + " milliseconds\n");
} catch (Error e) {
glClearColor(0xFFDC3C32);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
PIDisplay.error = e.id.toString();
System.err.println(e.id);
}
} }
public void interpreta(String eqn) throws Error { public void interpreta(String eqn) throws Error {
equazioneCorrente = eqn; equazioneCorrente = eqn;
f = Calculator.parseString(equazioneCorrente.replace("sqrt", "").replace("^", "")); List<Function> fncs = new ArrayList<Function>();
f.generateGraphics(); fncs.add(Calculator.parseString(equazioneCorrente.replace("sqrt", "").replace("^", "")));
f = fncs;
for (Function f : f) {
f.generateGraphics();
}
} }
public void solve() throws Error { public void solve() throws Error {
@ -131,10 +127,6 @@ public class EquationScreen extends Screen {
@Override @Override
public void beforeRender(float dt) { public void beforeRender(float dt) {
endLoading += dt;
if (endLoading >= 1) {
PIDisplay.loading = false;
}
showCaretDelta += dt; showCaretDelta += dt;
if (showCaretDelta >= 0.5f) { if (showCaretDelta >= 0.5f) {
mustRefresh = true; mustRefresh = true;
@ -145,12 +137,17 @@ public class EquationScreen extends Screen {
@Override @Override
public void render() { public void render() {
setFont(PIDisplay.fonts[0]); Display.Render.setFont(Utils.getFont(false));
glClearColor(0xFFCCE7D4); glClearColor(0xFFCCE7D4);
glColor3f(0, 0, 0); glColor3f(0, 0, 0);
glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length())); glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length()));
if (f != null) if (f != null) {
f.draw(2, 22+1+9+1); int topSpacing = 0;
for (Function f : f) {
f.draw(2, 22+1+getFontHeight()+1+topSpacing);
topSpacing += f.getHeight() + 2;
}
}
if (f2 != null) { if (f2 != null) {
int bottomSpacing = 0; int bottomSpacing = 0;
for (Function f : f2) { for (Function f : f2) {
@ -330,6 +327,7 @@ public class EquationScreen extends Screen {
caretPos+=1; caretPos+=1;
showCaret = true; showCaret = true;
showCaretDelta = 0L; showCaretDelta = 0L;
f.clear();
} }
@Override @Override

View File

@ -0,0 +1,112 @@
package org.warp.picalculator.screens;
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
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.PIDisplay;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.device.graphicengine.Display;
import org.warp.picalculator.device.graphicengine.Screen;
import org.warp.picalculator.math.Calculator;
import org.warp.picalculator.math.functions.Function;
import static org.warp.picalculator.device.PIDisplay.fonts;
import static org.warp.picalculator.device.PIDisplay.glyphsHeight;
import static org.warp.picalculator.device.PIDisplay.colore;
public class LoadingScreen extends Screen {
public float endLoading;
boolean mustRefresh = true;
public float loadingTextTranslation = 0.0f;
public boolean loadingTextTranslationTopToBottom = true;
private boolean loading;
public LoadingScreen() {
super();
canBeInHistory = false;
}
@Override
public void created() throws InterruptedException {
endLoading = 0;
}
@Override
public void init() throws InterruptedException {
}
@Override
public void beforeRender(float dt) {
if (loadingTextTranslation >= 10.0f) {
loadingTextTranslation = 10.0f;
loadingTextTranslationTopToBottom = false;
} else if (loadingTextTranslation <= -10.0f) {
loadingTextTranslation = -10.0f;
loadingTextTranslationTopToBottom = true;
}
if (loadingTextTranslationTopToBottom) {
loadingTextTranslation += dt * 15;
} else {
loadingTextTranslation -= dt * 15;
}
endLoading += dt;
if (endLoading >= 1) {
loading = false;
PIDisplay.INSTANCE.setScreen(new EquationScreen());
}
mustRefresh = true;
}
@Override
public void render() {
setFont(fonts[2]);
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2) - 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2) + 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 - 1 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 1.0f, 1.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + 1 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(1.0f, 0.5f, 0.0f, 1.0f);
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
colore(0.0f, 0.0f, 0.0f, 0.75f);
setFont(fonts[0]);
glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 11, "LOADING");
setFont(fonts[1]);
colore(0.0f, 0.0f, 0.0f, 0.5f);
glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 22, "PLEASE WAIT...");
}
@Override
public boolean mustBeRefreshed() {
if (mustRefresh) {
mustRefresh = false;
return true;
} else {
return false;
}
}
@Override
public boolean keyPressed(Key k) {
return false;
}
@Override
public boolean keyReleased(Key k) {
return false;
}
}