Continued fixing some classes
This commit is contained in:
parent
d799c2cf7d
commit
ceb1304675
@ -34,12 +34,12 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class Cloner {
|
||||
private final IInstantiationStrategy instantiationStrategy;
|
||||
private final Set<Class<?>> ignored = new HashSet<Class<?>>();
|
||||
private final Set<Class<?>> ignoredInstanceOf = new HashSet<Class<?>>();
|
||||
private final Set<Class<?>> nullInstead = new HashSet<Class<?>>();
|
||||
private final Map<Class<?>, IFastCloner> fastCloners = new HashMap<Class<?>, IFastCloner>();
|
||||
private final Map<Object, Boolean> ignoredInstances = new IdentityHashMap<Object, Boolean>();
|
||||
private final ConcurrentHashMap<Class<?>, List<Field>> fieldsCache = new ConcurrentHashMap<Class<?>, List<Field>>();
|
||||
private final Set<Class<?>> ignored = new HashSet<>();
|
||||
private final Set<Class<?>> ignoredInstanceOf = new HashSet<>();
|
||||
private final Set<Class<?>> nullInstead = new HashSet<>();
|
||||
private final Map<Class<?>, IFastCloner> fastCloners = new HashMap<>();
|
||||
private final Map<Object, Boolean> ignoredInstances = new IdentityHashMap<>();
|
||||
private final ConcurrentHashMap<Class<?>, List<Field>> fieldsCache = new ConcurrentHashMap<>();
|
||||
|
||||
public IDumpCloned getDumpCloned() {
|
||||
return dumpCloned;
|
||||
@ -333,7 +333,7 @@ public class Cloner {
|
||||
if (dumpCloned != null) {
|
||||
dumpCloned.startCloning(o.getClass());
|
||||
}
|
||||
final Map<Object, Object> clones = new IdentityHashMap<Object, Object>(16);
|
||||
final Map<Object, Object> clones = new IdentityHashMap<>(16);
|
||||
try {
|
||||
return cloneInternal(o, clones);
|
||||
} catch (final IllegalAccessException e) {
|
||||
@ -349,7 +349,7 @@ public class Cloner {
|
||||
if (dumpCloned != null) {
|
||||
dumpCloned.startCloning(o.getClass());
|
||||
}
|
||||
final Map<Object, Object> clones = new IdentityHashMap<Object, Object>(16);
|
||||
final Map<Object, Object> clones = new IdentityHashMap<>(16);
|
||||
for (final Object dc : dontCloneThese) {
|
||||
clones.put(dc, dc);
|
||||
}
|
||||
@ -383,7 +383,7 @@ public class Cloner {
|
||||
}
|
||||
|
||||
// caches immutables for quick reference
|
||||
private final ConcurrentHashMap<Class<?>, Boolean> immutables = new ConcurrentHashMap<Class<?>, Boolean>();
|
||||
private final ConcurrentHashMap<Class<?>, Boolean> immutables = new ConcurrentHashMap<>();
|
||||
private boolean cloneAnonymousParent = true;
|
||||
|
||||
/**
|
||||
@ -602,7 +602,7 @@ public class Cloner {
|
||||
protected List<Field> allFields(final Class<?> c) {
|
||||
List<Field> l = fieldsCache.get(c);
|
||||
if (l == null) {
|
||||
l = new LinkedList<Field>();
|
||||
l = new LinkedList<>();
|
||||
final Field[] fields = c.getDeclaredFields();
|
||||
addAll(l, fields);
|
||||
Class<?> sc = c;
|
||||
|
@ -15,7 +15,7 @@ public class Bernoulli {
|
||||
/*
|
||||
* The list of all Bernoulli numbers as a vector, n=0,2,4,....
|
||||
*/
|
||||
static Vector<Rational> a = new Vector<Rational>();
|
||||
static Vector<Rational> a = new Vector<>();
|
||||
|
||||
public Bernoulli() {
|
||||
if (a.size() == 0) {
|
||||
|
@ -28,7 +28,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
* Creates the polynomial p(x)=0.
|
||||
*/
|
||||
public BigIntegerPoly() {
|
||||
a = new Vector<BigInteger>();
|
||||
a = new Vector<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,7 +38,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
* the string of the form a0,a1,a2,a3 with the coefficients
|
||||
*/
|
||||
public BigIntegerPoly(final String L) throws NumberFormatException {
|
||||
a = new Vector<BigInteger>();
|
||||
a = new Vector<>();
|
||||
Scanner sc = new Scanner(L);
|
||||
sc.useDelimiter(",");
|
||||
while (sc.hasNextBigInteger())
|
||||
@ -537,7 +537,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
*/
|
||||
public Vector<BigInteger> iroots() {
|
||||
/* The vector of the roots */
|
||||
Vector<BigInteger> res = new Vector<BigInteger>();
|
||||
Vector<BigInteger> res = new Vector<>();
|
||||
|
||||
/*
|
||||
* collect the zero
|
||||
@ -581,7 +581,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
/*
|
||||
* The vector of the factors to be returned
|
||||
*/
|
||||
Vector<BigIntegerPoly> res = new Vector<BigIntegerPoly>();
|
||||
Vector<BigIntegerPoly> res = new Vector<>();
|
||||
|
||||
if (degree() < 2)
|
||||
return res;
|
||||
@ -679,7 +679,7 @@ public class BigIntegerPoly implements Cloneable {
|
||||
/*
|
||||
* this ought be entirely rewritten in terms of the LLL algorithm
|
||||
*/
|
||||
Vector<BigIntegerPoly> fac = new Vector<BigIntegerPoly>();
|
||||
Vector<BigIntegerPoly> fac = new Vector<>();
|
||||
|
||||
/* collect integer roots (polynomial factors of degree 1) */
|
||||
Vector<BigInteger> r = iroots();
|
||||
|
@ -39,7 +39,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigSurdVec() {
|
||||
terms = new Vector<BigSurd>();
|
||||
terms = new Vector<>();
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigSurdVec(BigSurd a) {
|
||||
terms = new Vector<BigSurd>(1);
|
||||
terms = new Vector<>(1);
|
||||
terms.add(a);
|
||||
} /* ctor */
|
||||
|
||||
@ -64,7 +64,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigSurdVec(BigSurd a, BigSurd b) {
|
||||
terms = new Vector<BigSurd>(2);
|
||||
terms = new Vector<>(2);
|
||||
terms.add(a);
|
||||
terms.add(b);
|
||||
try {
|
||||
@ -90,7 +90,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
|
||||
if (terms.size() <= 1)
|
||||
return;
|
||||
|
||||
Vector<BigSurd> newter = new Vector<BigSurd>();
|
||||
Vector<BigSurd> newter = new Vector<>();
|
||||
newter.add(terms.firstElement());
|
||||
/*
|
||||
* add j-th element to the existing vector and combine were possible
|
||||
|
@ -14,7 +14,7 @@ public class Euler {
|
||||
/*
|
||||
* The list of all Euler numbers as a vector, n=0,2,4,....
|
||||
*/
|
||||
static protected Vector<BigInteger> a = new Vector<BigInteger>();
|
||||
static protected Vector<BigInteger> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* Ctor(). Fill the hash list initially with E_0 to E_3.
|
||||
|
@ -14,7 +14,7 @@ public class Factorial {
|
||||
/**
|
||||
* The list of all factorials as a vector.
|
||||
*/
|
||||
static Vector<Ifactor> a = new Vector<Ifactor>();
|
||||
static Vector<Ifactor> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* ctor().
|
||||
|
@ -45,7 +45,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
*/
|
||||
public Ifactor(int number) {
|
||||
n = new BigInteger("" + number);
|
||||
primeexp = new Vector<Integer>();
|
||||
primeexp = new Vector<>();
|
||||
if (number > 1) {
|
||||
int primindx = 0;
|
||||
Prime primes = new Prime();
|
||||
@ -86,7 +86,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
*/
|
||||
public Ifactor(BigInteger number) {
|
||||
n = number;
|
||||
primeexp = new Vector<Integer>();
|
||||
primeexp = new Vector<>();
|
||||
if (number.compareTo(BigInteger.ONE) == 0) {
|
||||
primeexp.add(new Integer(1));
|
||||
primeexp.add(new Integer(0));
|
||||
@ -125,7 +125,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
* continuous prime-smooth basis.
|
||||
*/
|
||||
public Ifactor(Vector<Integer> pows) {
|
||||
primeexp = new Vector<Integer>(2 * pows.size());
|
||||
primeexp = new Vector<>(2 * pows.size());
|
||||
if (pows.size() > 0) {
|
||||
n = BigInteger.ONE;
|
||||
Prime primes = new Prime();
|
||||
@ -512,7 +512,7 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
|
||||
* multiplied
|
||||
* by 1 or by a product that contains the factors p1..py.
|
||||
*/
|
||||
Vector<BigInteger> d = new Vector<BigInteger>();
|
||||
Vector<BigInteger> d = new Vector<>();
|
||||
if (n.compareTo(BigInteger.ZERO) == 0)
|
||||
return d;
|
||||
d.add(BigInteger.ONE);
|
||||
|
@ -13,7 +13,7 @@ public class PartitionsP {
|
||||
/**
|
||||
* The list of all partitions as a vector.
|
||||
*/
|
||||
static protected Vector<BigInteger> a = new Vector<BigInteger>();
|
||||
static protected Vector<BigInteger> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* The maximum integer covered by the high end of the list.
|
||||
|
@ -21,7 +21,7 @@ public class Prime {
|
||||
/**
|
||||
* The list of all numbers as a vector.
|
||||
*/
|
||||
static Vector<BigInteger> a = new Vector<BigInteger>();
|
||||
static Vector<BigInteger> a = new Vector<>();
|
||||
|
||||
/**
|
||||
* The maximum integer covered by the high end of the list.
|
||||
|
@ -31,7 +31,7 @@ class RatPoly {
|
||||
* Initializes the zero-valued polynomial x=0.
|
||||
*/
|
||||
public RatPoly() {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
@ -42,7 +42,7 @@ class RatPoly {
|
||||
* is created.
|
||||
*/
|
||||
public RatPoly(final Vector<Rational> L) {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
for (int i = 0; i < L.size(); i++)
|
||||
a.add(L.elementAt(i).clone());
|
||||
simplify();
|
||||
@ -55,7 +55,7 @@ class RatPoly {
|
||||
* the string of the form a0,a1,a2,a3 with the coefficients
|
||||
*/
|
||||
public RatPoly(final String L) throws NumberFormatException {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
Scanner sc = new Scanner(L);
|
||||
sc.useDelimiter(",");
|
||||
while (sc.hasNext()) {
|
||||
@ -129,7 +129,7 @@ class RatPoly {
|
||||
* @since 2008-11-13
|
||||
*/
|
||||
protected void init(final Vector<BigInteger> A, final Vector<BigInteger> B, int nmax) throws Error {
|
||||
a = new Vector<Rational>();
|
||||
a = new Vector<>();
|
||||
Factorial f = new Factorial();
|
||||
for (int n = 0; n <= nmax; n++) {
|
||||
Rational c = new Rational(1, 1);
|
||||
@ -888,7 +888,7 @@ class RatPoly {
|
||||
Random rand = new Random();
|
||||
MathContext mc = new MathContext(digits + 3, RoundingMode.DOWN);
|
||||
|
||||
Vector<BigComplex> res = new Vector<BigComplex>();
|
||||
Vector<BigComplex> res = new Vector<>();
|
||||
|
||||
final int d = mon.degree();
|
||||
double randRad = 0.;
|
||||
@ -918,7 +918,7 @@ class RatPoly {
|
||||
for (; !convr;)// ORIGINAL LINE: for(int itr =0 ; ! convr ; itr++)
|
||||
{
|
||||
convr = true;
|
||||
Vector<BigComplex> resPlus = new Vector<BigComplex>();
|
||||
Vector<BigComplex> resPlus = new Vector<>();
|
||||
for (int v = 0; v < d; v++) {
|
||||
/*
|
||||
* evaluate f(x)/(x-root1)/(x-root2)/... (x-rootdegr), Newton
|
||||
@ -959,7 +959,7 @@ class RatPoly {
|
||||
*/
|
||||
public Vector<BigInteger> iroots() {
|
||||
/* The vector of the roots */
|
||||
Vector<BigInteger> res = new Vector<BigInteger>();
|
||||
Vector<BigInteger> res = new Vector<>();
|
||||
|
||||
int lowd = ldegree();
|
||||
if (lowd == 0 && a.elementAt(0).compareTo(BigInteger.ZERO) == 0) {
|
||||
@ -984,7 +984,7 @@ class RatPoly {
|
||||
* and eventually get the integer polynomial by ignoring the
|
||||
* denominators
|
||||
*/
|
||||
Vector<BigInteger> ipo = new Vector<BigInteger>();
|
||||
Vector<BigInteger> ipo = new Vector<>();
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
BigInteger d = a.elementAt(i).a.multiply(lcmDeno).divide(a.elementAt(i).b);
|
||||
ipo.add(d);
|
||||
|
@ -2,7 +2,6 @@ package org.warp.picalculator;
|
||||
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.screens.KeyboardDebugScreen;
|
||||
import org.warp.picalculator.screens.LoadingScreen;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
|
@ -10,7 +10,6 @@ import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.BigDecimalMath;
|
||||
|
@ -1,16 +1,11 @@
|
||||
package org.warp.picalculator.device;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.chip.ParallelToSerial;
|
||||
import org.warp.picalculator.device.chip.SerialToParallel;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.screens.KeyboardDebugScreen;
|
||||
import org.warp.picalculator.screens.MarioScreen;
|
||||
|
||||
|
@ -23,9 +23,6 @@ import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
|
||||
/**
|
||||
@ -322,7 +319,7 @@ public final class PIDisplay {
|
||||
if (error != null) {
|
||||
glSetFont(Utils.getFont(false, false));
|
||||
glColor3i(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]- PIDisplay.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR");
|
||||
glColor3i(149, 32, 26);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), 22, error);
|
||||
glColor3i(164, 34, 28);
|
||||
|
@ -179,7 +179,7 @@ public class Display {
|
||||
newColor = skin[(s0 + texx) + (t0 + texy) * skinwidth];
|
||||
if (transparent) {
|
||||
oldColor = canvas2d[(x0 + texx*onex + width) + (y0 + texy*oney + height) * size[0]];
|
||||
float a2 = ((float)(newColor >> 24 & 0xFF)) / 255f;
|
||||
float a2 = (newColor >> 24 & 0xFF) / 255f;
|
||||
float a1 = 1f-a2;
|
||||
int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
|
||||
int g = (int) ((oldColor >> 8 & 0xFF) * a1 + (newColor >> 8 & 0xFF) * a2);
|
||||
|
@ -166,7 +166,7 @@ public class RAWFont {
|
||||
j = x + cpos + dx;
|
||||
if (j > 0 & j < screenSize[0]) {
|
||||
int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor((double)bit)/((double)intBits));
|
||||
currentInt = (int) (Math.floor(bit)/(intBits));
|
||||
currentIntBitPosition = bit-(currentInt*intBits);
|
||||
bitData = (chars32[charIndex*charIntCount+currentInt] >> currentIntBitPosition) & 1;
|
||||
screenPos = x + cpos + dx + (y + dy) * screenSize[0];
|
||||
|
@ -2,30 +2,31 @@ package org.warp.picalculator.math;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
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.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.equations.EquationsSystem;
|
||||
import org.warp.picalculator.screens.MathInputScreen;
|
||||
import org.warp.picalculator.screens.SolveEquationScreen;
|
||||
|
||||
public class Calculator {
|
||||
|
||||
public AngleMode angleMode = AngleMode.DEG;
|
||||
public boolean exactMode = false;
|
||||
public ArrayList<Function> f;
|
||||
public ArrayList<Function> f2;
|
||||
public ArrayList<VariableValue> variablesValues;
|
||||
public int resultsCount;
|
||||
|
||||
public Calculator() {
|
||||
f = new ArrayList<>();
|
||||
f2 = new ArrayList<>();
|
||||
variablesValues = new ArrayList<>();
|
||||
resultsCount = 0;
|
||||
}
|
||||
|
||||
public Function parseString(String string) throws Error {
|
||||
@ -34,7 +35,7 @@ public class Calculator {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
String[] parts = string.substring(1).split("\\{");
|
||||
EquationsSystem s = new EquationsSystem(null);
|
||||
EquationsSystem s = new EquationsSystem(this);
|
||||
for (String part : parts) {
|
||||
s.addFunctionToEnd(parseEquationString(part));
|
||||
}
|
||||
@ -42,21 +43,21 @@ public class Calculator {
|
||||
} else if (string.contains("=")) {
|
||||
return parseEquationString(string);
|
||||
} else {
|
||||
return new Expression(null, string);
|
||||
return new Expression(this, string);
|
||||
}
|
||||
}
|
||||
|
||||
public Function parseEquationString(String string) throws Error {
|
||||
String[] parts = string.split("=");
|
||||
if (parts.length == 1) {
|
||||
Equation e = new Equation(null, null, null);
|
||||
e.setVariable1(new Expression(e, parts[0]));
|
||||
e.setVariable2(new Number(e, BigInteger.ZERO));
|
||||
Equation e = new Equation(this, null, null);
|
||||
e.setVariable1(new Expression(this, parts[0]));
|
||||
e.setVariable2(new Number(this, BigInteger.ZERO));
|
||||
return e;
|
||||
} else if (parts.length == 2) {
|
||||
Equation e = new Equation(null, null, null);
|
||||
e.setVariable1(new Expression(e, parts[0]));
|
||||
e.setVariable2(new Expression(e, parts[1]));
|
||||
Equation e = new Equation(this, null, null);
|
||||
e.setVariable1(new Expression(this, parts[0]));
|
||||
e.setVariable2(new Expression(this, parts[1]));
|
||||
return e;
|
||||
} else {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
@ -85,13 +86,45 @@ public class Calculator {
|
||||
partialResults.add(itm);
|
||||
}
|
||||
}
|
||||
results = new ArrayList<Function>(partialResults);
|
||||
results = new ArrayList<>(partialResults);
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public Function getChild() {
|
||||
return f.get(0);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
if (f == null & f2 == null) {
|
||||
f = new ArrayList<>();
|
||||
f2 = new ArrayList<>();
|
||||
variablesValues = new ArrayList<>();
|
||||
resultsCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void parseInputString(String eqn) throws Error {
|
||||
ArrayList<Function> fncs = new ArrayList<>();
|
||||
if (eqn.length() > 0) {
|
||||
try {
|
||||
fncs.add(parseString(eqn.replace("sqrt", "Ⓐ").replace("^", "Ⓑ")));
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
f = fncs;
|
||||
for (Function f : f) {
|
||||
try {
|
||||
f.generateGraphics();
|
||||
} catch (NullPointerException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*public void solve(EquationScreen equationScreen, char letter) throws Error {
|
||||
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
|
||||
|
@ -3,25 +3,30 @@ package org.warp.picalculator.math.functions;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class AnteriorFunction implements Function {
|
||||
public AnteriorFunction(Function parent, Function value) {
|
||||
setParent(parent);
|
||||
setVariable(value);
|
||||
public AnteriorFunction(Function value) {
|
||||
this.root = value.getRoot();
|
||||
variable = value;
|
||||
}
|
||||
|
||||
protected abstract Function NewInstance(Function parent2, Function f);
|
||||
|
||||
protected Function parent;
|
||||
protected Function variable = new Number(null, BigInteger.ZERO);
|
||||
public AnteriorFunction(Calculator root, Function value) {
|
||||
this.root = root;
|
||||
variable = value;
|
||||
}
|
||||
|
||||
protected abstract Function NewInstance(Calculator root, Function value);
|
||||
|
||||
protected final Calculator root;
|
||||
protected Function variable;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
@ -35,13 +40,9 @@ public abstract class AnteriorFunction implements Function {
|
||||
variable = value;
|
||||
}
|
||||
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
@Override
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,7 +56,7 @@ public abstract class AnteriorFunction implements Function {
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
|
||||
ArrayList<Function> l1 = new ArrayList<Function>();
|
||||
ArrayList<Function> l1 = new ArrayList<>();
|
||||
if (variable.isSolved()) {
|
||||
l1.add(variable);
|
||||
} else {
|
||||
@ -63,7 +64,7 @@ public abstract class AnteriorFunction implements Function {
|
||||
}
|
||||
|
||||
for (Function f : l1) {
|
||||
result.add(NewInstance(this.parent, (Function)f));
|
||||
result.add(NewInstance(this.root, f));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,13 +18,13 @@ import org.warp.picalculator.math.rules.UndefinedRule2;
|
||||
|
||||
public class Division extends FunctionTwoValues {
|
||||
|
||||
public Division(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Division(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Division(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Division(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,7 +39,7 @@ public class Division extends FunctionTwoValues {
|
||||
if (FractionsRule2.compare(this)) return true;
|
||||
if (FractionsRule3.compare(this)) return true;
|
||||
if (UndefinedRule2.compare(this)) return true;
|
||||
if (variable1 instanceof Number && variable2 instanceof Number && Calculator.exactMode == false) {
|
||||
if (variable1 instanceof Number && variable2 instanceof Number && root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -56,8 +56,8 @@ public class Division extends FunctionTwoValues {
|
||||
result = FractionsRule3.execute(this);
|
||||
} else if (UndefinedRule2.compare(this)) {
|
||||
result = UndefinedRule2.execute(this);
|
||||
} else if (variable1 instanceof Number && variable2 instanceof Number && Calculator.exactMode == false) {
|
||||
result.add(((Number)variable1).divide((Number)variable2).setParent(parent));
|
||||
} else if (variable1 instanceof Number && variable2 instanceof Number && root.exactMode == false) {
|
||||
result.add(((Number)variable1).divide((Number)variable2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -5,10 +5,15 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public class EmptyNumber implements Function {
|
||||
|
||||
public static EmptyNumber emptyNumber = new EmptyNumber();
|
||||
public EmptyNumber(Calculator root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
private final Calculator root;
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
@ -52,13 +57,8 @@ public class EmptyNumber implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParent(Function parent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return null;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean small = false;
|
||||
|
@ -13,6 +13,7 @@ import java.util.regex.Pattern;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcCosine;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcSine;
|
||||
@ -23,30 +24,29 @@ import org.warp.picalculator.math.functions.trigonometry.Tangent;
|
||||
|
||||
public class Expression extends FunctionMultipleValues {
|
||||
|
||||
public Expression(Function parent) {
|
||||
super(parent);
|
||||
public Expression(Calculator root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
public Expression(Function parent, Function[] values) {
|
||||
super(parent, values);
|
||||
public Expression(Calculator root, Function[] values) {
|
||||
super(root, values);
|
||||
}
|
||||
|
||||
private boolean initialParenthesis = false;
|
||||
|
||||
public Expression(Function parent, String string) throws Error {
|
||||
this(parent, string, "", true);
|
||||
public Expression(Calculator root, String string) throws Error {
|
||||
this(root, string, "", true);
|
||||
}
|
||||
|
||||
public Expression(Function parent, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
public Expression(Calculator root, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
||||
super(root);
|
||||
this.initialParenthesis = initialParenthesis;
|
||||
boolean isNumber = false;
|
||||
|
||||
// Determine if the expression is already a number:
|
||||
// Determina se l'espressione è già un numero:
|
||||
try {
|
||||
new Number(this, string);
|
||||
new Number(root, string);
|
||||
isNumber = true;
|
||||
} catch (NumberFormatException ex) {
|
||||
isNumber = false;
|
||||
@ -60,7 +60,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (isNumber){
|
||||
// If the expression is already a number:
|
||||
// Se l'espressione è già un numero:
|
||||
Number t = new Number(this, string);
|
||||
Number t = new Number(root, string);
|
||||
setVariables(new Function[] { t });
|
||||
Utils.debug.println(debugSpaces + "•Result:" + t.toString());
|
||||
} else {
|
||||
@ -211,7 +211,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
debugSpaces += " ";
|
||||
|
||||
// Convert the expression to a list of objects
|
||||
Expression imputRawParenthesis = new Expression(this);
|
||||
Expression imputRawParenthesis = new Expression(root);
|
||||
imputRawParenthesis.setVariables(new Function[] {});
|
||||
String tmp = "";
|
||||
final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
|
||||
@ -225,49 +225,49 @@ public class Expression extends FunctionMultipleValues {
|
||||
Function f = null;
|
||||
switch (charI) {
|
||||
case MathematicalSymbols.SUM:
|
||||
f = new Sum(this, null, null);
|
||||
f = new Sum(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SUM_SUBTRACTION:
|
||||
f = new SumSubtraction(this, null, null);
|
||||
f = new SumSubtraction(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SUBTRACTION:
|
||||
f = new Subtraction(this, null, null);
|
||||
f = new Subtraction(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.MINUS:
|
||||
f = new Negative(this, null);
|
||||
f = new Negative(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.MULTIPLICATION:
|
||||
f = new Multiplication(this, null, null);
|
||||
f = new Multiplication(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.DIVISION:
|
||||
f = new Division(this, null, null);
|
||||
f = new Division(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.NTH_ROOT:
|
||||
f = new Root(this, null, null);
|
||||
f = new Root(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SQUARE_ROOT:
|
||||
f = new RootSquare(this, null);
|
||||
f = new RootSquare(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.POWER:
|
||||
f = new Power(this, null, null);
|
||||
f = new Power(root, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.SINE:
|
||||
f = new Sine(this, null);
|
||||
f = new Sine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.COSINE:
|
||||
f = new Cosine(this, null);
|
||||
f = new Cosine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.TANGENT:
|
||||
f = new Tangent(this, null);
|
||||
f = new Tangent(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.ARC_SINE:
|
||||
f = new ArcSine(this, null);
|
||||
f = new ArcSine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.ARC_COSINE:
|
||||
f = new ArcCosine(this, null);
|
||||
f = new ArcCosine(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.ARC_TANGENT:
|
||||
f = new ArcTangent(this, null);
|
||||
f = new ArcTangent(root, null);
|
||||
break;
|
||||
case MathematicalSymbols.PARENTHESIS_OPEN:
|
||||
// Find the last closed parenthesis
|
||||
@ -300,15 +300,16 @@ public class Expression extends FunctionMultipleValues {
|
||||
tmpExpr += processExpression.charAt(i);
|
||||
i++;
|
||||
}
|
||||
f = new Expression(this, tmpExpr, debugSpaces, false);
|
||||
f = new Expression(root, tmpExpr, debugSpaces, false);
|
||||
break;
|
||||
default:
|
||||
if (Utils.isInArray(charI, MathematicalSymbols.variables())) {
|
||||
f = new Variable(this, charI);
|
||||
f = new Variable(root, charI);
|
||||
} else {
|
||||
if (charI == "(" || charI == ")") {
|
||||
throw new Error(Errors.UNBALANCED_BRACKETS);
|
||||
} else {
|
||||
System.err.println("Unexpected character while parsing expression: " + charI);
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
// throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!");
|
||||
@ -319,28 +320,28 @@ public class Expression extends FunctionMultipleValues {
|
||||
} else if (f instanceof Variable) {
|
||||
if (imputRawParenthesis.getVariablesLength() == 0) {
|
||||
if (tmp.length() > 0) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
||||
}
|
||||
} else {
|
||||
Function precedentFunction = imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1);
|
||||
if (tmp.length() > 0) {
|
||||
if (precedentFunction instanceof Number || precedentFunction instanceof Variable) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
||||
}
|
||||
if (tmp.equals("-")) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Subtraction(this, null, null));
|
||||
imputRawParenthesis.addFunctionToEnd(new Subtraction(root, null, null));
|
||||
} else {
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
}
|
||||
}
|
||||
if (tmp.length() > 0 || (precedentFunction instanceof Number || precedentFunction instanceof Variable)) {
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Multiplication(root, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added multiplication to expression:" + new Multiplication(root, null, null).getSymbol());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -350,7 +351,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
tmp = "-1";
|
||||
}
|
||||
}
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
}
|
||||
}
|
||||
@ -373,7 +374,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (tmp.length() > 0) {
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
|
||||
try {
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(root, tmp));
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
@ -406,7 +407,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
Utils.debug.println(debugSpaces + "•Pushing classes...");
|
||||
|
||||
Function[] oldFunctionsArray = imputRawParenthesis.getVariables();
|
||||
ArrayList<Function> oldFunctionsList = new ArrayList<Function>();
|
||||
ArrayList<Function> oldFunctionsList = new ArrayList<>();
|
||||
for (int i = 0; i < oldFunctionsArray.length; i++) {
|
||||
Function funzione = oldFunctionsArray[i];
|
||||
if (funzione != null) {
|
||||
@ -417,7 +418,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
oldFunctionsArray[i-1] = null;
|
||||
oldFunctionsList.remove(oldFunctionsList.size()-1);
|
||||
i -= 1;
|
||||
funzione = new RootSquare(this, null);
|
||||
funzione = new RootSquare(root, null);
|
||||
}
|
||||
}
|
||||
//Aggiunta della funzione alla lista grezza
|
||||
@ -448,7 +449,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
System.out.println("WARN: ---> POSSIBILE ERRORE????? <---");// BOH
|
||||
// throw new Errore(Errori.SYNTAX_ERROR);
|
||||
while (oldFunctionsList.size() > 1) {
|
||||
oldFunctionsList.set(0, new Multiplication(this, oldFunctionsList.get(0), oldFunctionsList.remove(1)));
|
||||
oldFunctionsList.set(0, new Multiplication(root, oldFunctionsList.get(0), oldFunctionsList.remove(1)));
|
||||
}
|
||||
}
|
||||
Utils.debug.println(debugSpaces + " •Phase: "+step);
|
||||
@ -512,8 +513,8 @@ public class Expression extends FunctionMultipleValues {
|
||||
change = true;
|
||||
|
||||
if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) {
|
||||
((FunctionTwoValues) funzioneTMP).setVariable1((Function) oldFunctionsList.get(i - 1));
|
||||
((FunctionTwoValues) funzioneTMP).setVariable2((Function) oldFunctionsList.get(i + 1));
|
||||
((FunctionTwoValues) funzioneTMP).setVariable1(oldFunctionsList.get(i - 1));
|
||||
((FunctionTwoValues) funzioneTMP).setVariable2(oldFunctionsList.get(i + 1));
|
||||
oldFunctionsList.set(i, funzioneTMP);
|
||||
|
||||
// è importante togliere prima gli elementi
|
||||
@ -546,7 +547,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
|
||||
} else {
|
||||
change = true;
|
||||
((AnteriorFunction) funzioneTMP).setVariable((Function) nextFunc);
|
||||
((AnteriorFunction) funzioneTMP).setVariable(nextFunc);
|
||||
oldFunctionsList.set(i, funzioneTMP);
|
||||
|
||||
// è importante togliere prima gli elementi in
|
||||
@ -580,7 +581,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
} while (((oldFunctionsList.size() != before || step != "sums") && oldFunctionsList.size() > 1));
|
||||
}
|
||||
if(oldFunctionsList.isEmpty()) {
|
||||
setVariables(new Function[]{new Number(this, 0)});
|
||||
setVariables(new Function[]{new Number(root, 0)});
|
||||
} else {
|
||||
setVariables(oldFunctionsList);
|
||||
}
|
||||
@ -630,7 +631,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (f instanceof Number || f instanceof Variable) {
|
||||
ret.add(f);
|
||||
} else {
|
||||
ret.add(new Expression(this, new Function[]{(Function) f}));
|
||||
ret.add(new Expression(root, new Function[]{f}));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -640,7 +641,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (f.isSolved() == false) {
|
||||
List<Function> partial = f.solveOneStep();
|
||||
for (Function fnc : partial) {
|
||||
ret.add(new Expression(this, new Function[]{(Function) fnc}));
|
||||
ret.add(new Expression(root, new Function[]{fnc}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -662,7 +663,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
|
||||
public boolean parenthesisNeeded() {
|
||||
boolean parenthesisneeded = true;
|
||||
if (parent == null || initialParenthesis || parent instanceof Division) {
|
||||
if (initialParenthesis) {
|
||||
parenthesisneeded = false;
|
||||
} else {
|
||||
if (functions.length == 1) {
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public interface Function {
|
||||
public String getSymbol();
|
||||
@ -21,9 +22,7 @@ public interface Function {
|
||||
|
||||
public int getLine();
|
||||
|
||||
public Function setParent(Function parent);
|
||||
|
||||
public Function getParent();
|
||||
public Calculator getRoot();
|
||||
|
||||
public void setSmall(boolean small);
|
||||
|
||||
|
@ -3,20 +3,31 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class FunctionMultipleValues implements Function {
|
||||
public FunctionMultipleValues(Function parent) {
|
||||
setParent(parent);
|
||||
setVariables(new Function[] {});
|
||||
public FunctionMultipleValues(Calculator root) {
|
||||
this.root = root;
|
||||
functions = new Function[] {};
|
||||
}
|
||||
|
||||
public FunctionMultipleValues(Function parent, Function[] values) {
|
||||
setParent(parent);
|
||||
setVariables(values);
|
||||
public FunctionMultipleValues(Function[] values) {
|
||||
if (values.length > 0) {
|
||||
this.root = values[0].getRoot();
|
||||
} else {
|
||||
throw new NullPointerException("Nessun elemento nell'array. Impossibile ricavare il nodo root");
|
||||
}
|
||||
functions = values;
|
||||
}
|
||||
|
||||
protected Function parent;
|
||||
public FunctionMultipleValues(Calculator root, Function[] values) {
|
||||
this.root = root;
|
||||
functions = values;
|
||||
}
|
||||
|
||||
protected final Calculator root;
|
||||
protected Function[] functions;
|
||||
protected int width;
|
||||
protected int height;
|
||||
@ -27,34 +38,28 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
return functions;
|
||||
}
|
||||
|
||||
public void setVariables(Function[] value) {
|
||||
for (Function f : value) {
|
||||
f.setParent(this);
|
||||
}
|
||||
functions = value;
|
||||
}
|
||||
|
||||
public void setVariables(final List<Function> value) {
|
||||
int vsize = value.size();
|
||||
Function[] tmp = new Function[vsize];
|
||||
for (int i = 0; i < vsize; i++) {
|
||||
tmp[i] = value.get(i);
|
||||
tmp[i].setParent(this);
|
||||
}
|
||||
functions = tmp;
|
||||
}
|
||||
|
||||
public void setVariables(final Function[] value) {
|
||||
functions = value;
|
||||
}
|
||||
|
||||
public Function getVariable(int index) {
|
||||
return functions[index];
|
||||
}
|
||||
|
||||
public void setVariable(int index, Function value) {
|
||||
value.setParent(this);
|
||||
functions[index] = value;
|
||||
}
|
||||
|
||||
public void addFunctionToEnd(Function value) {
|
||||
value.setParent(this);
|
||||
int index = functions.length;
|
||||
setVariablesLength(index + 1);
|
||||
functions[index] = value;
|
||||
@ -83,14 +88,9 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
@Override
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,19 +8,20 @@ import java.util.ArrayList;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public abstract class FunctionTwoValues implements Function {
|
||||
public FunctionTwoValues(Function parent, Function value1, Function value2) {
|
||||
this.parent = parent;
|
||||
public FunctionTwoValues(Calculator root, Function value1, Function value2) {
|
||||
this.root = root;
|
||||
variable1 = value1;
|
||||
variable2 = value2;
|
||||
}
|
||||
|
||||
protected abstract Function NewInstance(Function parent2, Function value1, Function value2);
|
||||
protected abstract Function NewInstance(Calculator root, Function value1, Function value2);
|
||||
|
||||
protected Function parent;
|
||||
protected final Calculator root;
|
||||
|
||||
protected Function variable1 = null;
|
||||
protected Function variable2 = null;
|
||||
@ -34,25 +35,19 @@ public abstract class FunctionTwoValues implements Function {
|
||||
}
|
||||
|
||||
public void setVariable1(Function value) {
|
||||
value.setParent(this);
|
||||
variable1 = value;
|
||||
}
|
||||
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
@Override
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Function getVariable2() {
|
||||
return variable2;
|
||||
}
|
||||
|
||||
public void setVariable2(Function value) {
|
||||
value.setParent(this);
|
||||
variable2 = value;
|
||||
}
|
||||
|
||||
@ -74,8 +69,8 @@ public abstract class FunctionTwoValues implements Function {
|
||||
if (result == null || result.isEmpty()) {
|
||||
result = new ArrayList<>();
|
||||
|
||||
ArrayList<Function> l1 = new ArrayList<Function>();
|
||||
ArrayList<Function> l2 = new ArrayList<Function>();
|
||||
ArrayList<Function> l1 = new ArrayList<>();
|
||||
ArrayList<Function> l2 = new ArrayList<>();
|
||||
if (variable1.isSolved()) {
|
||||
l1.add(variable1);
|
||||
} else {
|
||||
@ -90,7 +85,7 @@ public abstract class FunctionTwoValues implements Function {
|
||||
Function[][] results = Utils.joinFunctionsResults(l1, l2);
|
||||
|
||||
for (Function[] f : results) {
|
||||
result.add(NewInstance(this.parent, (Function)f[0], (Function)f[1]));
|
||||
result.add(NewInstance(this.root, f[0], f[1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public class Joke implements Function {
|
||||
|
||||
@ -16,8 +17,10 @@ public class Joke implements Function {
|
||||
private static final String[] jokes = new String[]{"♓", "TORNADO", "SHARKNADO"};
|
||||
private static final int[] jokesFont = new int[]{4, -1, -1};
|
||||
private final byte joke;
|
||||
private final Calculator root;
|
||||
|
||||
public Joke(byte joke) {
|
||||
public Joke(Calculator root, byte joke) {
|
||||
this.root = root;
|
||||
this.joke = joke;
|
||||
}
|
||||
|
||||
@ -75,15 +78,10 @@ public class Joke implements Function {
|
||||
public int getLine() {
|
||||
return getHeight()/2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParent(Function value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return null;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean small = false;
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule15;
|
||||
import org.warp.picalculator.math.rules.NumberRule1;
|
||||
@ -13,8 +14,8 @@ import org.warp.picalculator.math.rules.methods.MultiplicationMethod1;
|
||||
|
||||
public class Multiplication extends FunctionTwoValues {
|
||||
|
||||
public Multiplication(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Multiplication(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
if (value1 instanceof Variable && value2 instanceof Variable == false) {
|
||||
variable1 = value2;
|
||||
variable2 = value1;
|
||||
@ -22,8 +23,8 @@ public class Multiplication extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Multiplication(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Multiplication(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,19 +6,20 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
|
||||
public class Negative extends AnteriorFunction {
|
||||
|
||||
public Negative(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Negative(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Negative(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Negative(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,6 +45,7 @@ public class Negative extends AnteriorFunction {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
if (variable == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
@ -56,7 +58,7 @@ public class Negative extends AnteriorFunction {
|
||||
} else if (variable.isSolved()) {
|
||||
try {
|
||||
Number var = (Number) getVariable();
|
||||
result.add(var.multiply(new Number(null, "-1")));
|
||||
result.add(var.multiply(new Number(root, "-1")));
|
||||
} catch(NullPointerException ex) {
|
||||
throw new Error(Errors.ERROR);
|
||||
} catch(NumberFormatException ex) {
|
||||
@ -65,7 +67,7 @@ public class Negative extends AnteriorFunction {
|
||||
throw new Error(Errors.NUMBER_TOO_SMALL);
|
||||
}
|
||||
} else {
|
||||
ArrayList<Function> l1 = new ArrayList<Function>();
|
||||
ArrayList<Function> l1 = new ArrayList<>();
|
||||
if (variable.isSolved()) {
|
||||
l1.add(variable);
|
||||
} else {
|
||||
@ -73,7 +75,7 @@ public class Negative extends AnteriorFunction {
|
||||
}
|
||||
|
||||
for (Function f : l1) {
|
||||
result.add(new Negative(this.parent, (Function)f));
|
||||
result.add(new Negative(root, f));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -20,37 +20,37 @@ import com.rits.cloning.Cloner;
|
||||
|
||||
public class Number implements Function {
|
||||
|
||||
private Function parent;
|
||||
private final Calculator root;
|
||||
protected BigDecimal term;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected boolean small;
|
||||
|
||||
public Number(Calculator calc, Function parent, BigInteger val) {
|
||||
this.parent = parent;
|
||||
public Number(Calculator root, BigInteger val) {
|
||||
this.root = root;
|
||||
term = new BigDecimal(val).setScale(Utils.scale, Utils.scaleMode2);
|
||||
}
|
||||
|
||||
public Number(Function parent, BigDecimal val) {
|
||||
this.parent = parent;
|
||||
public Number(Calculator root, BigDecimal val) {
|
||||
this.root = root;
|
||||
term = val.setScale(Utils.scale, Utils.scaleMode2);
|
||||
}
|
||||
|
||||
public Number(Function parent, String s) throws Error {
|
||||
this(parent, new BigInteger(s));
|
||||
public Number(Calculator root, String s) throws Error {
|
||||
this(root, new BigDecimal(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public Number(Function parent, int s) {
|
||||
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
public Number(Calculator root, int s) {
|
||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public Number(Function parent, float s) {
|
||||
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
public Number(Calculator root, float s) {
|
||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public Number(Function parent, double s) {
|
||||
this(parent, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
public Number(Calculator root, double s) {
|
||||
this(root, BigDecimal.valueOf(s).setScale(Utils.scale, Utils.scaleMode2));
|
||||
}
|
||||
|
||||
public BigDecimal getTerm() {
|
||||
@ -74,26 +74,26 @@ public class Number implements Function {
|
||||
}
|
||||
|
||||
public Number add(Number f) {
|
||||
Number ret = new Number(this.parent, getTerm().add(f.getTerm()));
|
||||
Number ret = new Number(this.root, getTerm().add(f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number multiply(Number f) {
|
||||
Number ret = new Number(this.parent, getTerm().multiply(f.getTerm()));
|
||||
Number ret = new Number(this.root, getTerm().multiply(f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number divide(Number f) throws Error {
|
||||
Number ret = new Number(this.parent, BigDecimalMath.divideRound(getTerm(), f.getTerm()));
|
||||
Number ret = new Number(this.root, BigDecimalMath.divideRound(getTerm(), f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number pow(Number f) throws Error {
|
||||
Number ret = new Number(this.parent, BigDecimal.ONE);
|
||||
Number ret = new Number(this.root, BigDecimal.ONE);
|
||||
if (Utils.isIntegerValue(f.term)) {
|
||||
final BigInteger bi = f.term.toBigInteger();
|
||||
for (BigInteger i = BigInteger.ZERO; i.compareTo(bi) < 0; i = i.add(BigInteger.ONE)) {
|
||||
ret = ret.multiply(new Number(this.parent, getTerm()));
|
||||
ret = ret.multiply(new Number(this.root, getTerm()));
|
||||
}
|
||||
} else {
|
||||
ret.term = BigDecimalMath.pow(term, f.term);
|
||||
@ -113,7 +113,7 @@ public class Number implements Function {
|
||||
s = s+"…";
|
||||
}
|
||||
|
||||
if (Calculator.exactMode == false) {
|
||||
if (root.exactMode == false) {
|
||||
String cuttedNumber = s.split("\\.")[0];
|
||||
if (cuttedNumber.length() > 8) {
|
||||
return cuttedNumber.substring(0, 1)+","+cuttedNumber.substring(1, 8)+"ℯ℮"+(cuttedNumber.length()-1);
|
||||
@ -265,14 +265,9 @@ public class Number implements Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -302,7 +297,7 @@ public class Number implements Function {
|
||||
{
|
||||
BigInteger n = getTerm().toBigIntegerExact();
|
||||
BigInteger two = BigInteger.valueOf(2);
|
||||
LinkedList<BigInteger> fs = new LinkedList<BigInteger>();
|
||||
LinkedList<BigInteger> fs = new LinkedList<>();
|
||||
|
||||
if (n.compareTo(two) < 0)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule1;
|
||||
import org.warp.picalculator.math.rules.ExponentRule2;
|
||||
@ -14,13 +15,13 @@ import org.warp.picalculator.math.rules.UndefinedRule1;
|
||||
|
||||
public class Power extends FunctionTwoValues {
|
||||
|
||||
public Power(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Power(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Power(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Power(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +75,7 @@ public class Power extends FunctionTwoValues {
|
||||
} else if (FractionsRule5.compare(this)) {
|
||||
result.addAll(FractionsRule5.execute(this));
|
||||
} else if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
result.add((Function) ((Number)variable1).pow((Number)variable2));
|
||||
result.add(((Number)variable1).pow((Number)variable2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -12,13 +12,13 @@ import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class Root extends FunctionTwoValues {
|
||||
|
||||
public Root(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Root(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Root(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Root(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -42,14 +42,14 @@ public class Root extends FunctionTwoValues {
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
if (Calculator.exactMode == false) {
|
||||
if (root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Number exponent = new Number(this.parent, BigDecimal.ONE);
|
||||
Number exponent = new Number(root, BigDecimal.ONE);
|
||||
exponent = exponent.divide((Number) variable1);
|
||||
Number resultVal = ((Number)variable2).pow(exponent);
|
||||
Number originalVariable = resultVal.pow(new Number(null, 2));
|
||||
Number originalVariable = resultVal.pow(new Number(root, 2));
|
||||
if (originalVariable.equals(variable2)) {
|
||||
return true;
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class Root extends FunctionTwoValues {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(root, 2))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -66,11 +66,11 @@ public class Root extends FunctionTwoValues {
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (Calculator.exactMode) {
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(null, 2))) {
|
||||
result.add(new RootSquare(parent, variable2));
|
||||
if (root.exactMode) {
|
||||
if (variable1 instanceof Number && ((Number)variable1).equals(new Number(root, 2))) {
|
||||
result.add(new RootSquare(root, variable2));
|
||||
} else {
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
Number exponent = new Number(root, BigInteger.ONE);
|
||||
exponent = exponent.divide((Number) variable1);
|
||||
result.add(((Number)variable2).pow(exponent));
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class Root extends FunctionTwoValues {
|
||||
Number exp = (Number) variable1;
|
||||
Number numb = (Number) variable2;
|
||||
|
||||
result.add(numb.pow(new Number(null, 1).divide(exp)).setParent(parent));
|
||||
result.add(numb.pow(new Number(root, 1).divide(exp)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -10,13 +10,13 @@ import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class RootSquare extends AnteriorFunction {
|
||||
|
||||
public RootSquare(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public RootSquare(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new RootSquare(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new RootSquare(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,14 +37,14 @@ public class RootSquare extends AnteriorFunction {
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variable instanceof Number) {
|
||||
if (Calculator.exactMode == false) {
|
||||
if (root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(null, 2));
|
||||
Number exponent = new Number(root, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(root, 2));
|
||||
Number resultVal = ((Number)variable).pow(exponent);
|
||||
Number originalVariable = resultVal.pow(new Number(null, 2));
|
||||
Number originalVariable = resultVal.pow(new Number(root, 2));
|
||||
if (originalVariable.equals(variable)) {
|
||||
return true;
|
||||
}
|
||||
@ -58,15 +58,15 @@ public class RootSquare extends AnteriorFunction {
|
||||
@Override
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (Calculator.exactMode) {
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(null, 2));
|
||||
if (root.exactMode) {
|
||||
Number exponent = new Number(root, BigInteger.ONE);
|
||||
exponent = exponent.divide(new Number(root, 2));
|
||||
result.add(((Number)variable).pow(exponent));
|
||||
} else {
|
||||
Number exp = new Number(null, 2);
|
||||
Number exp = new Number(root, 2);
|
||||
Number numb = (Number) variable;
|
||||
|
||||
result.add(numb.pow(new Number(null, 1).divide(exp)).setParent(parent));
|
||||
result.add(numb.pow(new Number(root, 1).divide(exp)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
@ -15,13 +16,13 @@ import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||
|
||||
public class Subtraction extends FunctionTwoValues {
|
||||
|
||||
public Subtraction(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Subtraction(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Subtraction(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Subtraction(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +66,7 @@ public class Subtraction extends FunctionTwoValues {
|
||||
} else if (SumMethod1.compare(this)) {
|
||||
result = SumMethod1.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(this.parent, "-1"))));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(root, "-1"))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule5;
|
||||
@ -20,13 +21,13 @@ import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||
|
||||
public class Sum extends FunctionTwoValues {
|
||||
|
||||
public Sum(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public Sum(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new Sum(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Sum(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,15 +74,15 @@ public class Sum extends FunctionTwoValues {
|
||||
} else if (SumMethod1.compare(this)) {
|
||||
result = SumMethod1.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if ((parent == null || parent.getParent() == null)) {
|
||||
if ((root.getChild().equals(this))) {
|
||||
if (((Number)variable1).term.compareTo(new BigDecimal(2)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(2)) == 0) {
|
||||
result.add(new Joke(Joke.FISH));
|
||||
result.add(new Joke(root, Joke.FISH));
|
||||
return result;
|
||||
} else if (((Number)variable1).term.compareTo(new BigDecimal(20)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(20)) == 0) {
|
||||
result.add(new Joke(Joke.TORNADO));
|
||||
result.add(new Joke(root, Joke.TORNADO));
|
||||
return result;
|
||||
} else if (((Number)variable1).term.compareTo(new BigDecimal(29)) == 0 && ((Number)variable2).term.compareTo(new BigDecimal(29)) == 0) {
|
||||
result.add(new Joke(Joke.SHARKNADO));
|
||||
result.add(new Joke(root, Joke.SHARKNADO));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
@ -17,13 +18,13 @@ import org.warp.picalculator.math.rules.NumberRule5;
|
||||
|
||||
public class SumSubtraction extends FunctionTwoValues {
|
||||
|
||||
public SumSubtraction(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
public SumSubtraction(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Function parent2, Function value1, Function value2) {
|
||||
return new SumSubtraction(parent, value1, value2);
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new SumSubtraction(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,7 +60,7 @@ public class SumSubtraction extends FunctionTwoValues {
|
||||
result = NumberRule5.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).add((Number)variable2));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(this.parent, "-1"))));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(root, "-1"))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -5,11 +5,14 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
public class Undefined implements Function {
|
||||
|
||||
protected final Calculator root;
|
||||
|
||||
public Undefined(Function parent) {
|
||||
setParent(parent);
|
||||
public Undefined(Calculator root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,7 +31,6 @@ public class Undefined implements Function {
|
||||
}
|
||||
|
||||
private int width, height, line;
|
||||
private Function parent;
|
||||
private boolean small;
|
||||
|
||||
@Override
|
||||
@ -60,14 +62,8 @@ public class Undefined implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParent(Function parent) {
|
||||
this.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,25 +9,26 @@ import java.util.List;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Variable implements Function {
|
||||
|
||||
private Function parent;
|
||||
protected char var;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected boolean small;
|
||||
protected final Calculator root;
|
||||
|
||||
public Variable(Function parent, char val) {
|
||||
this.parent = parent;
|
||||
public Variable(Calculator root, char val) {
|
||||
this.root = root;
|
||||
var = val;
|
||||
}
|
||||
|
||||
public Variable(Function parent, String s) throws Error {
|
||||
this(parent, s.charAt(0));
|
||||
public Variable(Calculator root, String s) throws Error {
|
||||
this(root, s.charAt(0));
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
@ -142,13 +143,8 @@ public class Variable implements Function {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
public Calculator getRoot() {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.Set;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.SolveMethod;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
@ -19,8 +20,13 @@ import com.rits.cloning.Cloner;
|
||||
|
||||
public class Equation extends FunctionTwoValues {
|
||||
|
||||
public Equation(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1,value2);
|
||||
public Equation(Calculator root, Function value1, Function value2) {
|
||||
super(root, value1,value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Calculator root, Function value1, Function value2) {
|
||||
return new Equation(root, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,9 +52,9 @@ public class Equation extends FunctionTwoValues {
|
||||
if (((Number)variable2).getTerm().compareTo(new BigDecimal(0)) == 0) {
|
||||
result.add(this);
|
||||
} else {
|
||||
Equation e = new Equation(this.parent, null, null);
|
||||
e.setVariable1(new Subtraction(e, variable1, variable2));
|
||||
e.setVariable2(new Number(e, "0"));
|
||||
Equation e = new Equation(root, null, null);
|
||||
e.setVariable1(new Subtraction(root, variable1, variable2));
|
||||
e.setVariable2(new Number(root, "0"));
|
||||
result.add(e);
|
||||
}
|
||||
}
|
||||
@ -65,10 +71,10 @@ public class Equation extends FunctionTwoValues {
|
||||
|
||||
//WORK IN PROGRESS
|
||||
public ArrayList<Equation> solveStep(char charIncognita) {
|
||||
ArrayList<Equation> result = new ArrayList<Equation>();
|
||||
ArrayList<Equation> result = new ArrayList<>();
|
||||
result.add(this.clone());
|
||||
for (SolveMethod t : SolveMethod.techniques) {
|
||||
ArrayList<Equation> newResults = new ArrayList<Equation>();
|
||||
ArrayList<Equation> newResults = new ArrayList<>();
|
||||
final int sz = result.size();
|
||||
for (int n = 0; n < sz; n++) {
|
||||
newResults.addAll(t.solve(result.get(n)));
|
||||
|
@ -1,12 +1,10 @@
|
||||
package org.warp.picalculator.math.functions.equations;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class EquationResult {
|
||||
public boolean isAnEquation = false;
|
||||
public Number LR = new Number(null, new BigInteger("0"));
|
||||
public Number LR;
|
||||
|
||||
public EquationResult(Number LR, boolean isAnEquation) {
|
||||
this.LR = LR;
|
||||
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionMultipleValues;
|
||||
@ -13,17 +14,17 @@ import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class EquationsSystem extends FunctionMultipleValues {
|
||||
static final int spacing = 2;
|
||||
|
||||
public EquationsSystem(Function parent) {
|
||||
super(parent);
|
||||
|
||||
public EquationsSystem(Calculator root) {
|
||||
super(root);
|
||||
}
|
||||
|
||||
public EquationsSystem(Function parent, Function value) {
|
||||
super(parent, new Function[]{value});
|
||||
public EquationsSystem(Calculator root, Function value) {
|
||||
super(root, new Function[]{value});
|
||||
}
|
||||
|
||||
public EquationsSystem(Function parent, Function[] value) {
|
||||
super(parent, value);
|
||||
public EquationsSystem(Calculator root, Function[] value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,7 +53,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
if (f instanceof Number) {
|
||||
ret.add(f);
|
||||
} else {
|
||||
ret.add(new Expression(this.parent, new Function[]{(Function) f}));
|
||||
ret.add(new Expression(this.root, new Function[]{f}));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -62,7 +63,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
if (f.isSolved() == false) {
|
||||
List<Function> partial = f.solveOneStep();
|
||||
for (Function fnc : partial) {
|
||||
ret.add(new Expression(this.parent, new Function[]{(Function) fnc}));
|
||||
ret.add(new Expression(this.root, new Function[]{fnc}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,37 +6,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class EquationsSystemPart extends AnteriorFunction {
|
||||
|
||||
public EquationsSystemPart(Function parent, Equation equazione) {
|
||||
super(parent, equazione);
|
||||
public EquationsSystemPart(Calculator root, Equation equazione) {
|
||||
super(root, equazione);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function NewInstance(Calculator root, Function value) {
|
||||
return new EquationsSystemPart(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return MathematicalSymbols.SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
return variable.isSolved()==false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws NumberFormatException, Error {
|
||||
// TODO implementare il calcolo dei sistemi
|
||||
if (variable.isSolved()) {
|
||||
List<Function> ret = new ArrayList<>();
|
||||
ret.add(variable);
|
||||
return ret;
|
||||
}
|
||||
return variable.solveOneStep();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
variable.setSmall(false);
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class ArcCosine extends AnteriorFunction {
|
||||
|
||||
public ArcCosine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public ArcCosine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new ArcCosine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new ArcCosine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class ArcSine extends AnteriorFunction {
|
||||
|
||||
public ArcSine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public ArcSine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new ArcSine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new ArcSine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class ArcTangent extends AnteriorFunction {
|
||||
|
||||
public ArcTangent(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public ArcTangent(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new ArcTangent(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new ArcTangent(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class Cosine extends AnteriorFunction {
|
||||
|
||||
public Cosine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Cosine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Cosine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Cosine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,29 +1,25 @@
|
||||
package org.warp.picalculator.math.functions.trigonometry;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.nevec.rjm.BigDecimalMath;
|
||||
import org.nevec.rjm.BigIntegerMath;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
public class Sine extends AnteriorFunction {
|
||||
|
||||
public Sine(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Sine(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Sine(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Sine(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -34,12 +30,12 @@ public class Sine extends AnteriorFunction {
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variable instanceof Number) {
|
||||
if (Calculator.exactMode == false) {
|
||||
if (root.exactMode == false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Calculator.angleMode == AngleMode.DEG) {
|
||||
Function[] solvableValues = new Function[]{new Number(null, 0), new Number(null, 30), new Number(null, 90), };
|
||||
if (root.angleMode == AngleMode.DEG) {
|
||||
Function[] solvableValues = new Function[]{new Number(root, 0), new Number(root, 30), new Number(root, 90), };
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -48,8 +44,8 @@ public class Sine extends AnteriorFunction {
|
||||
public ArrayList<Function> solve() throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
if (variable instanceof Number) {
|
||||
if (Calculator.exactMode == false) {
|
||||
results.add(new Number(parent, BigDecimalMath.sin(((Number) variable).getTerm())));
|
||||
if (root.exactMode == false) {
|
||||
results.add(new Number(root, BigDecimalMath.sin(((Number) variable).getTerm())));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
@ -3,19 +3,20 @@ package org.warp.picalculator.math.functions.trigonometry;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
public class Tangent extends AnteriorFunction {
|
||||
|
||||
public Tangent(Function parent, Function value) {
|
||||
super(parent, value);
|
||||
public Tangent(Calculator root, Function value) {
|
||||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function NewInstance(Function parent, Function value) {
|
||||
return new Tangent(parent, value);
|
||||
public Function NewInstance(Calculator root, Function value) {
|
||||
return new Tangent(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
@ -55,6 +56,7 @@ public class ExpandRule1 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Calculator root = f.getRoot();
|
||||
|
||||
Expression expr = null;
|
||||
int fromSubtraction = 0;
|
||||
@ -78,10 +80,10 @@ public class ExpandRule1 {
|
||||
if (fnc instanceof Sum) {
|
||||
Function a = ((Sum) fnc).getVariable1();
|
||||
Function b = ((Sum) fnc).getVariable2();
|
||||
Subtraction fnc2 = new Subtraction(f.getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
Subtraction fnc2 = new Subtraction(root, null, b);
|
||||
fnc2.setVariable1(new Negative(root, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(f.getParent(), null, null);
|
||||
subtraction = new Subtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc2);
|
||||
result.add(subtraction);
|
||||
@ -91,10 +93,10 @@ public class ExpandRule1 {
|
||||
} else if (fnc instanceof Subtraction) {
|
||||
Function a = ((Subtraction) fnc).getVariable1();
|
||||
Function b = ((Subtraction) fnc).getVariable2();
|
||||
Sum fnc2 = new Sum(((Negative) f).getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
Sum fnc2 = new Sum(root, null, b);
|
||||
fnc2.setVariable1(new Negative(root, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(f.getParent(), null, null);
|
||||
subtraction = new Subtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc2);
|
||||
result.add(subtraction);
|
||||
@ -104,16 +106,16 @@ public class ExpandRule1 {
|
||||
} else if (fnc instanceof SumSubtraction) {
|
||||
Function a = ((SumSubtraction) fnc).getVariable1();
|
||||
Function b = ((SumSubtraction) fnc).getVariable2();
|
||||
Sum fnc2 = new Sum(f.getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
Subtraction fnc3 = new Subtraction(f.getParent(), null, b);
|
||||
fnc3.setVariable1(new Negative(fnc2, a));
|
||||
Sum fnc2 = new Sum(root, null, b);
|
||||
fnc2.setVariable1(new Negative(root, a));
|
||||
Subtraction fnc3 = new Subtraction(root, null, b);
|
||||
fnc3.setVariable1(new Negative(root, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new SumSubtraction(f.getParent(), null, null);
|
||||
subtraction = new SumSubtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc2);
|
||||
result.add(subtraction);
|
||||
subtraction = new SumSubtraction(f.getParent(), null, null);
|
||||
subtraction = new SumSubtraction(root, null, null);
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc3);
|
||||
result.add(subtraction);
|
||||
|
@ -39,10 +39,10 @@ public class ExpandRule5 {
|
||||
|
||||
if (f instanceof Negative) {
|
||||
Negative fnc = (Negative) f;
|
||||
result.add(((Negative)((Expression)fnc.getVariable()).getVariable(0)).getVariable().setParent(f.getParent()));
|
||||
result.add(((Negative)((Expression)fnc.getVariable()).getVariable(0)).getVariable().setParent(root));
|
||||
} else if (f instanceof Subtraction) {
|
||||
Subtraction fnc = (Subtraction) f;
|
||||
result.add(((Negative)((Expression)fnc.getVariable2()).getVariable(0)).getVariable().setParent(f.getParent()));
|
||||
result.add(((Negative)((Expression)fnc.getVariable2()).getVariable(0)).getVariable().setParent(root));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
@ -17,15 +18,17 @@ public class ExponentRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 1))) {
|
||||
Calculator root = f.getRoot();
|
||||
if (fnc.getVariable1().equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 1));
|
||||
result.add(new Number(root, 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
@ -26,13 +27,14 @@ public class ExponentRule15 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication fnc = (Multiplication) f;
|
||||
Power p = new Power(fnc.getParent(), null, null);
|
||||
Expression expr = new Expression(p);
|
||||
Function a = fnc.getVariable1().setParent(expr);
|
||||
Power p = new Power(root, null, null);
|
||||
Expression expr = new Expression(root);
|
||||
Function a = fnc.getVariable1();
|
||||
expr.addFunctionToEnd(a);
|
||||
Number two = new Number(p, 2);
|
||||
Number two = new Number(root, 2);
|
||||
p.setVariable1(expr);
|
||||
p.setVariable2(two);
|
||||
result.add(p);
|
||||
|
@ -17,7 +17,7 @@ public class ExponentRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable2().equals(new Number(null, 1))) {
|
||||
if (fnc.getVariable2().equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -25,7 +25,7 @@ public class ExponentRule2 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(((Power)f).getVariable1().setParent(f.getParent()));
|
||||
result.add(((Power)f).getVariable1().setParent(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class ExponentRule3 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable2().equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -19,10 +19,10 @@ public class FractionsRule1 {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1() instanceof Number) {
|
||||
Number numb1 = (Number) fnc.getVariable1();
|
||||
if (numb1.equals(new Number(null, 0))) {
|
||||
if (numb1.equals(new Number(root, 0))) {
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb2 = (Number) fnc.getVariable2();
|
||||
if (numb2.equals(new Number(null, 0))) {
|
||||
if (numb2.equals(new Number(root, 0))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class FractionsRule2 {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ public class FractionsRule2 {
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Division fnc = (Division) f;
|
||||
result.add(fnc.getVariable1().setParent(f.getParent()));
|
||||
result.add(fnc.getVariable1().setParent(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class FractionsRule4 {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
||||
Number n2 = (Number) fnc.getVariable2();
|
||||
if (n2.equals(new Number(null, -1))) {
|
||||
if (n2.equals(new Number(root, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ public class FractionsRule5 {
|
||||
Power fnc = (Power) f;
|
||||
Function a = ((Division)fnc.getVariable1()).getVariable1();
|
||||
Function b = ((Division)fnc.getVariable1()).getVariable2();
|
||||
Function c = ((Number)fnc.getVariable2()).multiply(new Number(null, "-1"));
|
||||
Division dv = new Division(null, b, a);
|
||||
Function c = ((Number)fnc.getVariable2()).multiply(new Number(root, "-1"));
|
||||
Division dv = new Division(root, b, a);
|
||||
Power pow = new Power(f.getParent(), dv, c);
|
||||
dv.setParent(pow);
|
||||
result.add(pow);
|
||||
|
@ -19,13 +19,13 @@ public class NumberRule1 {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
if (numb.equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
if (numb.equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,13 @@ public class NumberRule2 {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -39,20 +39,20 @@ public class NumberRule2 {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
a = mult.getVariable2();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
if (aFound == false && mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
if (numb.equals(new Number(root, 1))) {
|
||||
a = mult.getVariable1();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
result.add(a.setParent(f.getParent()));
|
||||
result.add(a.setParent(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class NumberRule3 {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (f instanceof SumSubtraction) {
|
||||
Multiplication mul = new Multiplication(f.getParent(), null, null);
|
||||
mul.setVariable1(new Number(null, 2));
|
||||
mul.setVariable1(new Number(root, 2));
|
||||
mul.setVariable2(f);
|
||||
result.add(mul);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -22,20 +23,21 @@ public class NumberRule5 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
FunctionTwoValues fnc = (FunctionTwoValues) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 0)) || fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable1().equals(new Number(root, 0)) || fnc.getVariable2().equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
FunctionTwoValues fnc = (FunctionTwoValues) f;
|
||||
Function a = fnc.getVariable1();
|
||||
if (a.equals(new Number(null, 0))) {
|
||||
if (a.equals(new Number(root, 0))) {
|
||||
a = fnc.getVariable2();
|
||||
}
|
||||
result.add(a.setParent(f.getParent()));
|
||||
result.add(a);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,13 @@ public class NumberRule6 {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -40,14 +40,14 @@ public class NumberRule6 {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
a = mult.getVariable2();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
if (aFound == false && mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
if (numb.equals(new Number(root, -1))) {
|
||||
a = mult.getVariable1();
|
||||
aFound = true;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.warp.picalculator.math.rules;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
@ -21,9 +22,10 @@ public class NumberRule7 {
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication mult = new Multiplication(f.getParent(), null, null);
|
||||
mult.setVariable1(new Number(null, 2));
|
||||
Multiplication mult = new Multiplication(root, null, null);
|
||||
mult.setVariable1(new Number(root, 2));
|
||||
mult.setVariable2(f.getVariable1());
|
||||
result.add(mult);
|
||||
return result;
|
||||
|
@ -18,7 +18,7 @@ public class UndefinedRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 0)) && fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable1().equals(new Number(root, 0)) && fnc.getVariable2().equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -26,7 +26,7 @@ public class UndefinedRule1 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Undefined(f.getParent()));
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class UndefinedRule2 {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
if (numb.equals(new Number(root, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ public class UndefinedRule2 {
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Undefined(f.getParent()));
|
||||
result.add(new Undefined(root));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
@ -16,11 +17,12 @@ import org.warp.picalculator.math.functions.Number;
|
||||
*/
|
||||
public class DivisionRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
return ((Division)f).getVariable1().isSolved() && ((Division)f).getVariable2().isSolved() && !(((Division)f).getVariable1() instanceof Number && ((Division)f).getVariable2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null;
|
||||
public static boolean compare(Division f) {
|
||||
return f.getVariable1().isSolved() && f.getVariable2().isSolved() && !(f.getVariable1() instanceof Number && f.getVariable2() instanceof Number) && getFirstWorkingDivisionCouple(getDivisionElements(f)) != null;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
public static ArrayList<Function> execute(Division f) throws Error {
|
||||
Calculator root = f.getRoot();
|
||||
Function result;
|
||||
ArrayList<Function> elements = getDivisionElements(f);
|
||||
int[] workingElementCouple = getFirstWorkingDivisionCouple(elements);
|
||||
@ -28,19 +30,14 @@ public class DivisionRule1 {
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Multiplication(null, elem1, elem2);
|
||||
elem1.setParent(prec);
|
||||
elem2.setParent(prec);
|
||||
Function prec = new Multiplication(root, elem1, elem2);
|
||||
for (int i = size-1; i >= 0; i--) {
|
||||
if (i != workingElementCouple[0] & i != workingElementCouple[1]) {
|
||||
Function a = prec;
|
||||
Function b = elements.get(i);
|
||||
prec = new Multiplication(null, a, b);
|
||||
a.setParent(prec);
|
||||
b.setParent(prec);
|
||||
prec = new Multiplication(root, a, b);
|
||||
}
|
||||
}
|
||||
prec.setParent(f.getParent());
|
||||
|
||||
result = prec;
|
||||
|
||||
@ -83,7 +80,7 @@ public class DivisionRule1 {
|
||||
b = elements.get(j);
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
testFunc = new Multiplication(null, a, b);
|
||||
testFunc = new Multiplication(root, a, b);
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
}
|
||||
|
@ -27,19 +27,19 @@ public class MultiplicationMethod1 {
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Multiplication(null, elem1, elem2);
|
||||
Function prec = new Multiplication(root, elem1, elem2);
|
||||
elem1.setParent(prec);
|
||||
elem2.setParent(prec);
|
||||
for (int i = size-1; i >= 0; i--) {
|
||||
if (i != workingElementCouple[0] & i != workingElementCouple[1]) {
|
||||
Function a = prec;
|
||||
Function b = elements.get(i);
|
||||
prec = new Multiplication(null, a, b);
|
||||
prec = new Multiplication(root, a, b);
|
||||
a.setParent(prec);
|
||||
b.setParent(prec);
|
||||
}
|
||||
}
|
||||
prec.setParent(f.getParent());
|
||||
prec.setParent(root);
|
||||
|
||||
result = prec;
|
||||
|
||||
@ -71,7 +71,7 @@ public class MultiplicationMethod1 {
|
||||
b = elements.get(j);
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
testFunc = new Multiplication(null, a, b);
|
||||
testFunc = new Multiplication(root, a, b);
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class SumMethod1 {
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Sum(null, elem1, elem2);
|
||||
Function prec = new Sum(root, elem1, elem2);
|
||||
elem1.setParent(prec);
|
||||
elem2.setParent(prec);
|
||||
for (int i = size-1; i >= 0; i--) {
|
||||
@ -39,21 +39,21 @@ public class SumMethod1 {
|
||||
Function a = prec;
|
||||
Function b = elements.get(i);
|
||||
if (b instanceof Negative) {
|
||||
prec = new Subtraction(null, a, ((Negative)b).getVariable());
|
||||
prec = new Subtraction(root, a, ((Negative)b).getVariable());
|
||||
a.setParent(prec);
|
||||
((FunctionTwoValues)prec).getVariable2().setParent(prec);
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
prec = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
|
||||
prec = new Subtraction(root, a, ((Number)b).multiply(new Number(root, -1)));
|
||||
a.setParent(prec);
|
||||
((FunctionTwoValues)prec).getVariable2().setParent(prec);
|
||||
} else {
|
||||
prec = new Sum(null, a, b);
|
||||
prec = new Sum(root, a, b);
|
||||
a.setParent(prec);
|
||||
b.setParent(prec);
|
||||
}
|
||||
}
|
||||
}
|
||||
prec.setParent(f.getParent());
|
||||
prec.setParent(root);
|
||||
|
||||
result = prec;
|
||||
|
||||
@ -68,7 +68,7 @@ public class SumMethod1 {
|
||||
if (sum instanceof Sum) {
|
||||
elements.add(((FunctionTwoValues) sum).getVariable2());
|
||||
} else {
|
||||
elements.add(new Negative(null, ((FunctionTwoValues) sum).getVariable2()));
|
||||
elements.add(new Negative(root, ((FunctionTwoValues) sum).getVariable2()));
|
||||
}
|
||||
sum = ((FunctionTwoValues) sum).getVariable1();
|
||||
}
|
||||
@ -90,15 +90,15 @@ public class SumMethod1 {
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
if (b instanceof Negative) {
|
||||
testFunc = new Subtraction(null, a, ((Negative)b).getVariable());
|
||||
testFunc = new Subtraction(root, a, ((Negative)b).getVariable());
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
testFunc = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
|
||||
testFunc = new Subtraction(root, a, ((Number)b).multiply(new Number(root, -1)));
|
||||
} else if (a instanceof Negative) {
|
||||
testFunc = new Subtraction(null, b, ((Negative)a).getVariable());
|
||||
testFunc = new Subtraction(root, b, ((Negative)a).getVariable());
|
||||
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigDecimal.ZERO) < 0) {
|
||||
testFunc = new Subtraction(null, b, ((Number)a).multiply(new Number(null, -1)));
|
||||
testFunc = new Subtraction(root, b, ((Number)a).multiply(new Number(root, -1)));
|
||||
} else {
|
||||
testFunc = new Sum(null, a, b);
|
||||
testFunc = new Sum(root, a, b);
|
||||
}
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
|
@ -4,14 +4,10 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor4i;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringCenter;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
|
||||
public class ChooseVariableValueScreen extends Screen {
|
||||
|
@ -47,16 +47,12 @@ public class MathInputScreen extends Screen {
|
||||
public volatile int caretPos = 0;
|
||||
public volatile boolean showCaret = true;
|
||||
public volatile float showCaretDelta = 0f;
|
||||
public ArrayList<Function> f;
|
||||
public ArrayList<Function> f2;
|
||||
public ArrayList<VariableValue> variablesValues;
|
||||
public int resultsCount;
|
||||
public Calculator calc;
|
||||
public boolean autoscroll;
|
||||
public int scrollX = 0;
|
||||
public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto
|
||||
boolean mustRefresh = true;
|
||||
boolean afterDoNextStep = false;
|
||||
public final Calculator calc;
|
||||
|
||||
public MathInputScreen() {
|
||||
super();
|
||||
@ -102,12 +98,7 @@ public class MathInputScreen extends Screen {
|
||||
// Funzione f = new Parentesi("5Y+XY=2", "")
|
||||
|
||||
// calcola("((5^2+3√(100/0.1))+Ⓐ(7)+9/15*2√(26/2))/21");
|
||||
if (f == null & f2 == null) {
|
||||
f = new ArrayList<Function>();
|
||||
f2 = new ArrayList<Function>();
|
||||
variablesValues = new ArrayList<>();
|
||||
resultsCount = 0;
|
||||
}
|
||||
calc.init();
|
||||
// interpreta("{(5X*(15X/3X))+(25X/(5X*(15X/3X)))=15{X=5"); //TODO RIMUOVERE
|
||||
|
||||
// long start = System.nanoTime();
|
||||
@ -138,22 +129,8 @@ public class MathInputScreen extends Screen {
|
||||
if (!temporary) {
|
||||
equazioneCorrente = eqn;
|
||||
}
|
||||
ArrayList<Function> fncs = new ArrayList<Function>();
|
||||
if (eqn.length() > 0) {
|
||||
try {
|
||||
fncs.add(calc.parseString(eqn.replace("sqrt", "Ⓐ").replace("^", "Ⓑ")));
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
f = fncs;
|
||||
for (Function f : f) {
|
||||
try {
|
||||
f.generateGraphics();
|
||||
} catch (NullPointerException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
calc.parseInputString(eqn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -205,9 +182,9 @@ public class MathInputScreen extends Screen {
|
||||
glColor(textColor);
|
||||
PIDisplay.drawSkinPart(Main.screenSize[0]-16, padding+20+fontBig.charH/2-16/2, 304, 0, 304+16, 16);
|
||||
}
|
||||
if (f != null) {
|
||||
if (calc.f != null) {
|
||||
int topSpacing = 0;
|
||||
Iterator<Function> iter = f.iterator();
|
||||
Iterator<Function> iter = calc.f.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Function fnc = iter.next();
|
||||
try {
|
||||
@ -235,14 +212,14 @@ public class MathInputScreen extends Screen {
|
||||
topSpacing += fnc.getHeight() + 2;
|
||||
}
|
||||
}
|
||||
if (f2 != null) {
|
||||
if (calc.f2 != null) {
|
||||
int bottomSpacing = 0;
|
||||
for (Function f : f2) {
|
||||
for (Function f : calc.f2) {
|
||||
bottomSpacing += f.getHeight()+2;
|
||||
f.draw(Display.getWidth() - 2 - f.getWidth(), Display.getHeight() - bottomSpacing);
|
||||
}
|
||||
if (resultsCount > 1 && resultsCount != f2.size()) {
|
||||
String resultsCountText = resultsCount+" total results".toUpperCase();
|
||||
if (calc.resultsCount > 1 && calc.resultsCount != calc.f2.size()) {
|
||||
String resultsCountText = calc.resultsCount+" total results".toUpperCase();
|
||||
glColor(0xFF9AAEA0);
|
||||
glSetFont(Utils.getFont(true));
|
||||
bottomSpacing += fontBig.charH+2;
|
||||
@ -274,7 +251,7 @@ public class MathInputScreen extends Screen {
|
||||
@Override
|
||||
public void run() {
|
||||
equazioneCorrente = nuovaEquazione;
|
||||
f2 = f;
|
||||
calc.f2 = calc.f;
|
||||
afterDoNextStep = true;
|
||||
simplify(MathInputScreen.this);
|
||||
}
|
||||
@ -302,9 +279,9 @@ public class MathInputScreen extends Screen {
|
||||
Utils.debug.println("Resetting after error...");
|
||||
PIDisplay.error = null;
|
||||
this.equazioneCorrente = null;
|
||||
this.f = null;
|
||||
this.f2 = null;
|
||||
this.resultsCount = 0;
|
||||
calc.f = null;
|
||||
calc.f2 = null;
|
||||
calc.resultsCount = 0;
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
@ -476,15 +453,15 @@ public class MathInputScreen extends Screen {
|
||||
caretPos = 0;
|
||||
nuovaEquazione="";
|
||||
afterDoNextStep = false;
|
||||
if (f != null) {
|
||||
f.clear();
|
||||
if (calc.f != null) {
|
||||
calc.f.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case SURD_MODE:
|
||||
calc.exactMode = !calc.exactMode;
|
||||
if (calc.exactMode == false) {
|
||||
f2 = solveExpression(f2);
|
||||
calc.f2 = solveExpression(calc.f2);
|
||||
} else {
|
||||
equazioneCorrente = "";
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
@ -574,7 +551,7 @@ public class MathInputScreen extends Screen {
|
||||
showVariablesDialog();
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
ArrayList<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : f2) {
|
||||
for (Function f : calc.f2) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(this));
|
||||
} else {
|
||||
@ -587,23 +564,23 @@ public class MathInputScreen extends Screen {
|
||||
partialResults.add(itm);
|
||||
}
|
||||
}
|
||||
results = new ArrayList<Function>(partialResults);
|
||||
results = new ArrayList<>(partialResults);
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (results.size() == 0) {
|
||||
resultsCount = 0;
|
||||
calc.resultsCount = 0;
|
||||
} else {
|
||||
resultsCount = results.size();
|
||||
calc.resultsCount = results.size();
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
f2 = results;
|
||||
for (Function rf : f2) {
|
||||
calc.f2 = results;
|
||||
for (Function rf : calc.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
@ -626,26 +603,26 @@ public class MathInputScreen extends Screen {
|
||||
protected void solve() {
|
||||
try {
|
||||
try {
|
||||
for (Function f : f) {
|
||||
for (Function f : calc.f) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Function> results = solveExpression(f);
|
||||
ArrayList<Function> results = solveExpression(calc.f);
|
||||
if (results.size() == 0) {
|
||||
resultsCount = 0;
|
||||
calc.resultsCount = 0;
|
||||
} else {
|
||||
resultsCount = results.size();
|
||||
calc.resultsCount = results.size();
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
f2 = results;
|
||||
for (Function rf : f2) {
|
||||
calc.f2 = results;
|
||||
for (Function rf : calc.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
@ -699,10 +676,14 @@ public class MathInputScreen extends Screen {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showVariablesDialog() {
|
||||
showVariablesDialog(null);
|
||||
}
|
||||
|
||||
public void showVariablesDialog(final Runnable runnable) {
|
||||
Thread ct = new Thread(()->{
|
||||
ArrayList<Function> variablesInFunctions = getVariables(f.toArray(new Function[f.size()]));
|
||||
for (VariableValue f : variablesValues) {
|
||||
ArrayList<Function> variablesInFunctions = getVariables(calc.f.toArray(new Function[calc.f.size()]));
|
||||
for (VariableValue f : calc.variablesValues) {
|
||||
if (variablesInFunctions.contains(f.v)) {
|
||||
variablesInFunctions.remove(f.v);
|
||||
}
|
||||
@ -710,7 +691,7 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
boolean cancelled = false;
|
||||
for (Function f : variablesInFunctions) {
|
||||
ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(null, 0)));
|
||||
ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(calc, 0)));
|
||||
PIDisplay.INSTANCE.setScreen(cvs);
|
||||
try {
|
||||
while (PIDisplay.screen == cvs) {
|
||||
@ -722,18 +703,20 @@ public class MathInputScreen extends Screen {
|
||||
cancelled = true;
|
||||
break;
|
||||
} else {
|
||||
final int is = variablesValues.size();
|
||||
final int is = calc.variablesValues.size();
|
||||
for (int i = 0; i < is; i++) {
|
||||
if (variablesValues.get(i).v == f) {
|
||||
variablesValues.remove(i);
|
||||
if (calc.variablesValues.get(i).v == f) {
|
||||
calc.variablesValues.remove(i);
|
||||
}
|
||||
}
|
||||
variablesValues.add(new VariableValue((Variable) f, (Number) cvs.resultNumberValue));
|
||||
calc.variablesValues.add(new VariableValue((Variable) f, (Number) cvs.resultNumberValue));
|
||||
}
|
||||
}
|
||||
if (!cancelled) {
|
||||
runnable.run();
|
||||
Utils.debug.println(f.toString());
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
Utils.debug.println(calc.f.toString());
|
||||
}
|
||||
});
|
||||
ct.setName("Variables user-input queue thread");
|
||||
@ -770,14 +753,15 @@ public class MathInputScreen extends Screen {
|
||||
es2.showCaret = es.showCaret;
|
||||
es2.showCaretDelta = es.showCaretDelta;
|
||||
es2.caretPos = es.caretPos;
|
||||
es2.f = Utils.cloner.deepClone(es.f);
|
||||
es2.f2 = Utils.cloner.deepClone(es.f2);
|
||||
es2.resultsCount = es.resultsCount;
|
||||
// es2.calc.f = Utils.cloner.deepClone(es.calc.f);
|
||||
// es2.calc.f2 = Utils.cloner.deepClone(es.calc.f2);
|
||||
// es2.calc.resultsCount = es.calc.resultsCount;
|
||||
es2.autoscroll = es.autoscroll;
|
||||
es2.errorLevel = es.errorLevel;
|
||||
es2.mustRefresh = es.mustRefresh;
|
||||
es2.afterDoNextStep = es.afterDoNextStep;
|
||||
es2.variablesValues = Utils.cloner.deepClone(es.variablesValues);
|
||||
// es2.calc.variablesValues = Utils.cloner.deepClone(es.calc.variablesValues);
|
||||
es2.calc = Utils.cloner.deepClone(es.calc);
|
||||
return es2;
|
||||
}
|
||||
|
||||
|
@ -56,13 +56,13 @@ public class SolveEquationScreen extends Screen {
|
||||
case LETTER_X:
|
||||
PIDisplay.INSTANCE.goBack();
|
||||
try {
|
||||
Calculator.solveExpression('X');
|
||||
es.calc.solveExpression('X');
|
||||
} catch (Error e) {
|
||||
Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
if (scr instanceof MathInputScreen) {
|
||||
MathInputScreen escr = (MathInputScreen) scr;
|
||||
escr.errorLevel = 1;
|
||||
escr.err2 = e;
|
||||
//escr.err2 = e; //TODO: What is this variable, and why it doesn't exists?
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user