A lot of new Rules and important bugfixes.
This commit is contained in:
parent
d3ab2579b3
commit
c37b7528c9
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry excluding="org/warp/picalculator/deprecatedmath/" kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="res"/>
|
||||
<classpathentry kind="lib" path="D:/Users/Andrea/Downloads/objenesis-2.4-bin/objenesis-2.4/objenesis-2.4.jar" sourcepath="D:/Users/Andrea/Downloads/objenesis-2.4-bin/objenesis-2.4/objenesis-2.4-sources.jar">
|
||||
|
BIN
Algebra Cheat Sheet.rtf
Normal file
BIN
Algebra Cheat Sheet.rtf
Normal file
Binary file not shown.
BIN
res/font_big.rft
BIN
res/font_big.rft
Binary file not shown.
Binary file not shown.
BIN
res/font_ex.rft
Normal file
BIN
res/font_ex.rft
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
res/skin.png
BIN
res/skin.png
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 4.3 KiB |
BIN
res/skin.xcf
BIN
res/skin.xcf
Binary file not shown.
@ -1,748 +0,0 @@
|
||||
package org.nevec.rjm;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.MathContext;
|
||||
import java.security.ProviderException;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Variables;
|
||||
|
||||
/**
|
||||
* Square roots on the real line. These represent numbers which are a product of
|
||||
* a (signed) fraction by a square root of a non-negative fraction. This might
|
||||
* be extended to values on the imaginary axis by allowing negative values
|
||||
* underneath the square root, but this is not yet implemented.
|
||||
*
|
||||
* @since 2011-02-12
|
||||
* @author Richard J. Mathar
|
||||
*/
|
||||
public class NumeroAvanzato implements Cloneable {
|
||||
/**
|
||||
* The value of zero.
|
||||
*/
|
||||
public static final NumeroAvanzato ZERO = new NumeroAvanzato();
|
||||
|
||||
/**
|
||||
* The value of one.
|
||||
*/
|
||||
public static final NumeroAvanzato ONE = new NumeroAvanzato(Rational.ONE, Rational.ONE);
|
||||
/**
|
||||
* Prefactor
|
||||
*/
|
||||
Rational pref;
|
||||
|
||||
private Variables variablex;
|
||||
|
||||
private Variables variabley;
|
||||
|
||||
private Variables variablez;
|
||||
|
||||
/**
|
||||
* The number underneath the square root, always non-negative. The
|
||||
* mathematical object has the value pref*sqrt(disc).
|
||||
*/
|
||||
Rational disc;
|
||||
|
||||
/**
|
||||
* Default ctor, which represents the zero.
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato() {
|
||||
pref = Rational.ZERO;
|
||||
disc = Rational.ZERO;
|
||||
variablex = new Variables();
|
||||
variabley = new Variables();
|
||||
variablez = new Variables();
|
||||
}
|
||||
|
||||
/**
|
||||
* ctor given the prefactor and the basis of the root. This creates an
|
||||
* object of value a*sqrt(b).
|
||||
*
|
||||
* @param a
|
||||
* the prefactor.
|
||||
* @param b
|
||||
* the discriminant.
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato(Rational a, Rational b) {
|
||||
this.pref = a;
|
||||
/*
|
||||
* reject attempts to use a negative b
|
||||
*/
|
||||
if (b.signum() < 0)
|
||||
throw new ProviderException("Not implemented: imaginary surds");
|
||||
this.disc = b;
|
||||
variablex = new Variables();
|
||||
variabley = new Variables();
|
||||
variablez = new Variables();
|
||||
try {
|
||||
normalize();
|
||||
normalizeG();
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public NumeroAvanzato(Rational a, Rational b, Variables x, Variables y, Variables z) {
|
||||
this.pref = a;
|
||||
/*
|
||||
* reject attempts to use a negative b
|
||||
*/
|
||||
if (b.signum() < 0)
|
||||
throw new ProviderException("Not implemented: imaginary surds");
|
||||
this.disc = b;
|
||||
variablex = x;
|
||||
variabley = y;
|
||||
variablez = z;
|
||||
try {
|
||||
normalize();
|
||||
normalizeG();
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ctor given the numerator and denominator of the root. This creates an
|
||||
* object of value sqrt(a/b).
|
||||
*
|
||||
* @param a
|
||||
* the numerator
|
||||
* @param b
|
||||
* the denominator.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato(int a, int b) {
|
||||
this(Rational.ONE, new Rational(a, b));
|
||||
}
|
||||
|
||||
/**
|
||||
* ctor given the value under the root. This creates an object of value
|
||||
* sqrt(a).
|
||||
*
|
||||
* @param a
|
||||
* the discriminant.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato(BigInteger a) {
|
||||
this(Rational.ONE, new Rational(a, BigInteger.ONE));
|
||||
}
|
||||
|
||||
public NumeroAvanzato(Rational a) {
|
||||
this(Rational.ONE, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a deep copy.
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
@Override
|
||||
public NumeroAvanzato clone() {
|
||||
Rational fclon = pref.clone();
|
||||
Rational dclon = disc.clone();
|
||||
Variables incognitexb = variablex;
|
||||
Variables incogniteyb = variabley;
|
||||
Variables incognitezb = variablez;
|
||||
/*
|
||||
* the main intent here is to bypass any attempt to reduce the
|
||||
* discriminant by figuring out the square-free part in normalize(),
|
||||
* which has already done in the current copy of the number.
|
||||
*/
|
||||
NumeroAvanzato cl = new NumeroAvanzato();
|
||||
cl.pref = fclon;
|
||||
cl.disc = dclon;
|
||||
cl.variablex = incognitexb;
|
||||
cl.variabley = incogniteyb;
|
||||
cl.variablez = incognitezb;
|
||||
return cl;
|
||||
} /* NumeroAvanzato.clone */
|
||||
|
||||
/**
|
||||
* Add two surds of compatible discriminant.
|
||||
*
|
||||
* @param val
|
||||
* The value to be added to this.
|
||||
*/
|
||||
|
||||
public NumeroAvanzatoVec add(final NumeroAvanzato val) {
|
||||
// zero plus somethings yields something
|
||||
if (signum() == 0)
|
||||
return new NumeroAvanzatoVec(val);
|
||||
else if (val.signum() == 0)
|
||||
return new NumeroAvanzatoVec(this);
|
||||
else
|
||||
// let the ctor of NumeroAvanzatoVec to the work
|
||||
return new NumeroAvanzatoVec(this, val);
|
||||
} /* NumeroAvanzato.add */
|
||||
|
||||
/**
|
||||
* Multiply by another square root.
|
||||
*
|
||||
* @param val
|
||||
* a second number of this type.
|
||||
* @return the product of this with the val.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato multiply(final NumeroAvanzato val) {
|
||||
return new NumeroAvanzato(pref.multiply(val.pref), disc.multiply(val.disc), variablex.multiply(val.variablex), variabley.multiply(val.variabley), variablez.multiply(val.variablez));
|
||||
} /* NumeroAvanzato.multiply */
|
||||
|
||||
/**
|
||||
* Multiply by a rational number.
|
||||
*
|
||||
* @param val
|
||||
* the factor.
|
||||
* @return the product of this with the val.
|
||||
* @since 2011-02-15
|
||||
*/
|
||||
public NumeroAvanzato multiply(final Rational val) {
|
||||
return new NumeroAvanzato(pref.multiply(val), disc, variablex, variabley, variablez);
|
||||
} /* NumeroAvanzato.multiply */
|
||||
|
||||
/**
|
||||
* Multiply by a BigInteger.
|
||||
*
|
||||
* @param val
|
||||
* a second number.
|
||||
* @return the product of this with the value.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato multiply(final BigInteger val) {
|
||||
return new NumeroAvanzato(pref.multiply(val), disc, variablex, variabley, variablez);
|
||||
} /* NumeroAvanzato.multiply */
|
||||
|
||||
/**
|
||||
* Multiply by an integer.
|
||||
*
|
||||
* @param val
|
||||
* a second number.
|
||||
* @return the product of this with the value.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato multiply(final int val) {
|
||||
BigInteger tmp = new BigInteger("" + val);
|
||||
return multiply(tmp);
|
||||
} /* NumeroAvanzato.multiply */
|
||||
|
||||
/**
|
||||
* Compute the square.
|
||||
*
|
||||
* @return this value squared.
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato pow2() throws Error {
|
||||
NumeroAvanzato res = new NumeroAvanzato();
|
||||
BigInteger a = pref.a;
|
||||
BigInteger b = pref.b;
|
||||
BigInteger c = disc.a;
|
||||
BigInteger d = disc.b;
|
||||
res.pref = new Rational(a.pow(2).multiply(c).multiply(d), b.pow(2).multiply(d));
|
||||
res.disc = new Rational(0, 1);
|
||||
res.normalize();
|
||||
res.variablex = variablex;
|
||||
res.variabley = variabley.multiply(variabley);
|
||||
res.variablez = variablez.multiply(variablez);
|
||||
return res;
|
||||
} /* NumeroAvanzato.sqr */
|
||||
|
||||
/**
|
||||
* Divide by another square root.
|
||||
*
|
||||
* @param val
|
||||
* A second number of this type.
|
||||
* @return The value of this/val
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato divide(final NumeroAvanzato val) throws Error {
|
||||
if (val.signum() == 0)
|
||||
throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
|
||||
NumeroAvanzato result = new NumeroAvanzato(pref.divide(val.pref), disc.divide(val.disc));
|
||||
result.variablex = variablex.divide(val.variablex);
|
||||
result.variabley = variabley.divide(val.variabley);
|
||||
result.variablez = variablez.divide(val.variablez);
|
||||
result.normalize();
|
||||
return result;
|
||||
} /* NumeroAvanzato.divide */
|
||||
|
||||
private String toFancyString() throws Error {
|
||||
return new NumeroAvanzatoVec(this).toFancyString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Divide by an integer.
|
||||
*
|
||||
* @param val
|
||||
* a second number.
|
||||
* @return the value of this/val
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato divide(final BigInteger val) throws Error {
|
||||
if (val.signum() == 0)
|
||||
throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
|
||||
return new NumeroAvanzato(pref.divide(val), disc);
|
||||
} /* NumeroAvanzato.divide */
|
||||
|
||||
/**
|
||||
* Divide by an integer.
|
||||
*
|
||||
* @param val
|
||||
* A second number.
|
||||
* @return The value of this/val
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato divide(int val) throws Error {
|
||||
if (val == 0)
|
||||
throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
|
||||
return new NumeroAvanzato(pref.divide(val), disc);
|
||||
} /* NumeroAvanzato.divide */
|
||||
|
||||
/**
|
||||
* Compute the negative.
|
||||
*
|
||||
* @return -this.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato negate() {
|
||||
/*
|
||||
* This is trying to be quick, avoiding normalize(), by toggling the
|
||||
* sign in a clone()
|
||||
*/
|
||||
NumeroAvanzato n = clone();
|
||||
n.pref = n.pref.negate();
|
||||
return n;
|
||||
} /* NumeroAvanzato.negate */
|
||||
|
||||
/**
|
||||
* Absolute value.
|
||||
*
|
||||
* @return The absolute (non-negative) value of this.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzato abs() {
|
||||
return new NumeroAvanzato(pref.abs(), disc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the value of this with another constant.
|
||||
*
|
||||
* @param val
|
||||
* the other constant to compare with
|
||||
* @return -1, 0 or 1 if this number is numerically less than, equal to, or
|
||||
* greater than val.
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public int signumComparedTo(final NumeroAvanzato val) throws Error {
|
||||
/*
|
||||
* Since we keep the discriminant positive, the rough estimate comes
|
||||
* from comparing the signs of the prefactors.
|
||||
*/
|
||||
final int sig = signum();
|
||||
final int sigv = val.signum();
|
||||
if (sig < 0 && sigv >= 0)
|
||||
return -1;
|
||||
if (sig > 0 && sigv <= 0)
|
||||
return 1;
|
||||
if (sig == 0 && sigv == 0)
|
||||
return 0;
|
||||
if (sig == 0 && sigv > 0)
|
||||
return -1;
|
||||
if (sig == 0 && sigv < 0)
|
||||
return 1;
|
||||
|
||||
/*
|
||||
* Work out the cases of equal sign. Compare absolute values by
|
||||
* comparison of the squares which is forwarded to the comparison of the
|
||||
* Rational class.
|
||||
*/
|
||||
final Rational this2 = pow2().pref;
|
||||
final Rational val2 = val.pow2().pref;
|
||||
final int c2 = this2.compareTo(val2);
|
||||
if (c2 == 0)
|
||||
return 0;
|
||||
/*
|
||||
* If both values have negative sign, the one with the smaller square is
|
||||
* the larger number.
|
||||
*/
|
||||
else if (sig > 0 && c2 > 0 || sig < 0 && c2 < 0)
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
} /* NumeroAvanzato.compareTo */
|
||||
|
||||
/**
|
||||
* Return a string in the format (number/denom)*()^(1/2). If the
|
||||
* discriminant equals 1, print just the prefactor.
|
||||
*
|
||||
* @return the human-readable version in base 10
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return toFancyString();
|
||||
} catch (Error e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*
|
||||
* if (disc.compareTo(Rational.ONE) != 0 &&
|
||||
* disc.compareTo(Rational.ZERO) != 0)
|
||||
* return ("(" + pref.toString() + ")*(" + disc.toString() + ")^(1/2)");
|
||||
* else
|
||||
* return pref.toString();
|
||||
*/
|
||||
return "err";
|
||||
} /* NumeroAvanzato.toString */
|
||||
|
||||
/**
|
||||
* Return a double value representation.
|
||||
*
|
||||
* @return The value with double precision.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public double doubleValue() {
|
||||
/*
|
||||
* First compute the square to prevent overflows if the two pieces of
|
||||
* the prefactor and the discriminant are of very different magnitude.
|
||||
*/
|
||||
Rational p2 = pref.pow(2).multiply(disc);
|
||||
System.out.println("dv sq " + p2.toString());
|
||||
double res = p2.doubleValue();
|
||||
System.out.println("dv sq " + res);
|
||||
return (pref.signum() >= 0) ? Math.sqrt(res) : -Math.sqrt(res);
|
||||
} /* NumeroAvanzato.doubleValue */
|
||||
|
||||
/**
|
||||
* Return a float value representation.
|
||||
*
|
||||
* @return The value with single precision.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public float floatValue() {
|
||||
return (float) (doubleValue());
|
||||
} /* NumeroAvanzato.floatValue */
|
||||
|
||||
/**
|
||||
* True if the value is integer. Equivalent to the indication whether a
|
||||
* conversion to an integer can be exact.
|
||||
*
|
||||
* @param hasBigIntegerVariables
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public boolean isBigInteger(boolean hasBigIntegerVariables) {
|
||||
if (pref.isBigInteger() && (disc.signum() == 0 || disc.compareTo(Rational.ONE) == 0)) {
|
||||
if (disc.signum() != 0 && variablex.count() > 0) {
|
||||
return false;
|
||||
}
|
||||
if (hasBigIntegerVariables == false && variabley.count() > 0) {
|
||||
return false;
|
||||
}
|
||||
if (pref.b.compareTo(BigInteger.ZERO) != 0 && disc.b.compareTo(BigInteger.ZERO) != 0 && variablez.count() > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} /* NumeroAvanzato.isBigInteger */
|
||||
|
||||
public boolean isRational(boolean hasRationalVariables) {
|
||||
if (disc.signum() == 0 || disc.compareTo(new Rational(1, 1)) == 0) {
|
||||
if (variablex.count() > 0) {
|
||||
return false;
|
||||
} else if (hasRationalVariables == false) {
|
||||
if (variabley.count() > 0 || variablez.count() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.pref.b.compareTo(new BigInteger("10000")) > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
} /* NumeroAvanzato.isRational */
|
||||
|
||||
public boolean isTooPreciseRational(boolean hasRationalVariables) {
|
||||
if (disc.signum() == 0 || disc.compareTo(new Rational(1, 1)) == 0) {
|
||||
if (variablex.count() > 0) {
|
||||
return false;
|
||||
} else if (hasRationalVariables == false) {
|
||||
if (variabley.count() > 0 || variablez.count() > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.pref.b.compareTo(new BigInteger("10000")) > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
} /* NumeroAvanzato.isRational */
|
||||
|
||||
/**
|
||||
* Convert to a rational value if possible
|
||||
*
|
||||
* @throws Error
|
||||
*
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public Rational toRational(boolean hasRationalVariables) throws Error {
|
||||
if (isRational(hasRationalVariables) || isTooPreciseRational(hasRationalVariables))
|
||||
return pref;
|
||||
else
|
||||
throw new ArithmeticException("Undefined conversion " + toFancyString() + " to Rational.");
|
||||
} /* NumeroAvanzato.toRational */
|
||||
|
||||
public Rational toRational() throws Error {
|
||||
if (isRational(true))
|
||||
return pref;
|
||||
else
|
||||
throw new ArithmeticException("Undefined conversion " + toFancyString() + " to Rational.");
|
||||
}
|
||||
|
||||
/**
|
||||
* The sign: 1 if the number is >0, 0 if ==0, -1 if <0
|
||||
*
|
||||
* @return the signum of the value.
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public int signum() {
|
||||
/*
|
||||
* Since the disc is kept positive, this is the same as the sign of the
|
||||
* prefactor. This works because a zero discriminant is always copied
|
||||
* over to the prefactor, not hidden.
|
||||
*/
|
||||
return pref.signum();
|
||||
} /* NumeroAvanzato.signum */
|
||||
|
||||
/**
|
||||
* Normalize to squarefree discriminant.
|
||||
*
|
||||
* @throws Error
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
protected void normalize() throws Error {
|
||||
/*
|
||||
* Move squares out of the numerator and denominator of the discriminant
|
||||
*/
|
||||
if (disc.signum() != 0) {
|
||||
/*
|
||||
* square-free part of the numerator: numer = numC*some^2
|
||||
*/
|
||||
BigInteger numC = BigIntegerMath.core(disc.numer());
|
||||
/*
|
||||
* extract the perfect square of the numerator
|
||||
*/
|
||||
BigInteger sq = disc.numer().divide(numC);
|
||||
/*
|
||||
* extract the associated square root
|
||||
*/
|
||||
BigInteger sqf = BigIntegerMath.isqrt(sq);
|
||||
|
||||
/*
|
||||
* move sqf over to the pre-factor
|
||||
*/
|
||||
pref = pref.multiply(sqf);
|
||||
|
||||
BigInteger denC = BigIntegerMath.core(disc.denom());
|
||||
sq = disc.denom().divide(denC);
|
||||
sqf = BigIntegerMath.isqrt(sq);
|
||||
try {
|
||||
pref = pref.divide(sqf);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
disc = new Rational(numC, denC);
|
||||
|
||||
if (disc.b.compareTo(BigInteger.ZERO) == 0 || disc.a.compareTo(BigInteger.ZERO) == 0 || pref.a.compareTo(BigInteger.ZERO) == 0) {
|
||||
variablex = new Variables();
|
||||
variabley = new Variables();
|
||||
}
|
||||
|
||||
if (disc.b.compareTo(BigInteger.ZERO) == 0 || pref.b.compareTo(BigInteger.ZERO) == 0) {
|
||||
variablez = new Variables();
|
||||
}
|
||||
|
||||
if (variabley.compareTo(variablez)) {
|
||||
variabley = new Variables();
|
||||
variablez = new Variables();
|
||||
}
|
||||
|
||||
/**/
|
||||
Variables[] incognitetemp = new Variables[] { variablex, variabley, variablez };
|
||||
incognitetemp = Variables.normalizeBigSurdVariables(incognitetemp);
|
||||
variablex = incognitetemp[0];
|
||||
variabley = incognitetemp[1];
|
||||
variablez = incognitetemp[2];
|
||||
/**/
|
||||
} else {
|
||||
pref = Rational.ZERO;
|
||||
variablex = new Variables();
|
||||
variabley = new Variables();
|
||||
variablez = new Variables();
|
||||
}
|
||||
} /* NumeroAvanzato.normalize */
|
||||
|
||||
/**
|
||||
* Normalize to coprime numerator and denominator in prefactor and
|
||||
* discriminant
|
||||
*
|
||||
* @throws Error
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
protected void normalizeG() throws Error {
|
||||
/*
|
||||
* Is there a common factor between the numerator of the prefactor and
|
||||
* the denominator of the discriminant ?
|
||||
*/
|
||||
BigInteger d = pref.numer().abs().gcd(disc.denom());
|
||||
if (d.compareTo(BigInteger.ONE) > 0) {
|
||||
try {
|
||||
pref = pref.divide(d);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*
|
||||
* instead of multiplying with the square of d, using two steps
|
||||
* offers a change to recognize the common factor..
|
||||
*/
|
||||
disc = disc.multiply(d);
|
||||
disc = disc.multiply(d);
|
||||
}
|
||||
/*
|
||||
* Is there a common factor between the denominator of the prefactor and
|
||||
* the numerator of the discriminant ?
|
||||
*/
|
||||
d = pref.denom().gcd(disc.numer());
|
||||
if (d.compareTo(BigInteger.ONE) > 0) {
|
||||
pref = pref.multiply(d);
|
||||
/*
|
||||
* instead of dividing through the square of d, using two steps
|
||||
* offers a change to recognize the common factor..
|
||||
*/
|
||||
disc = disc.divide(d);
|
||||
disc = disc.divide(d);
|
||||
}
|
||||
} /* NumeroAvanzato.normalizeG */
|
||||
|
||||
/**
|
||||
* Return the approximate floating point representation.
|
||||
*
|
||||
* @param mc
|
||||
* Description of the accuracy needed.
|
||||
* @return A representation with digits valid as described by mc
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigDecimal BigDecimalValue(MathContext mc) {
|
||||
/*
|
||||
* the relative error of the result equals the relative error of the
|
||||
* prefactor plus half of the relative error of the discriminant. So
|
||||
* adding 3 digits temporarily is sufficient.
|
||||
*/
|
||||
final MathContext locmc = new MathContext(mc.getPrecision() + 3, mc.getRoundingMode());
|
||||
/*
|
||||
* first the square root of the discriminant
|
||||
*/
|
||||
BigDecimal sqrdis = BigDecimalMath.sqrt(disc.BigDecimalValue(locmc), locmc);
|
||||
/*
|
||||
* Then multiply by the prefactor. If sqrdis is a terminating decimal
|
||||
* fraction, we prevent early truncation of the result by truncating
|
||||
* later.
|
||||
*/
|
||||
BigDecimal res = sqrdis.multiply(pref.BigDecimalValue(mc));
|
||||
return BigDecimalMath.scalePrec(res, mc);
|
||||
} /* BigDecimalValue */
|
||||
|
||||
@Override
|
||||
public boolean equals(Object val) {
|
||||
if (val instanceof NumeroAvanzato) {
|
||||
NumeroAvanzato na = (NumeroAvanzato) val;
|
||||
try {
|
||||
if (pow2().pref == na.pow2().pref) {
|
||||
if (pow2().pref == Rational.ZERO) {
|
||||
return true;
|
||||
} else {
|
||||
if (variablex == na.variablex) {
|
||||
if (variabley == na.variabley) {
|
||||
if (variablez == na.variablez) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Variables getVariableX() {
|
||||
if (variablex == null) {
|
||||
return variablex;
|
||||
}
|
||||
return variablex.clone();
|
||||
}
|
||||
|
||||
public NumeroAvanzato setVariableX(Variables x) {
|
||||
NumeroAvanzato result = this.clone();
|
||||
result.variablex = x;
|
||||
return result;
|
||||
}
|
||||
|
||||
public Variables getVariableY() {
|
||||
if (variabley == null) {
|
||||
return variabley;
|
||||
}
|
||||
return variabley.clone();
|
||||
}
|
||||
|
||||
public NumeroAvanzato setVariableY(Variables y) {
|
||||
NumeroAvanzato result = this.clone();
|
||||
result.variabley = y;
|
||||
return result;
|
||||
}
|
||||
|
||||
public Variables getVariableZ() {
|
||||
if (variablez == null) {
|
||||
return variablez;
|
||||
}
|
||||
return variablez.clone();
|
||||
}
|
||||
|
||||
public NumeroAvanzato setVariableZ(Variables z) {
|
||||
NumeroAvanzato result = this.clone();
|
||||
result.variablez = z;
|
||||
return result;
|
||||
}
|
||||
|
||||
public NumeroAvanzato divideUnsafe(BigInteger denominator) {
|
||||
try {
|
||||
return divide(denominator);
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
return new NumeroAvanzato();
|
||||
}
|
||||
}
|
||||
|
||||
} /* NumeroAvanzato */
|
@ -1,772 +0,0 @@
|
||||
package org.nevec.rjm;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.MathContext;
|
||||
import java.util.Comparator;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.Variables;
|
||||
|
||||
/**
|
||||
* A NumeroAvanzatoVec represents an algebraic sum or differences of values
|
||||
* which each
|
||||
* term an instance of NumeroAvanzato. This mainly means that sums or
|
||||
* differences of
|
||||
* two NumeroAvanzato (or two NumeroAvanzatoVec) can be represented (exactly) as
|
||||
* a NumeroAvanzatoVec.
|
||||
*
|
||||
* @since 2012-02-15
|
||||
* @author Richard J. Mathar
|
||||
*/
|
||||
public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
|
||||
/**
|
||||
* The value of zero.
|
||||
*/
|
||||
public static final NumeroAvanzatoVec ZERO = new NumeroAvanzatoVec();
|
||||
|
||||
/**
|
||||
* The value of one.
|
||||
*/
|
||||
public static final NumeroAvanzatoVec ONE = new NumeroAvanzatoVec(NumeroAvanzato.ONE);
|
||||
|
||||
/**
|
||||
* Internal representation: Each term as a single NumeroAvanzato. The value
|
||||
* zero is
|
||||
* represented by an empty vector.
|
||||
*/
|
||||
Vector<NumeroAvanzato> terms;
|
||||
|
||||
/**
|
||||
* Default ctor, which represents the zero.
|
||||
*
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public NumeroAvanzatoVec() {
|
||||
terms = new Vector<NumeroAvanzato>();
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
* ctor given the value of a NumeroAvanzato.
|
||||
*
|
||||
* @param a
|
||||
* The value to be represented by this vector.
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public NumeroAvanzatoVec(NumeroAvanzato a) {
|
||||
terms = new Vector<NumeroAvanzato>(1);
|
||||
terms.add(a);
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
* ctor given two values, which (when added) represent this number a+b.
|
||||
*
|
||||
* @param a
|
||||
* The value to be represented by the first term of the vector.
|
||||
* @param b
|
||||
* The value to be represented by the second term of the vector.
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public NumeroAvanzatoVec(NumeroAvanzato a, NumeroAvanzato b) {
|
||||
terms = new Vector<NumeroAvanzato>(2);
|
||||
terms.add(a);
|
||||
terms.add(b);
|
||||
try {
|
||||
normalize();
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} /* ctor */
|
||||
|
||||
/**
|
||||
* Combine terms that can be written as a single surd. This unites for
|
||||
* example the terms sqrt(90) and sqrt(10) to 4*sqrt(10).
|
||||
*
|
||||
* @throws Error
|
||||
*
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
protected void normalize() throws Error {
|
||||
/*
|
||||
* nothing to be done if at most one term
|
||||
*/
|
||||
if (terms.size() <= 1)
|
||||
return;
|
||||
|
||||
Vector<NumeroAvanzato> newter = new Vector<NumeroAvanzato>();
|
||||
newter.add(terms.firstElement());
|
||||
/*
|
||||
* add j-th element to the existing vector and combine were possible
|
||||
*/
|
||||
for (int j = 1; j < terms.size(); j++) {
|
||||
NumeroAvanzato todo = terms.elementAt(j);
|
||||
boolean merged = false;
|
||||
for (int ex = 0; ex < newter.size(); ex++) {
|
||||
NumeroAvanzato v = newter.elementAt(ex);
|
||||
/*
|
||||
* try to merge terms[j] and newter[ex]. todo = r * v with r a
|
||||
* rational number is needed. Replaces v with v+todo = v*(1+r)
|
||||
* if this reduction works.
|
||||
*/
|
||||
NumeroAvanzato r = todo.divide(v);
|
||||
if ((r.isRational(true) || r.isTooPreciseRational(true)) && todo.getVariableX().compareTo(v.getVariableX()) && todo.getVariableY().compareTo(v.getVariableY()) && todo.getVariableZ().compareTo(v.getVariableZ())) {
|
||||
/* compute r+1 */
|
||||
Rational newpref = r.toRational(true).add(1);
|
||||
/*
|
||||
* eliminate accidental zeros; overwrite with v*(1+r).
|
||||
*/
|
||||
if (newpref.compareTo(Rational.ZERO) == 0)
|
||||
newter.removeElementAt(ex);
|
||||
else {
|
||||
v = v.multiply(newpref);
|
||||
newter.setElementAt(v, ex);
|
||||
}
|
||||
merged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* append if none of the existing elements matched
|
||||
*/
|
||||
if (!merged)
|
||||
newter.add(todo);
|
||||
}
|
||||
|
||||
newter.sort(new Comparator<NumeroAvanzato>() {
|
||||
@Override
|
||||
public int compare(NumeroAvanzato o1, NumeroAvanzato o2) {
|
||||
int index1 = Variables.priority(o1.getVariableX().sqrt().multiply(o1.getVariableY()).divide(o1.getVariableZ()));
|
||||
int index2 = Variables.priority(o2.getVariableX().sqrt().multiply(o2.getVariableY()).divide(o2.getVariableZ()));
|
||||
return index2 - index1;
|
||||
}
|
||||
});
|
||||
|
||||
/* overwrite old version */
|
||||
terms = newter;
|
||||
} /* normalize */
|
||||
|
||||
/**
|
||||
* Compare algebraic value with oth. Returns -1, 0 or +1 depending on
|
||||
* whether this is smaller, equal to or larger than oth.
|
||||
*
|
||||
* @param oth
|
||||
* The value with which this is to be compared.
|
||||
* @return 0 or +-1.
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(NumeroAvanzatoVec oth) {
|
||||
NumeroAvanzatoVec diff;
|
||||
try {
|
||||
diff = this.subtract(oth);
|
||||
return diff.signum();
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
} /* compareTo */
|
||||
|
||||
/**
|
||||
* Sign function. Returns -1, 0 or +1 depending on whether this is smaller,
|
||||
* equal to or larger than zero.
|
||||
*
|
||||
* @return 0 or +-1.
|
||||
* @throws Error
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public int signum() throws Error {
|
||||
/*
|
||||
* the case of zero is unique, because no (reduced) vector of surds
|
||||
* other than the one element 0 itself can add/subtract to zero.
|
||||
*/
|
||||
if (terms.size() == 0)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* if there is one term: forward to the signum function of
|
||||
* NumeroAvanzato
|
||||
*/
|
||||
if (terms.size() == 1)
|
||||
return terms.firstElement().signum();
|
||||
|
||||
/*
|
||||
* if all terms have a common sign: take that one offsig is the index of
|
||||
* the first "offending" term in the sense that its sign doese not agree
|
||||
* with the term[0].
|
||||
*/
|
||||
int sig0 = terms.elementAt(0).signum();
|
||||
int offsig = 1;
|
||||
for (; offsig < terms.size(); offsig++)
|
||||
if (terms.elementAt(offsig).signum() != sig0)
|
||||
break;
|
||||
if (offsig >= terms.size())
|
||||
return sig0;
|
||||
|
||||
/*
|
||||
* if there are two terms (now known to have different sign): forward to
|
||||
* the comparison of the two elements as NumeroAvanzatos
|
||||
*/
|
||||
if (terms.size() == 2)
|
||||
return terms.elementAt(0).signumComparedTo(terms.elementAt(1).negate());
|
||||
|
||||
/*
|
||||
* if there are three terms, move the one with the offending sign to the
|
||||
* other side and square both sides (which looses the sign) to remove
|
||||
* all but one surds. The difference of the squared sides contains at
|
||||
* most two terms, which reduces to the case above. t(0)+t(offbar) <>
|
||||
* -t(offs)
|
||||
*/
|
||||
if (terms.size() == 3) {
|
||||
NumeroAvanzatoVec lhs;
|
||||
if (offsig == 2)
|
||||
lhs = new NumeroAvanzatoVec(terms.elementAt(0), terms.elementAt(1));
|
||||
else
|
||||
lhs = new NumeroAvanzatoVec(terms.elementAt(0), terms.elementAt(2));
|
||||
lhs = lhs.sqr();
|
||||
/*
|
||||
* Strange line: this line isn't used, but it's present in this
|
||||
* code!
|
||||
*
|
||||
*
|
||||
*
|
||||
* NumeroAvanzato rhs = new
|
||||
* NumeroAvanzato(terms.elementAt(offsig).sqr(), Rational.ONE);
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
if (lhs.compareTo(lhs) > 0)
|
||||
/*
|
||||
* dominating sign was t(0)+t(offbar)
|
||||
*/
|
||||
return terms.elementAt(0).signum();
|
||||
else
|
||||
return terms.elementAt(offsig).signum();
|
||||
}
|
||||
|
||||
/*
|
||||
* for a larger number of terms: take a floating point representation
|
||||
* with a small but correct number of digits, and resume with the sign
|
||||
* of that one.
|
||||
*/
|
||||
return (floatValue() > 0.) ? 1 : -1;
|
||||
|
||||
} /* signum */
|
||||
|
||||
/**
|
||||
* Construct an approximate floating point representation
|
||||
*
|
||||
* @param mc
|
||||
* The intended accuracy of the result.
|
||||
* @return A truncated version with the precision described by mc
|
||||
*/
|
||||
public BigDecimal BigDecimalValue(MathContext mc) {
|
||||
/*
|
||||
* simple cases with one term forwarded to the NumeroAvanzato class
|
||||
*/
|
||||
if (terms.size() == 0)
|
||||
return BigDecimal.ZERO;
|
||||
else if (terms.size() == 1) {
|
||||
return terms.firstElement().BigDecimalValue(mc);
|
||||
}
|
||||
|
||||
/*
|
||||
* To reduce cancellation errors, loop over increasing local precision
|
||||
* until we are stable to the required result. Keep the old (less
|
||||
* precise) estimate in res[0], and the newer, more precise in res[1].
|
||||
*/
|
||||
BigDecimal[] res = new BigDecimal[2];
|
||||
res[0] = BigDecimal.ZERO;
|
||||
for (int addpr = 1;; addpr += 3) {
|
||||
MathContext locmc = new MathContext(mc.getPrecision() + addpr, mc.getRoundingMode());
|
||||
res[1] = BigDecimal.ZERO;
|
||||
for (NumeroAvanzato j : terms)
|
||||
res[1] = BigDecimalMath.addRound(res[1], j.BigDecimalValue(locmc));
|
||||
if (addpr > 1) {
|
||||
BigDecimal err = res[1].subtract(res[0]).abs();
|
||||
int prec = BigDecimalMath.err2prec(res[1], err);
|
||||
if (prec == Integer.MIN_VALUE) {
|
||||
break;
|
||||
}
|
||||
if (prec > mc.getPrecision())
|
||||
break;
|
||||
}
|
||||
res[0] = res[1];
|
||||
}
|
||||
return BigDecimalMath.scalePrec(res[1], mc);
|
||||
|
||||
} /* BigDecimalValue */
|
||||
|
||||
/**
|
||||
* Construct an approximate floating point representation
|
||||
*
|
||||
* @return A truncated version with the precision described by mc
|
||||
*/
|
||||
public double doubleValue() {
|
||||
BigDecimal bd = BigDecimalValue(MathContext.DECIMAL128);
|
||||
return bd.doubleValue();
|
||||
} /* doubleValue */
|
||||
|
||||
/**
|
||||
* Construct an approximate floating point representation
|
||||
*
|
||||
* @return A truncated version with the precision described by mc
|
||||
*/
|
||||
public double floatValue() {
|
||||
BigDecimal bd = BigDecimalValue(MathContext.DECIMAL64);
|
||||
return bd.floatValue();
|
||||
} /* floatValue */
|
||||
|
||||
/**
|
||||
* Add two vectors algebraically.
|
||||
*
|
||||
* @param val
|
||||
* The value to be added to this.
|
||||
* @return The new value representing this+val.
|
||||
* @throws Error
|
||||
*/
|
||||
public NumeroAvanzatoVec add(final NumeroAvanzatoVec val) throws Error {
|
||||
NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
|
||||
/*
|
||||
* concatenate the vectors and eliminate common overlaps
|
||||
*/
|
||||
for (NumeroAvanzato term : terms) {
|
||||
if (term.signumComparedTo(NumeroAvanzato.ZERO) != 0) {
|
||||
sum.terms.add(term);
|
||||
}
|
||||
}
|
||||
for (NumeroAvanzato term : val.terms) {
|
||||
if (term.signumComparedTo(NumeroAvanzato.ZERO) != 0) {
|
||||
sum.terms.add(term);
|
||||
}
|
||||
}
|
||||
sum.normalize();
|
||||
return sum;
|
||||
} /* add */
|
||||
|
||||
/**
|
||||
* Add two vectors algebraically.
|
||||
*
|
||||
* @param val
|
||||
* The value to be added to this.
|
||||
* @return The new value representing this+val.
|
||||
* @throws Error
|
||||
*/
|
||||
public NumeroAvanzatoVec add(final NumeroAvanzato val) throws Error {
|
||||
NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
|
||||
/*
|
||||
* concatenate the vectors and eliminate common overlaps
|
||||
*/
|
||||
sum.terms.addAll(terms);
|
||||
sum.terms.add(val);
|
||||
sum.normalize();
|
||||
return sum;
|
||||
} /* add */
|
||||
|
||||
/**
|
||||
* Subtract another number.
|
||||
*
|
||||
* @param val
|
||||
* The value to be subtracted from this.
|
||||
* @return The new value representing this-val.
|
||||
* @throws Error
|
||||
*/
|
||||
public NumeroAvanzatoVec subtract(final NumeroAvanzatoVec val) throws Error {
|
||||
NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
|
||||
/*
|
||||
* concatenate the vectors and eliminate common overlaps
|
||||
*/
|
||||
sum.terms.addAll(terms);
|
||||
for (NumeroAvanzato s : val.terms)
|
||||
sum.terms.add(s.negate());
|
||||
sum.normalize();
|
||||
return sum;
|
||||
} /* subtract */
|
||||
|
||||
/**
|
||||
* Subtract another number.
|
||||
*
|
||||
* @param val
|
||||
* The value to be subtracted from this.
|
||||
* @return The new value representing this-val.
|
||||
* @throws Error
|
||||
*/
|
||||
public NumeroAvanzatoVec subtract(final NumeroAvanzato val) throws Error {
|
||||
NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
|
||||
/*
|
||||
* concatenate the vectors and eliminate common overlaps
|
||||
*/
|
||||
sum.terms.addAll(terms);
|
||||
sum.terms.add(val.negate());
|
||||
sum.normalize();
|
||||
return sum;
|
||||
} /* subtract */
|
||||
|
||||
/**
|
||||
* Compute the negative.
|
||||
*
|
||||
* @return -this.
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public NumeroAvanzatoVec negate() {
|
||||
/*
|
||||
* accumulate the negated elements of term one by one
|
||||
*/
|
||||
NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
|
||||
for (NumeroAvanzato s : terms)
|
||||
resul.terms.add(s.negate());
|
||||
/*
|
||||
* no normalization step here, because the negation of all terms does
|
||||
* not introduce new common factors
|
||||
*/
|
||||
return resul;
|
||||
} /* negate */
|
||||
|
||||
/**
|
||||
* Compute the square.
|
||||
*
|
||||
* @return this value squared.
|
||||
* @throws Error
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public NumeroAvanzatoVec sqr() throws Error {
|
||||
/*
|
||||
* Binomial expansion. First the sum of the terms squared, then 2 times
|
||||
* the mixed products.
|
||||
*/
|
||||
NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
|
||||
for (int i = 0; i < terms.size(); i++)
|
||||
resul.terms.add(terms.elementAt(i).pow2());
|
||||
for (int i = 0; i < terms.size() - 1; i++)
|
||||
for (int j = i + 1; j < terms.size(); j++)
|
||||
resul.terms.add(terms.elementAt(i).multiply(terms.elementAt(j)).multiply(2));
|
||||
resul.normalize();
|
||||
return resul;
|
||||
} /* sqr */
|
||||
|
||||
/**
|
||||
* Multiply by another square root.
|
||||
*
|
||||
* @param val
|
||||
* a second number of this type.
|
||||
* @return the product of this with the val.
|
||||
* @throws Error
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public NumeroAvanzatoVec multiply(final NumeroAvanzato val) throws Error {
|
||||
NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
|
||||
for (NumeroAvanzato s : terms)
|
||||
resul.terms.add(s.multiply(val));
|
||||
resul.normalize();
|
||||
return resul;
|
||||
} /* multiply */
|
||||
|
||||
public NumeroAvanzatoVec multiply(final NumeroAvanzatoVec val) throws Error {
|
||||
NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
|
||||
for (NumeroAvanzato s : terms) {
|
||||
for (NumeroAvanzato s2 : val.terms) {
|
||||
resul = resul.add(s.multiply(s2));
|
||||
}
|
||||
}
|
||||
return resul;
|
||||
} /* multiply */
|
||||
|
||||
public NumeroAvanzatoVec divide(final NumeroAvanzato val) throws Error {
|
||||
NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
|
||||
for (NumeroAvanzato s : terms) {
|
||||
resul.terms.add(s.divide(val));
|
||||
}
|
||||
resul.normalize();
|
||||
return resul;
|
||||
} /* divide */
|
||||
|
||||
public NumeroAvanzatoVec divide(final NumeroAvanzatoVec val) throws Error {
|
||||
NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
|
||||
resul.terms = this.terms;
|
||||
for (NumeroAvanzato s : val.terms) {
|
||||
resul = resul.divide(s);
|
||||
}
|
||||
return resul;
|
||||
} /* divide */
|
||||
|
||||
/**
|
||||
* True if the value is rational. Equivalent to the indication whether a
|
||||
* conversion to a Rational can be exact.
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public boolean isRational(boolean hasRationalVariables) {
|
||||
boolean val = false;
|
||||
for (NumeroAvanzato s : terms) {
|
||||
val = s.isRational(hasRationalVariables);
|
||||
if (val == false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
} /* NumeroAvanzatoVec.isRational */
|
||||
|
||||
public boolean isNumeroAvanzato() {
|
||||
return (this.terms.size() <= 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean hasVariables() {
|
||||
for (NumeroAvanzato s : terms) {
|
||||
if ((s.getVariableX().count() | s.getVariableY().count() | s.getVariableZ().count()) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the value is BigInteger. Equivalent to the indication whether a
|
||||
* conversion to a BigInteger can be exact.
|
||||
*
|
||||
* @since 2011-02-12
|
||||
*/
|
||||
public boolean isBigInteger(boolean hasBigIntegerVariables) {
|
||||
boolean val = false;
|
||||
for (NumeroAvanzato s : terms) {
|
||||
val = s.isBigInteger(hasBigIntegerVariables);
|
||||
if (val == true) {
|
||||
if (s.getVariableX().count() > 0 || s.getVariableZ().count() > 0) {
|
||||
val = false;
|
||||
}
|
||||
}
|
||||
if (val == false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return val;
|
||||
} /* NumeroAvanzatoVec.isRational */
|
||||
|
||||
/**
|
||||
* Convert to a rational value if possible
|
||||
*
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public Rational toRational(boolean hasRationalVariables) {
|
||||
Rational rat = Rational.ZERO;
|
||||
if (isRational(hasRationalVariables) == false)
|
||||
throw new ArithmeticException("Undefined conversion " + toString() + " to Rational.");
|
||||
for (NumeroAvanzato s : terms) {
|
||||
rat = rat.add(s.pref);
|
||||
}
|
||||
return rat;
|
||||
} /* NumeroAvanzato.toRational */
|
||||
|
||||
/**
|
||||
* Convert to a BigInteger value if possible
|
||||
*
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigInteger toBigInteger(boolean hasBigIntegerVariables) {
|
||||
BigDecimal tmp = BigDecimal.ZERO.setScale(Utils.scale, Utils.scaleMode);
|
||||
if (isBigInteger(hasBigIntegerVariables) == false)
|
||||
throw new ArithmeticException("Undefined conversion " + toString() + " to BigInteger.");
|
||||
for (NumeroAvanzato s : terms) {
|
||||
tmp = BigDecimalMath.addRound(tmp, s.pref.BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2)));
|
||||
}
|
||||
return tmp.toBigInteger();
|
||||
} /* NumeroAvanzato.toRational */
|
||||
|
||||
/**
|
||||
* Convert to a BigDecimal value if possible
|
||||
*
|
||||
* @since 2012-02-15
|
||||
*/
|
||||
public BigDecimal toBigDecimal() {
|
||||
BigDecimal tmp = BigDecimal.ZERO.setScale(Utils.scale, Utils.scaleMode);
|
||||
for (NumeroAvanzato s : terms) {
|
||||
tmp = BigDecimalMath.addRound(tmp, s.BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2)));
|
||||
}
|
||||
return tmp;
|
||||
} /* NumeroAvanzato.toBigDecimal */
|
||||
|
||||
public NumeroAvanzato toNumeroAvanzato() {
|
||||
if (this.terms.size() == 0) {
|
||||
return NumeroAvanzato.ZERO;
|
||||
}
|
||||
return this.terms.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string in the format (number/denom)*()^(1/2). If the
|
||||
* discriminant equals 1, print just the prefactor.
|
||||
*
|
||||
* @return the human-readable version in base 10
|
||||
* @since 2012-02-16
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
/*
|
||||
* simple cases with one term forwarded to the NumeroAvanzato class
|
||||
*/
|
||||
return toFancyString();
|
||||
/*
|
||||
* if (terms.size() == 0)
|
||||
* return new String("0");
|
||||
* else {
|
||||
* String s = new String();
|
||||
* for (int t = 0; t < terms.size(); t++) {
|
||||
* NumeroAvanzato bs = terms.elementAt(t);
|
||||
* if (bs.signum() > 0)
|
||||
* s += "+";
|
||||
* s += bs.toString();
|
||||
* }
|
||||
* return s;
|
||||
* }
|
||||
*/
|
||||
} /* toString */
|
||||
|
||||
public String toFancyString() {
|
||||
if (terms.size() == 0) {
|
||||
return new String("0");
|
||||
} else if (terms.size() == 1 && terms.elementAt(0).isTooPreciseRational(true)) {
|
||||
String s = "";
|
||||
NumeroAvanzato bs = terms.elementAt(0).clone();
|
||||
String num = bs.BigDecimalValue(new MathContext(Utils.resultScale, Utils.scaleMode2)).toEngineeringString();
|
||||
if (num.contains("E")) {
|
||||
s += "(" + num.replace("E+", "*10^") + ")";
|
||||
} else {
|
||||
s += num;
|
||||
}
|
||||
s += bs.getVariableY().toString();
|
||||
return s;
|
||||
} else {
|
||||
BigInteger denominator = BigInteger.ONE;
|
||||
Variables incognitedenom = new Variables();
|
||||
for (int i = 0; i < terms.size(); i++) {
|
||||
denominator = BigIntegerMath.lcm(denominator, terms.elementAt(i).pref.b);
|
||||
// denominator =
|
||||
// denominator.multiply(terms.elementAt(i).pref.b);
|
||||
Variables iz = terms.elementAt(i).getVariableZ();
|
||||
incognitedenom = Variables.lcm(incognitedenom, iz);
|
||||
}
|
||||
String s = "";
|
||||
|
||||
if (denominator.abs().compareTo(new BigInteger("10000")) > 0) {
|
||||
for (int i = 0; i < terms.size(); i++) {
|
||||
NumeroAvanzato bs = terms.elementAt(i).clone();
|
||||
String num = bs.BigDecimalValue(new MathContext(Utils.resultScale, Utils.scaleMode2)).toEngineeringString().replaceAll("\\.0+$", "").replaceAll("\\.0+E", "E");
|
||||
if (num.contains("E")) {
|
||||
if (bs.signum() > 0) {
|
||||
s += "+";
|
||||
}
|
||||
num = num.replace("E+", "*10^") + ")";
|
||||
if (num.contains("*10^1)")) {
|
||||
num = num.replace("*10^1)", ")");
|
||||
} else {
|
||||
num = "(" + num;
|
||||
}
|
||||
s += num;
|
||||
} else {
|
||||
if (bs.signum() > 0) {
|
||||
s += "+";
|
||||
}
|
||||
s += num;
|
||||
}
|
||||
s += bs.getVariableY().toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
if (denominator.compareTo(BigInteger.ONE) != 0 || incognitedenom.count() > 0) {
|
||||
if (terms.size() == 1 && terms.get(0).multiply(denominator).isBigInteger(true) == false) {
|
||||
s += "(";
|
||||
}
|
||||
}
|
||||
for (int t = 0; t < terms.size(); t++) {
|
||||
NumeroAvanzato bs = terms.elementAt(t).clone();
|
||||
|
||||
bs = bs.setVariableY(bs.getVariableY().divide(bs.getVariableZ()));
|
||||
bs = bs.setVariableY(bs.getVariableY().multiply(incognitedenom));
|
||||
bs = bs.multiply(denominator);
|
||||
bs = bs.setVariableZ(incognitedenom);
|
||||
|
||||
bs.pref = new Rational(bs.pref.a, BigInteger.ONE);
|
||||
if (bs.signum() > 0 && t > 0)
|
||||
s += "+";
|
||||
if (bs.isBigInteger(true)) {
|
||||
String numb;
|
||||
try {
|
||||
numb = bs.toRational(true).a.toString();
|
||||
} catch (Error e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
numb = "";
|
||||
}
|
||||
String incognite = bs.getVariableY().toString();
|
||||
if (((numb.equals("1") || numb.equals("-1")) == false && incognite.length() > 0) || incognite.length() == 0) {
|
||||
s += numb;
|
||||
} else if (numb.equals("-1")) {
|
||||
s += "-";
|
||||
}
|
||||
s += incognite;
|
||||
} else if (bs.isRational(true) || bs.isTooPreciseRational(true)) {
|
||||
try {
|
||||
s += bs.toRational(true).toString();
|
||||
} catch (Error e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
s += bs.getVariableY().toString();
|
||||
} else {
|
||||
BigInteger numerator = bs.pref.numer();
|
||||
if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getVariableY().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getVariableX().count() > 0)) {
|
||||
if (((bs.getVariableY().count() > 0) || (bs.getVariableY().count() == 0 && numerator.toString().length() > 0))) {
|
||||
if ((bs.getVariableY().count() > 0 && (numerator.toString().equals("1") || numerator.toString().equals("-1")) == false) || bs.getVariableY().count() == 0) {
|
||||
s += numerator.toString();
|
||||
} else if (numerator.toString().equals("-1")) {
|
||||
s += "-";
|
||||
}
|
||||
}
|
||||
// s += "(";
|
||||
}
|
||||
if (bs.disc.isInteger() && bs.getVariableX().count() == 0) {
|
||||
s += "Ⓐ(";
|
||||
s += bs.disc.toString();
|
||||
s += ")";
|
||||
} else if ((bs.disc.toString().equals("1") || bs.disc.toString().equals("-1")) && bs.getVariableX().count() > 0) {
|
||||
s += "Ⓐ(";
|
||||
if (bs.disc.toString().equals("-1")) {
|
||||
s += "-";
|
||||
}
|
||||
s += bs.getVariableX().toString();
|
||||
s += ")";
|
||||
} else {
|
||||
s += "Ⓐ(" + bs.disc.toString() + bs.getVariableX().toString() + ")";
|
||||
}
|
||||
if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getVariableY().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getVariableX().count() > 0)) {
|
||||
if (((bs.getVariableY().count() > 0) || (bs.getVariableY().count() == 0 && numerator.toString().length() > 0))) {
|
||||
s += bs.getVariableY().toString();
|
||||
}
|
||||
// s += "(";
|
||||
}
|
||||
if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getVariableY().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getVariableX().count() > 0)) {
|
||||
// s += ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (denominator.compareTo(BigInteger.ONE) != 0 || incognitedenom.count() > 0) {
|
||||
if (terms.size() == 1 && terms.get(0).multiply(denominator).isBigInteger(true) == false) {
|
||||
s += ")";
|
||||
}
|
||||
s += "/";
|
||||
if ((incognitedenom.count() > 0 && (denominator.toString().equals("1") || denominator.toString().equals("-1")) == false) || incognitedenom.count() == 0) {
|
||||
s += denominator;
|
||||
} else if (denominator.toString().equals("-1")) {
|
||||
s += "-";
|
||||
}
|
||||
s += incognitedenom.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
} /* NumeroAvanzatoVec */
|
@ -2,8 +2,6 @@ package org.warp.picalculator;
|
||||
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.screens.EquationScreen;
|
||||
import org.warp.picalculator.screens.LoadingScreen;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
|
@ -2,9 +2,6 @@ package org.warp.picalculator;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -19,21 +16,24 @@ import org.nevec.rjm.BigDecimalMath;
|
||||
import org.nevec.rjm.Rational;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.math.Variable;
|
||||
import org.warp.picalculator.math.functions.AnteriorFunction;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.EmptyNumber;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.PrioritaryMultiplication;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.equations.EquationsSystemPart;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final int scale = 24;
|
||||
@ -120,7 +120,7 @@ public class Utils {
|
||||
|
||||
public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (fl.get(i) instanceof AnteriorFunction) {
|
||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
||||
return false;
|
||||
@ -139,7 +139,7 @@ public class Utils {
|
||||
|
||||
public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Subtraction || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (fl.get(i) instanceof AnteriorFunction) {
|
||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
||||
return false;
|
||||
@ -158,7 +158,7 @@ public class Utils {
|
||||
|
||||
public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (fl.get(i) instanceof AnteriorFunction) {
|
||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
||||
return false;
|
||||
@ -177,7 +177,7 @@ public class Utils {
|
||||
|
||||
public static boolean areThereOnlySettedUpFunctionsAndSystems(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
|
||||
if (fl.get(i) instanceof AnteriorFunction) {
|
||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
||||
return false;
|
||||
@ -207,7 +207,7 @@ public class Utils {
|
||||
|
||||
public static boolean areThereOnlyEmptyNSNFunctions(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
if (fl.get(i) instanceof FunctionTwoValues && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof PrioritaryMultiplication) && !(fl.get(i) instanceof Division)) {
|
||||
if (fl.get(i) instanceof FunctionTwoValues && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof SumSubtraction) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof Division)) {
|
||||
if (((FunctionTwoValues) fl.get(i)).getVariable1() == null && ((FunctionTwoValues) fl.get(i)).getVariable2() == null) {
|
||||
return true;
|
||||
}
|
||||
@ -215,18 +215,6 @@ public class Utils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static boolean areThereEmptyPrioritaryMultiplications(ArrayList<Function> funzioniOLD) {
|
||||
for (int i = 0; i < funzioniOLD.size(); i++) {
|
||||
if (funzioniOLD.get(i) instanceof PrioritaryMultiplication) {
|
||||
if (((FunctionTwoValues) funzioniOLD.get(i)).getVariable1() == null && ((FunctionTwoValues) funzioniOLD.get(i)).getVariable2() == null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean areThereEmptyMultiplications(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
@ -263,7 +251,7 @@ public class Utils {
|
||||
|
||||
public static boolean areThereOtherSettedUpFunctions(ArrayList<Function> fl) {
|
||||
for (int i = 0; i < fl.size(); i++) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunction || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Division)) {
|
||||
if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Variable || fl.get(i) instanceof Sum || fl.get(i) instanceof SumSubtraction || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunction || fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division)) {
|
||||
if (fl.get(i) instanceof AnteriorFunction) {
|
||||
if (((AnteriorFunction) fl.get(i)).getVariable() == null) {
|
||||
return true;
|
||||
@ -478,4 +466,13 @@ public class Utils {
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public static boolean isNegative(Function b) {
|
||||
if (b instanceof Negative) {
|
||||
return true;
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigInteger.ZERO) < 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.warp.picalculator.math;
|
||||
package org.warp.picalculator.deprecatedmath;
|
||||
|
||||
import org.nevec.rjm.Rational;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.warp.picalculator.math;
|
||||
package org.warp.picalculator.deprecatedmath;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Comparator;
|
@ -1,6 +1,5 @@
|
||||
package org.warp.picalculator.device;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.chip.ParallelToSerial;
|
||||
import org.warp.picalculator.device.chip.SerialToParallel;
|
||||
@ -326,6 +325,14 @@ public class Keyboard {
|
||||
} else {
|
||||
keyPressed(Key.PARENTHESIS_CLOSE);
|
||||
}
|
||||
} else if (row == 5 && col == 6) {
|
||||
if (shift) {
|
||||
keyPressed(Key.NONE);
|
||||
} else if (alpha) {
|
||||
keyPressed(Key.NONE);
|
||||
} else {
|
||||
keyPressed(Key.SURD_MODE);
|
||||
}
|
||||
} else if (row == 2 && col == 1) {
|
||||
if (shift) {
|
||||
keyPressed(Key.NONE);
|
||||
@ -484,7 +491,7 @@ public class Keyboard {
|
||||
}
|
||||
|
||||
public static enum Key {
|
||||
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, DRG_CYCLE, LETTER_X, LETTER_Y, SIMPLIFY, SOLVE, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x
|
||||
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, SIMPLIFY, SOLVE, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x
|
||||
}
|
||||
}
|
||||
|
||||
@ -509,7 +516,7 @@ public class Keyboard {
|
||||
| | | | | | | |
|
||||
| | | | | | | |
|
||||
|5,1---|5,2---|5,3---|5,4---|5,5---|5,6---|5,7---|
|
||||
| | | | | | | |
|
||||
| | | | | |S<=>D | |
|
||||
| | | | | | | |
|
||||
| | | | | | | |
|
||||
|6,1---|6,2---|6,3---|6,4---|6,5---|6,6---|6,7---|
|
||||
|
@ -12,7 +12,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.device.graphicengine.Display.Startable;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
@ -31,13 +30,13 @@ public final class PIDisplay {
|
||||
public static PIDisplay INSTANCE;
|
||||
private static float brightness;
|
||||
|
||||
private int[] skin;
|
||||
private int[] skinSize;
|
||||
private static int[] skin;
|
||||
private static int[] skinSize;
|
||||
public static RAWFont[] fonts;
|
||||
|
||||
public static String error = null;
|
||||
public String[] errorStackTrace = null;
|
||||
public final static int[] glyphsHeight = new int[] { 9, 6, 18, 12 };
|
||||
public final static int[] glyphsHeight = new int[] { 9, 6, 12, 9 };
|
||||
|
||||
public static Screen screen;
|
||||
public static String displayDebugString = "";
|
||||
@ -153,7 +152,6 @@ public final class PIDisplay {
|
||||
Calculator.currentSession += 1;
|
||||
}
|
||||
PIDisplay.screen = Calculator.sessions[Calculator.currentSession];
|
||||
Utils.debug.println("Current session: " + Calculator.currentSession);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,9 +204,9 @@ public final class PIDisplay {
|
||||
fonts[1] = new RAWFont();
|
||||
fonts[1].create("small");
|
||||
fonts[2] = new RAWFont();
|
||||
fonts[2].create("big_2x");
|
||||
fonts[2].create("ex");
|
||||
fonts[3] = new RAWFont();
|
||||
fonts[3].create("small_2x");
|
||||
fonts[3].create("big");
|
||||
fonts[4] = new RAWFont();
|
||||
fonts[4].create("32");
|
||||
fonts[5] = new RAWFont();
|
||||
@ -220,16 +218,16 @@ public final class PIDisplay {
|
||||
glClear();
|
||||
}
|
||||
|
||||
public void drawSkinPart(int x, int y, int sx1, int sy1, int sx2, int sy2) {
|
||||
public static void drawSkinPart(int x, int y, int sx1, int sy1, int sx2, int sy2) {
|
||||
glDrawSkin(skinSize[0], skin, x, y, sx1, sy1, sx2, sy2, false);
|
||||
}
|
||||
|
||||
private void draw_status() {
|
||||
glColor3f(204, 231, 212);
|
||||
glColor(0xFFc5c2af);
|
||||
glFillRect(0, 0, Main.screenSize[0], 20);
|
||||
glColor3f(0, 0, 0);
|
||||
glColor3i(0, 0, 0);
|
||||
glDrawLine(0, 20, Main.screenSize[0]-1, 20);
|
||||
glColor3f(0, 0, 0);
|
||||
glColor3i(0, 0, 0);
|
||||
if (Keyboard.shift) {
|
||||
drawSkinPart(2 + 18 * 0, 2, 16 * 2, 16 * 0, 16 + 16 * 2, 16 + 16 * 0);
|
||||
} else {
|
||||
@ -306,22 +304,22 @@ public final class PIDisplay {
|
||||
}
|
||||
|
||||
private void draw_world() {
|
||||
glColor3f(255, 255, 255);
|
||||
glColor3i(255, 255, 255);
|
||||
|
||||
if (error != null) {
|
||||
glSetFont(Utils.getFont(false, false));
|
||||
glColor3f(129, 28, 22);
|
||||
glColor3i(129, 28, 22);
|
||||
glDrawStringRight(Main.screenSize[0] - 2, Main.screenSize[1]- this.glyphsHeight[1] - 2, "ANDREA CAVALLI'S CALCULATOR");
|
||||
glColor3f(149, 32, 26);
|
||||
glColor3i(149, 32, 26);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), 22, error);
|
||||
glColor3f(164, 34, 28);
|
||||
glColor3i(164, 34, 28);
|
||||
int i = 22;
|
||||
for (String stackPart : errorStackTrace) {
|
||||
glDrawStringLeft(2, 22 + i, stackPart);
|
||||
i += 11;
|
||||
}
|
||||
glSetFont(fonts[0]);
|
||||
glColor3f(129, 28, 22);
|
||||
glColor3i(129, 28, 22);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION");
|
||||
} else {
|
||||
draw_screen();
|
||||
@ -353,7 +351,7 @@ public final class PIDisplay {
|
||||
|
||||
screen.beforeRender(dt);
|
||||
|
||||
if(dt >= 0.03 | screen.mustBeRefreshed()) {
|
||||
if(dt >= 0.03 || screen.mustBeRefreshed()) {
|
||||
draw();
|
||||
}
|
||||
|
||||
@ -437,6 +435,6 @@ public final class PIDisplay {
|
||||
|
||||
public static void colore(float f1, float f2, float f3, float f4) {
|
||||
PIDisplay.INSTANCE.colore = new float[] { f1, f2, f3, f4 };
|
||||
glColor4f((int) (f1 * 255), (int) (f2 * 255), (int) (f3 * 255), (int) (f4 * 255));
|
||||
glColor4i((int) (f1 * 255), (int) (f2 * 255), (int) (f3 * 255), (int) (f4 * 255));
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
package org.warp.picalculator.device.graphicengine;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
@ -98,11 +95,11 @@ public class Display {
|
||||
}
|
||||
|
||||
public static class Render {
|
||||
public static int clearcolor = 0xFFCCE7D4;
|
||||
public static int clearcolor = 0xFFc5c2af;
|
||||
public static RAWFont currentFont;
|
||||
|
||||
public static void glColor3f(int r, int gg, int b) {
|
||||
glColor4f(r, gg, b, 255);
|
||||
public static void glColor3i(int r, int gg, int b) {
|
||||
glColor4i(r, gg, b, 255);
|
||||
}
|
||||
|
||||
public static void glColor(int c) {
|
||||
@ -113,7 +110,7 @@ public class Display {
|
||||
clearcolor = c & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
public static void glColor4f(int red, int green, int blue, int alpha) {
|
||||
public static void glColor4i(int red, int green, int blue, int alpha) {
|
||||
color = (alpha << 24) + (red << 16) + (green << 8) + (blue);
|
||||
}
|
||||
|
||||
@ -263,11 +260,11 @@ public class Display {
|
||||
}
|
||||
|
||||
public static void glDrawStringCenter(int x, int y, String text) {
|
||||
glDrawStringLeft(x - (glGetStringWidth(text) / 2), y, text);
|
||||
glDrawStringLeft(x - (glGetStringWidth(Display.Render.currentFont, text) / 2), y, text);
|
||||
}
|
||||
|
||||
public static void glDrawStringRight(int x, int y, String text) {
|
||||
glDrawStringLeft(x - glGetStringWidth(text), y, text);
|
||||
glDrawStringLeft(x - glGetStringWidth(Display.Render.currentFont, text), y, text);
|
||||
}
|
||||
|
||||
public static void glSetFont(RAWFont font) {
|
||||
@ -276,16 +273,6 @@ public class Display {
|
||||
}
|
||||
}
|
||||
|
||||
public static int glGetStringWidth(String text) {
|
||||
int w =(currentFont.charW+1)*text.length();
|
||||
if (text.length() > 0) {
|
||||
return w-1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
// return text.length()*6;
|
||||
}
|
||||
|
||||
public static int glGetStringWidth(RAWFont rf, String text) {
|
||||
int w =(rf.charW+1)*text.length();
|
||||
if (text.length() > 0) {
|
||||
@ -300,6 +287,7 @@ public class Display {
|
||||
return fm.stringWidth(text);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static int glGetCurrentFontHeight() {
|
||||
return currentFont.charH;
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
package org.warp.picalculator.device.graphicengine;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ComponentEvent;
|
||||
@ -13,16 +11,14 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
|
||||
public class Frame extends JFrame {
|
||||
private static final long serialVersionUID = 2945898937634075491L;
|
||||
@ -118,7 +114,9 @@ public class Frame extends JFrame {
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ENTER:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.SIMPLIFY);
|
||||
} else if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
@ -203,6 +201,15 @@ public class Frame extends JFrame {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_S:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.SURD_MODE);
|
||||
} else if (Keyboard.shift) {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
} else {
|
||||
Keyboard.keyPressed(Key.NONE);
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_ADD:
|
||||
if (!Keyboard.shift && !Keyboard.alpha) {
|
||||
Keyboard.keyPressed(Key.PLUS);
|
||||
|
@ -155,19 +155,25 @@ public class RAWFont {
|
||||
int currentInt;
|
||||
int currentIntBitPosition;
|
||||
int bitData;
|
||||
int cpos;
|
||||
int j;
|
||||
final int l = text.length;
|
||||
for (int i = 0; i < l; i++) {
|
||||
cpos = (i * (charW + 1));
|
||||
final int charIndex = text[i];
|
||||
for (int dy = 0; dy < charH; dy++) {
|
||||
for (int dx = 0; dx < charW; dx++) {
|
||||
int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor((double)bit)/((double)intBits));
|
||||
currentIntBitPosition = bit-(currentInt*intBits);
|
||||
bitData = (chars32[charIndex*charIntCount+currentInt] >> currentIntBitPosition) & 1;
|
||||
screenPos = x + (i * (charW + 1)) + dx + (y + dy) * screenSize[0];
|
||||
if (bitData == 1 & screenLength > screenPos) {
|
||||
screen[screenPos] = color;
|
||||
}
|
||||
j = x + cpos + dx;
|
||||
if (j > 0 & j < screenSize[0]) {
|
||||
int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor((double)bit)/((double)intBits));
|
||||
currentIntBitPosition = bit-(currentInt*intBits);
|
||||
bitData = (chars32[charIndex*charIntCount+currentInt] >> currentIntBitPosition) & 1;
|
||||
screenPos = x + cpos + dx + (y + dy) * screenSize[0];
|
||||
if (bitData == 1 & screenLength > screenPos) {
|
||||
screen[screenPos] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.warp.picalculator.device.graphicengine;
|
||||
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
|
||||
public abstract class Screen {
|
||||
public PIDisplay d;
|
||||
|
@ -1,17 +1,16 @@
|
||||
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.nevec.rjm.NumeroAvanzato;
|
||||
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.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
@ -27,6 +26,7 @@ public class Calculator {
|
||||
public static Screen[] sessions = new Screen[5];
|
||||
public static int currentSession = 0;
|
||||
public static boolean haxMode = true;
|
||||
public static boolean surdMode = true;
|
||||
|
||||
public static Function parseString(String string) throws Error {
|
||||
if (string.contains("{")) {
|
||||
@ -36,7 +36,7 @@ public class Calculator {
|
||||
String[] parts = string.substring(1).split("\\{");
|
||||
EquationsSystem s = new EquationsSystem(null);
|
||||
for (String part : parts) {
|
||||
s.addVariableToEnd(parseEquationString(part));
|
||||
s.addFunctionToEnd(parseEquationString(part));
|
||||
}
|
||||
return s;
|
||||
} else if (string.contains("=")) {
|
||||
@ -51,7 +51,7 @@ public class Calculator {
|
||||
if (parts.length == 1) {
|
||||
Equation e = new Equation(null, null, null);
|
||||
e.setVariable1(new Expression(e, parts[0]));
|
||||
e.setVariable2(new Number(e, NumeroAvanzato.ZERO));
|
||||
e.setVariable2(new Number(e, BigInteger.ZERO));
|
||||
return e;
|
||||
} else if (parts.length == 2) {
|
||||
Equation e = new Equation(null, null, null);
|
||||
@ -63,12 +63,12 @@ public class Calculator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void solve(EquationScreen es) throws Error {
|
||||
List<Function> results = new ArrayList<>();
|
||||
List<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : es.f) {
|
||||
public static ArrayList<Function> solveExpression(ArrayList<Function> input) throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
ArrayList<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : input) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
||||
throw new IllegalArgumentException("Not an expression!");
|
||||
} else {
|
||||
results.add(f);
|
||||
while (Utils.allSolved(results) == false) {
|
||||
@ -85,6 +85,75 @@ public class Calculator {
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public static void solve(EquationScreen es) throws Error {
|
||||
for (Function f : es.f) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Function> results = solveExpression(es.f);
|
||||
if (results.size() == 0) {
|
||||
es.resultsCount = 0;
|
||||
} else {
|
||||
es.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);
|
||||
es.f2 = results;
|
||||
for (Function rf : es.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void solve(EquationScreen equationScreen, char letter) throws Error {
|
||||
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
|
||||
EquationScreen es = (EquationScreen) Calculator.sessions[0];
|
||||
ArrayList<Function> f = es.f;
|
||||
if (f instanceof Equation) {
|
||||
List<Function> results = ((Equation)f).solve(letter);
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
es.f2 = results;
|
||||
for (Function rf : es.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void simplify(EquationScreen es) throws Error {
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
ArrayList<Function> partialResults = new ArrayList<>();
|
||||
for (Function f : es.f2) {
|
||||
if (f instanceof Equation) {
|
||||
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
|
||||
} else {
|
||||
results.add(f);
|
||||
for (Function itm : results) {
|
||||
if (itm.isSolved() == false) {
|
||||
List<Function> dt = itm.solveOneStep();
|
||||
partialResults.addAll(dt);
|
||||
} else {
|
||||
partialResults.add(itm);
|
||||
}
|
||||
}
|
||||
results = new ArrayList<Function>(partialResults);
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
if (results.size() == 0) {
|
||||
es.resultsCount = 0;
|
||||
} else {
|
||||
@ -101,29 +170,5 @@ public class Calculator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void solve(EquationScreen equationScreen, char letter) throws Error {
|
||||
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
|
||||
EquationScreen es = (EquationScreen) Calculator.sessions[0];
|
||||
List<Function> f = es.f;
|
||||
if (f instanceof Equation) {
|
||||
List<Function> results = ((Equation)f).solve(letter);
|
||||
Collections.reverse(results);
|
||||
// add elements to al, including duplicates
|
||||
Set<Function> hs = new LinkedHashSet<>();
|
||||
hs.addAll(results);
|
||||
results.clear();
|
||||
results.addAll(hs);
|
||||
es.f2 = results;
|
||||
for (Function rf : es.f2) {
|
||||
rf.generateGraphics();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void simplify(EquationScreen equationScreen) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ public class MathematicalSymbols {
|
||||
public static final String SUBTRACTION = "−";
|
||||
public static final String MINUS = "-";
|
||||
public static final String MULTIPLICATION = "*";
|
||||
public static final String PRIORITARY_MULTIPLICATION = "▪";
|
||||
public static final String DIVISION = "/";
|
||||
public static final String NTH_ROOT = "√";
|
||||
public static final String SQUARE_ROOT = "Ⓐ";
|
||||
@ -32,14 +31,11 @@ public class MathematicalSymbols {
|
||||
return new String[] { SQUARE_ROOT, MINUS };
|
||||
}
|
||||
|
||||
public static final String[] signums(boolean withMultiplication, boolean withPrioritaryMultiplication) {
|
||||
public static final String[] signums(boolean withMultiplication) {
|
||||
String[] ret = new String[] { SUM, SUM_SUBTRACTION, SUBTRACTION, DIVISION };
|
||||
if (withMultiplication) {
|
||||
ret = Utils.add(ret, MULTIPLICATION);
|
||||
}
|
||||
if (withPrioritaryMultiplication) {
|
||||
ret = Utils.add(ret, PRIORITARY_MULTIPLICATION);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -48,7 +44,7 @@ public class MathematicalSymbols {
|
||||
}
|
||||
|
||||
public static String[] variables() {
|
||||
return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
|
||||
return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "ⓧ", "Ⓨ", "Z"};
|
||||
}
|
||||
|
||||
public static String[] genericSyntax() {
|
||||
|
@ -1,14 +1,13 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
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.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
@ -20,7 +19,7 @@ public abstract class AnteriorFunction implements Function {
|
||||
}
|
||||
|
||||
protected Function parent;
|
||||
protected Function variable = new Number(null, NumeroAvanzatoVec.ZERO);
|
||||
protected Function variable = new Number(null, BigInteger.ZERO);
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
@ -50,18 +49,18 @@ public abstract class AnteriorFunction implements Function {
|
||||
public abstract List<Function> solveOneStep() throws Error;
|
||||
|
||||
@Override
|
||||
public boolean isSolved() throws Error {
|
||||
public boolean isSolved() {
|
||||
return variable.isSolved() ? !isSolvable() : false;
|
||||
}
|
||||
|
||||
protected abstract boolean isSolvable() throws Error;
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
variable.setSmall(small);
|
||||
variable.generateGraphics();
|
||||
|
||||
width = glGetStringWidth(getSymbol()) + 1 + getVariable().getWidth();
|
||||
width = glGetStringWidth(Utils.getFont(small), getSymbol()) + 1 + getVariable().getWidth();
|
||||
height = variable.getHeight();
|
||||
line = variable.getLine();
|
||||
}
|
||||
@ -69,7 +68,7 @@ public abstract class AnteriorFunction implements Function {
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
float h1 = getVariable().getHeight();
|
||||
int wsegno = glGetStringWidth(getSymbol());
|
||||
int wsegno = glGetStringWidth(Utils.getFont(small), getSymbol());
|
||||
float hsegno = Utils.getFontHeight(small);
|
||||
float maxh = getHeight();
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
@ -97,7 +96,11 @@ public abstract class AnteriorFunction implements Function {
|
||||
public String toString() {
|
||||
// try {
|
||||
// return solve().toString();
|
||||
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||
String val1 = "null";
|
||||
if (variable != null) {
|
||||
val1 = variable.toString();
|
||||
}
|
||||
return getSymbol()+val1;
|
||||
// } catch (Error e) {
|
||||
// return e.id.toString();
|
||||
// }
|
||||
@ -120,7 +123,5 @@ public abstract class AnteriorFunction implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o != null && o.hashCode() == this.hashCode();
|
||||
}
|
||||
public abstract boolean equals(Object o);
|
||||
}
|
||||
|
@ -1,26 +1,21 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3f;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glFillRect;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
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.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.Display.Render;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.FractionsRule1;
|
||||
import org.warp.picalculator.math.rules.FractionsRule2;
|
||||
import org.warp.picalculator.math.rules.FractionsRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule1;
|
||||
import org.warp.picalculator.math.rules.NumberRule2;
|
||||
import org.warp.picalculator.math.rules.UndefinedRule2;
|
||||
|
||||
public class Division extends FunctionTwoValues {
|
||||
@ -36,7 +31,7 @@ public class Division extends FunctionTwoValues {
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (FractionsRule1.compare(this)) return true;
|
||||
if (FractionsRule2.compare(this)) return true;
|
||||
if (FractionsRule3.compare(this)) return true;
|
||||
@ -97,10 +92,8 @@ public class Division extends FunctionTwoValues {
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
variable1.setSmall(true);
|
||||
variable1.generateGraphics();
|
||||
|
||||
variable2.setSmall(true);
|
||||
variable2.generateGraphics();
|
||||
|
||||
width = calcWidth();
|
||||
@ -120,7 +113,7 @@ public class Division extends FunctionTwoValues {
|
||||
int minusw = 0;
|
||||
int minush = 0;
|
||||
String numerator = ((Function) var1).toString();
|
||||
if (numerator.startsWith("-") && ((Function) var1) instanceof Number && ((Number) var1).term.isBigInteger(true)) {
|
||||
if (numerator.startsWith("-") && ((Function) var1) instanceof Number) {
|
||||
minus = true;
|
||||
numerator = numerator.substring(1);
|
||||
}
|
||||
@ -128,8 +121,8 @@ public class Division extends FunctionTwoValues {
|
||||
int h1 = 0;
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
if (minus) {
|
||||
w1 = glGetStringWidth(numerator);
|
||||
h1 = Render.glGetCurrentFontHeight();
|
||||
w1 = glGetStringWidth(Utils.getFont(small), numerator);
|
||||
h1 = Utils.getFont(small).charH;
|
||||
} else {
|
||||
w1 = ((Function) var1).getWidth();
|
||||
h1 = ((Function) var1).getHeight();
|
||||
@ -142,15 +135,14 @@ public class Division extends FunctionTwoValues {
|
||||
maxw = 1 + w2;
|
||||
}
|
||||
if (minus && drawMinus) {
|
||||
minusw = glGetStringWidth("-") + 1;
|
||||
minush = Render.glGetCurrentFontHeight();
|
||||
minusw = glGetStringWidth(Utils.getFont(small), "-") + 1;
|
||||
minush = Utils.getFont(small).charH;
|
||||
glDrawStringLeft(x+1, y + h1 + 1 + 1 - (minush / 2), "-");
|
||||
glDrawStringLeft((int) (x+1 + minusw + 1 + (maxw - w1) / 2d), y, numerator);
|
||||
} else {
|
||||
((Function) var1).draw((int) (x+1 + minusw + (maxw - w1) / 2d), y);
|
||||
}
|
||||
((Function) var2).draw((int) (x+1 + minusw + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1);
|
||||
glColor3f(0, 0, 0);
|
||||
glFillRect(x+1+ minusw, y + h1 + 1, maxw, 1);
|
||||
}
|
||||
|
||||
@ -164,7 +156,7 @@ public class Division extends FunctionTwoValues {
|
||||
|
||||
boolean minus = false;
|
||||
String numerator = variable1.toString();
|
||||
if (numerator.startsWith("-") && variable1 instanceof Number && ((Number) variable1).term.isBigInteger(true)) {
|
||||
if (numerator.startsWith("-") && variable1 instanceof Number) {
|
||||
minus = true;
|
||||
numerator = numerator.substring(1);
|
||||
}
|
||||
@ -192,13 +184,13 @@ public class Division extends FunctionTwoValues {
|
||||
protected int calcWidth() {
|
||||
boolean minus = false;
|
||||
String numerator = variable1.toString();
|
||||
if (numerator.startsWith("-") && variable1 instanceof Number && ((Number) variable1).term.isBigInteger(true)) {
|
||||
if (numerator.startsWith("-") && variable1 instanceof Number) {
|
||||
minus = true;
|
||||
numerator = numerator.substring(1);
|
||||
}
|
||||
int w1 = 0;
|
||||
if (minus) {
|
||||
w1 = glGetStringWidth(numerator);
|
||||
w1 = glGetStringWidth(Utils.getFont(small), numerator);
|
||||
} else {
|
||||
w1 = variable1.getWidth();
|
||||
}
|
||||
@ -210,9 +202,18 @@ public class Division extends FunctionTwoValues {
|
||||
maxw = w2+1;
|
||||
}
|
||||
if (minus && drawMinus) {
|
||||
return 1 + glGetStringWidth("-") + 1 + maxw;
|
||||
return 1 + glGetStringWidth(Utils.getFont(small), "-") + 1 + maxw;
|
||||
} else {
|
||||
return 1 + maxw;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Division) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,10 +3,13 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
|
||||
public class EmptyNumber implements Function {
|
||||
|
||||
public static EmptyNumber emptyNumber = new EmptyNumber();
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return " ";
|
||||
@ -19,7 +22,7 @@ public class EmptyNumber implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolved() throws Error {
|
||||
public boolean isSolved() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -30,22 +33,22 @@ public class EmptyNumber implements Function {
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
Display.Render.glDrawStringLeft(x, y, " ");
|
||||
Display.Render.glDrawStringLeft(x, y, "␀");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return Display.Render.glGetStringWidth(" ");
|
||||
return Display.Render.glGetStringWidth(Utils.getFont(small), "␀");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return Display.Render.glGetCurrentFontHeight();
|
||||
return Utils.getFont(small).charH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLine() {
|
||||
return Display.Render.glGetCurrentFontHeight()/2;
|
||||
return Utils.getFont(small).charH/2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,9 +61,15 @@ public class EmptyNumber implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean small = false;
|
||||
|
||||
@Override
|
||||
public void setSmall(boolean small) {
|
||||
|
||||
this.small = small;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o instanceof EmptyNumber;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.Utils.ArrayToRegex;
|
||||
import static org.warp.picalculator.Utils.concat;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3f;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -12,15 +12,10 @@ import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzato;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.Variable;
|
||||
import org.warp.picalculator.math.Variables;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class Expression extends FunctionMultipleValues {
|
||||
|
||||
@ -33,7 +28,6 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
|
||||
private boolean initialParenthesis = false;
|
||||
private Function parent = null;
|
||||
|
||||
public Expression(Function parent, String string) throws Error {
|
||||
this(parent, string, "", true);
|
||||
@ -135,7 +129,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
|
||||
// Rimuovi i + in eccesso
|
||||
pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions()), "(")) + "]\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]+?[" + ArrayToRegex(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions())) + "]|[" + ArrayToRegex(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions())) + "]+?\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]");
|
||||
pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions()), "(")) + "]\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]+?[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions())) + "]|[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions())) + "]+?\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]");
|
||||
matcher = pattern.matcher(processExpression);
|
||||
symbolsChanged = false;
|
||||
while (matcher.find()) {
|
||||
@ -149,7 +143,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
processExpression = processExpression.replace("-", MathematicalSymbols.SUBTRACTION);
|
||||
|
||||
// Correggi i segni − dopo di espressioni o funzioni SN in -
|
||||
pattern = Pattern.compile("[" + Utils.ArrayToRegex(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.variables()), new String[] { MathematicalSymbols.PARENTHESIS_OPEN }), MathematicalSymbols.signums(true, true))) + "]" + MathematicalSymbols.SUBTRACTION);
|
||||
pattern = Pattern.compile("[" + Utils.ArrayToRegex(concat(concat(MathematicalSymbols.functions(), new String[] { MathematicalSymbols.PARENTHESIS_OPEN }), MathematicalSymbols.signums(true))) + "]" + MathematicalSymbols.SUBTRACTION);
|
||||
matcher = pattern.matcher(processExpression);
|
||||
while (matcher.find()) {
|
||||
symbolsChanged = true;
|
||||
@ -169,7 +163,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
|
||||
// Aggiungi le parentesi implicite per le potenze con una incognita
|
||||
pattern = Pattern.compile("(?<!(?:\\(|^))(["+Utils.ArrayToRegex(MathematicalSymbols.variables())+"]+"+MathematicalSymbols.POWER+"[^" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functionsNSN(), concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.genericSyntax())), ")")) + "])(?!\\))");
|
||||
pattern = Pattern.compile("(?<!(?:\\(|^))(["+Utils.ArrayToRegex(MathematicalSymbols.variables())+"]+"+MathematicalSymbols.POWER+"[^" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functionsNSN(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), ")")) + "])(?!\\))");
|
||||
matcher = pattern.matcher(processExpression);
|
||||
symbolsChanged = false;
|
||||
while (matcher.find()) {
|
||||
@ -190,11 +184,11 @@ public class Expression extends FunctionMultipleValues {
|
||||
String beforeexp = processExpression.substring(0, matcher.start(0));
|
||||
String newexp = matcher.group(0).substring(1, matcher.group(0).length() - 1);
|
||||
String afterexp = processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
|
||||
if (Pattern.compile("[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.genericSyntax())), "(")) + "]$").matcher(beforeexp).find()) {
|
||||
if (Pattern.compile("[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), "(")) + "]$").matcher(beforeexp).find()) {
|
||||
// Se la stringa precedente finisce con un numero
|
||||
beforeexp += MathematicalSymbols.MULTIPLICATION;
|
||||
}
|
||||
if (Pattern.compile("^[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.genericSyntax())), ")")) + "]").matcher(afterexp).find()) {
|
||||
if (Pattern.compile("^[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), ")")) + "]").matcher(afterexp).find()) {
|
||||
// Se la stringa successiva inizia con un numero
|
||||
afterexp = MathematicalSymbols.MULTIPLICATION + afterexp;
|
||||
}
|
||||
@ -216,7 +210,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
Expression imputRawParenthesis = new Expression(this);
|
||||
imputRawParenthesis.setVariables(new Function[] {});
|
||||
String tmp = "";
|
||||
final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true, true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
|
||||
final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
|
||||
for (int i = 0; i < processExpression.length(); i++) {
|
||||
// Per ogni carattere cerca se è un numero o una funzione:
|
||||
String charI = processExpression.charAt(i) + "";
|
||||
@ -241,9 +235,6 @@ public class Expression extends FunctionMultipleValues {
|
||||
case MathematicalSymbols.MULTIPLICATION:
|
||||
f = new Multiplication(this, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.PRIORITARY_MULTIPLICATION:
|
||||
f = new PrioritaryMultiplication(this, null, null);
|
||||
break;
|
||||
case MathematicalSymbols.DIVISION:
|
||||
f = new Division(this, null, null);
|
||||
break;
|
||||
@ -291,45 +282,43 @@ public class Expression extends FunctionMultipleValues {
|
||||
break;
|
||||
default:
|
||||
if (Utils.isInArray(charI, MathematicalSymbols.variables())) {
|
||||
// Fallback
|
||||
NumeroAvanzato na = NumeroAvanzato.ONE;
|
||||
Variables iy = na.getVariableY();
|
||||
Variable var1 = new Variable(charI.charAt(0), 1, 1);
|
||||
List<Variable> newVariableList = iy.getVariablesList();
|
||||
newVariableList.add(var1);
|
||||
iy = new Variables(newVariableList.toArray(new Variable[newVariableList.size()]));
|
||||
na = na.setVariableY(iy);
|
||||
f = new Number(this, na);
|
||||
f = new Variable(this, charI);
|
||||
} else {
|
||||
throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!");
|
||||
if (charI == "(" || charI == ")") {
|
||||
throw new Error(Errors.UNBALANCED_BRACKETS);
|
||||
} else {
|
||||
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!");
|
||||
}
|
||||
}
|
||||
if (f instanceof Expression) {
|
||||
tmp = "";
|
||||
} else if (f instanceof Number) {
|
||||
} else if (f instanceof Variable) {
|
||||
if (imputRawParenthesis.getVariablesLength() == 0) {
|
||||
if (tmp.length() > 0) {
|
||||
imputRawParenthesis.addVariableToEnd(new Number(this, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added value to expression:" + tmp);
|
||||
imputRawParenthesis.addVariableToEnd(new PrioritaryMultiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + new PrioritaryMultiplication(this, null, null).getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, 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());
|
||||
}
|
||||
} else {
|
||||
Function precedentFunction = imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1);
|
||||
if (tmp.length() > 0) {
|
||||
if (imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1) instanceof Number) {
|
||||
imputRawParenthesis.addVariableToEnd(new PrioritaryMultiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + new PrioritaryMultiplication(this, null, null).getSymbol());
|
||||
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());
|
||||
}
|
||||
if (tmp.equals("-")) {
|
||||
imputRawParenthesis.addVariableToEnd(new Subtraction(this, null, null));
|
||||
imputRawParenthesis.addFunctionToEnd(new Subtraction(this, null, null));
|
||||
} else {
|
||||
imputRawParenthesis.addVariableToEnd(new Number(this, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added value to expression:" + tmp);
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
}
|
||||
}
|
||||
if (tmp.length() > 0 || imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1) instanceof Number) {
|
||||
imputRawParenthesis.addVariableToEnd(new PrioritaryMultiplication(this, null, null));
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + new PrioritaryMultiplication(this, null, null).getSymbol());
|
||||
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());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -339,12 +328,12 @@ public class Expression extends FunctionMultipleValues {
|
||||
tmp = "-1";
|
||||
}
|
||||
}
|
||||
imputRawParenthesis.addVariableToEnd(new Number(this, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
Utils.debug.println(debugSpaces + "•Added number to expression:" + tmp);
|
||||
}
|
||||
}
|
||||
imputRawParenthesis.addVariableToEnd(f);
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getSymbol());
|
||||
imputRawParenthesis.addFunctionToEnd(f);
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getSymbol() + (f instanceof Number ? " (number)" : " (variable)"));
|
||||
tmp = "";
|
||||
} else {
|
||||
try {
|
||||
@ -362,7 +351,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (tmp.length() > 0) {
|
||||
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
|
||||
try {
|
||||
imputRawParenthesis.addVariableToEnd(new Number(this, tmp));
|
||||
imputRawParenthesis.addFunctionToEnd(new Number(this, tmp));
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
@ -378,13 +367,13 @@ public class Expression extends FunctionMultipleValues {
|
||||
// Fine suddivisione di insieme
|
||||
|
||||
Utils.debug.println(debugSpaces + "•Removing useless parentheses");
|
||||
for (int i = 0; i < imputRawParenthesis.variables.length; i++) {
|
||||
if (imputRawParenthesis.variables[i] instanceof Expression) {
|
||||
Expression par = (Expression) imputRawParenthesis.variables[i];
|
||||
if (par.variables.length == 1) {
|
||||
Function subFunz = par.variables[0];
|
||||
if (subFunz instanceof Expression || subFunz instanceof Number) {
|
||||
imputRawParenthesis.variables[i] = subFunz;
|
||||
for (int i = 0; i < imputRawParenthesis.functions.length; i++) {
|
||||
if (imputRawParenthesis.functions[i] instanceof Expression) {
|
||||
Expression par = (Expression) imputRawParenthesis.functions[i];
|
||||
if (par.functions.length == 1) {
|
||||
Function subFunz = par.functions[0];
|
||||
if (subFunz instanceof Expression || subFunz instanceof Number || subFunz instanceof Variable) {
|
||||
imputRawParenthesis.functions[i] = subFunz;
|
||||
Utils.debug.println(debugSpaces + " •Useless parentheses removed");
|
||||
}
|
||||
}
|
||||
@ -401,7 +390,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (funzione != null) {
|
||||
//Affinazione
|
||||
if (funzione instanceof Root) {
|
||||
if ((i - 1) >= 0 && oldFunctionsArray[i-1] instanceof Number && ((Number)oldFunctionsArray[i-1]).getTerm().isBigInteger(false) && ((Number)oldFunctionsArray[i-1]).getTerm().toBigInteger(false).compareTo(new BigInteger("2")) == 0) {
|
||||
if ((i - 1) >= 0 && oldFunctionsArray[i-1] instanceof Number && ((Number)oldFunctionsArray[i-1]).getTerm().compareTo(new BigInteger("2")) == 0) {
|
||||
oldFunctionsArray[i] = null;
|
||||
oldFunctionsArray[i-1] = null;
|
||||
oldFunctionsList.remove(oldFunctionsList.size()-1);
|
||||
@ -424,9 +413,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
before = oldFunctionsList.size();
|
||||
int i = 0;
|
||||
boolean change = false;
|
||||
if (Utils.areThereEmptyPrioritaryMultiplications(oldFunctionsList)) {
|
||||
step = "prioritary multiplications"; // PRIMA FASE
|
||||
} else if (Utils.areThereOnlyEmptySNFunctions(oldFunctionsList)) {
|
||||
if (Utils.areThereOnlyEmptySNFunctions(oldFunctionsList)) {
|
||||
step = "SN Functions"; // SECONDA FASE
|
||||
} else if (Utils.areThereOnlyEmptyNSNFunctions(oldFunctionsList)) {
|
||||
step = "NSN Functions"; // TERZA FASE
|
||||
@ -450,16 +437,6 @@ public class Expression extends FunctionMultipleValues {
|
||||
if (
|
||||
(step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction || funzioneTMP instanceof Subtraction) == true && ((funzioneTMP instanceof AnteriorFunction && ((AnteriorFunction) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValues && ((FunctionTwoValues) funzioneTMP).variable1 == null && ((FunctionTwoValues) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunction) && !(funzioneTMP instanceof FunctionTwoValues))))
|
||||
||
|
||||
(
|
||||
step.equals("prioritary multiplications")
|
||||
&&
|
||||
(funzioneTMP instanceof PrioritaryMultiplication)
|
||||
&&
|
||||
((FunctionTwoValues) funzioneTMP).variable1 == null
|
||||
&&
|
||||
((FunctionTwoValues) funzioneTMP).variable2 == null
|
||||
)
|
||||
||
|
||||
(
|
||||
step.equals("multiplications")
|
||||
&&
|
||||
@ -485,8 +462,6 @@ public class Expression extends FunctionMultipleValues {
|
||||
&&
|
||||
(funzioneTMP instanceof Multiplication) == false
|
||||
&&
|
||||
(funzioneTMP instanceof PrioritaryMultiplication) == false
|
||||
&&
|
||||
(funzioneTMP instanceof Division) == false
|
||||
&&
|
||||
(
|
||||
@ -537,7 +512,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
} catch (NullPointerException ex2) {}
|
||||
|
||||
} else {
|
||||
throw new java.lang.RuntimeException("Argomenti mancanti! Sistemare l'equazione!");
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -566,10 +541,10 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new java.lang.RuntimeException("Argomenti mancanti! Sistemare l'equazione!");
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
} else if (funzioneTMP instanceof Number || funzioneTMP instanceof Expression) {
|
||||
} else if (funzioneTMP instanceof Number || funzioneTMP instanceof Variable || funzioneTMP instanceof Expression) {
|
||||
if (n < 300) {
|
||||
// Utils.debug.println(debugSpaces+" •Set variable
|
||||
// to number:"+funzioneTMP.calcola());
|
||||
@ -603,8 +578,15 @@ public class Expression extends FunctionMultipleValues {
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variables.length >= 1) {
|
||||
if (functions.length > 1) {
|
||||
return true;
|
||||
} else if (functions.length == 1) {
|
||||
Function f = functions[0];
|
||||
if (f.isSolved() == false) {
|
||||
return true;
|
||||
} else {
|
||||
return !parenthesisNeeded();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -612,14 +594,14 @@ public class Expression extends FunctionMultipleValues {
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
List<Function> ret = new ArrayList<>();
|
||||
if (variables.length == 1) {
|
||||
if (variables[0].isSolved()) {
|
||||
ret.add(variables[0]);
|
||||
if (functions.length == 1) {
|
||||
if (functions[0].isSolved() || !parenthesisNeeded()) {
|
||||
ret.add(functions[0]);
|
||||
return ret;
|
||||
} else {
|
||||
List<Function> l = variables[0].solveOneStep();
|
||||
List<Function> l = functions[0].solveOneStep();
|
||||
for (Function f : l) {
|
||||
if (f instanceof Number) {
|
||||
if (f instanceof Number || f instanceof Variable) {
|
||||
ret.add(f);
|
||||
} else {
|
||||
ret.add(new Expression(this, new Function[]{(Function) f}));
|
||||
@ -628,7 +610,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
if (f.isSolved() == false) {
|
||||
List<Function> partial = f.solveOneStep();
|
||||
for (Function fnc : partial) {
|
||||
@ -642,7 +624,7 @@ public class Expression extends FunctionMultipleValues {
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
for (Function var : variables) {
|
||||
for (Function var : functions) {
|
||||
var.setSmall(small);
|
||||
var.generateGraphics();
|
||||
}
|
||||
@ -652,43 +634,44 @@ public class Expression extends FunctionMultipleValues {
|
||||
line = calcLine();
|
||||
}
|
||||
|
||||
public boolean parenthesesNeeded() {
|
||||
boolean parenthesesneeded = true;
|
||||
if (initialParenthesis | parent instanceof Division) {
|
||||
parenthesesneeded = false;
|
||||
public boolean parenthesisNeeded() {
|
||||
boolean parenthesisneeded = true;
|
||||
if (parent == null || initialParenthesis || parent instanceof Division) {
|
||||
parenthesisneeded = false;
|
||||
} else {
|
||||
if (variables.length == 1) {
|
||||
if (variables[0] instanceof Division) {
|
||||
parenthesesneeded = false;
|
||||
} else if (variables[0] instanceof Power) {
|
||||
if (((Power)variables[0]).getVariable1() instanceof Number && ((Number)((Power)variables[0]).getVariable1()).soloIncognitaSemplice()) {
|
||||
parenthesesneeded = false;
|
||||
} else {
|
||||
parenthesesneeded = true;
|
||||
if (functions.length == 1) {
|
||||
Function f = functions[0];
|
||||
if (f instanceof Number || f instanceof Variable || f instanceof Expression || f instanceof Division || f instanceof Joke || f instanceof Undefined || f instanceof Power) {
|
||||
parenthesisneeded = false;
|
||||
}
|
||||
if (f instanceof Multiplication) {
|
||||
if (((Multiplication)f).getVariable1() instanceof Number) {
|
||||
parenthesisneeded = !(((Multiplication)f).getVariable2() instanceof Variable);
|
||||
} else if (((Multiplication)f).getVariable2() instanceof Number) {
|
||||
parenthesisneeded = !(((Multiplication)f).getVariable1() instanceof Variable);
|
||||
} else if (((Multiplication) f).getVariable1() instanceof Variable || ((Multiplication)f).getVariable2() instanceof Variable) {
|
||||
parenthesisneeded = false;
|
||||
}
|
||||
} else {
|
||||
parenthesesneeded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return parenthesesneeded;
|
||||
return parenthesisneeded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
if (parenthesesNeeded() == false) {
|
||||
this.variables[0].draw(x, y);
|
||||
if (parenthesisNeeded() == false) {
|
||||
this.functions[0].draw(x, y);
|
||||
} else {
|
||||
float miny = y;
|
||||
float maxy = y + getHeight();
|
||||
int h = getHeight();
|
||||
x += 1;
|
||||
glColor3f(0, 0, 0);
|
||||
glDrawLine(x, y + 2, x + 2, y);
|
||||
glDrawLine(x, y + 2, x, y + h - 3);
|
||||
glDrawLine(x, y + h - 3, x + 2, y + h - 1);
|
||||
x += 4;
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
float fheight = f.getHeight();
|
||||
float y2 = miny + ((maxy - miny) / 2 - fheight / 2);
|
||||
f.draw(x, (int) y2);
|
||||
@ -708,11 +691,11 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
|
||||
private int calcWidth() {
|
||||
if (parenthesesNeeded() == false) {
|
||||
return this.variables[0].getWidth();
|
||||
if (parenthesisNeeded() == false) {
|
||||
return this.functions[0].getWidth();
|
||||
} else {
|
||||
int w = 0;
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
w += f.getWidth();
|
||||
}
|
||||
return 1 + 4 + w + 2 + 4;
|
||||
@ -725,12 +708,12 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
|
||||
private int calcHeight() {
|
||||
if (initialParenthesis || variables.length == 1) {
|
||||
return this.variables[0].getHeight();
|
||||
if (initialParenthesis || functions.length == 1) {
|
||||
return this.functions[0].getHeight();
|
||||
} else {
|
||||
Function tmin = null;
|
||||
Function tmax = null;
|
||||
for (Function t : variables) {
|
||||
for (Function t : functions) {
|
||||
if (tmin == null || t.getLine() >= tmin.getLine()) {
|
||||
tmin = t;
|
||||
}
|
||||
@ -750,11 +733,11 @@ public class Expression extends FunctionMultipleValues {
|
||||
}
|
||||
|
||||
private int calcLine() {
|
||||
if (initialParenthesis || variables.length == 1) {
|
||||
return this.variables[0].getLine();
|
||||
if (initialParenthesis || functions.length == 1) {
|
||||
return this.functions[0].getLine();
|
||||
} else {
|
||||
Function tl = null;
|
||||
for (Function t : variables) {
|
||||
for (Function t : functions) {
|
||||
if (tl == null || t.getLine() >= tl.getLine()) {
|
||||
tl = t;
|
||||
}
|
||||
@ -764,5 +747,48 @@ public class Expression extends FunctionMultipleValues {
|
||||
return tl.getLine();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String vars = "null";
|
||||
if (functions != null && functions.length > 0) {
|
||||
if (functions.length == 1) {
|
||||
if (functions[0] != null) {
|
||||
vars = functions[0].toString();
|
||||
}
|
||||
} else {
|
||||
for (Function variable : functions) {
|
||||
if (variable != null) {
|
||||
vars += ", " + variable.toString();
|
||||
}
|
||||
}
|
||||
vars = vars.substring(2);
|
||||
}
|
||||
}
|
||||
return "("+vars+")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Expression) {
|
||||
Expression f = (Expression) o;
|
||||
Function[] exprFuncs1 = functions;
|
||||
Function[] exprFuncs2 = f.functions;
|
||||
if (exprFuncs1.length == exprFuncs2.length) {
|
||||
for (int i = 0; i < exprFuncs1.length; i++) {
|
||||
if (exprFuncs1[i].equals(exprFuncs2[i]) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} else if (o != null & getVariablesLength() == 1) {
|
||||
Function f = (Function) o;
|
||||
return (functions[0].equals(f));
|
||||
} else if (o == null & getVariablesLength() == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ public interface Function {
|
||||
|
||||
public List<Function> solveOneStep() throws Error;
|
||||
|
||||
public boolean isSolved() throws Error;
|
||||
public boolean isSolved();
|
||||
|
||||
public void generateGraphics();
|
||||
public void generateGraphics() throws NullPointerException;
|
||||
|
||||
public void draw(int x, int y);
|
||||
|
||||
|
@ -19,21 +19,21 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
}
|
||||
|
||||
protected Function parent;
|
||||
protected Function[] variables;
|
||||
protected Function[] functions;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected boolean small;
|
||||
|
||||
public Function[] getVariables() {
|
||||
return variables;
|
||||
return functions;
|
||||
}
|
||||
|
||||
public void setVariables(Function[] value) {
|
||||
for (Function f : value) {
|
||||
f.setParent(this);
|
||||
}
|
||||
variables = value;
|
||||
functions = value;
|
||||
}
|
||||
|
||||
public void setVariables(final List<Function> value) {
|
||||
@ -43,39 +43,39 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
tmp[i] = value.get(i);
|
||||
tmp[i].setParent(this);
|
||||
}
|
||||
variables = tmp;
|
||||
functions = tmp;
|
||||
}
|
||||
|
||||
public Function getVariable(int index) {
|
||||
return variables[index];
|
||||
return functions[index];
|
||||
}
|
||||
|
||||
public void setVariable(int index, Function value) {
|
||||
value.setParent(this);
|
||||
variables[index] = value;
|
||||
functions[index] = value;
|
||||
}
|
||||
|
||||
public void addVariableToEnd(Function value) {
|
||||
public void addFunctionToEnd(Function value) {
|
||||
value.setParent(this);
|
||||
int index = variables.length;
|
||||
int index = functions.length;
|
||||
setVariablesLength(index + 1);
|
||||
variables[index] = value;
|
||||
functions[index] = value;
|
||||
}
|
||||
|
||||
public int getVariablesLength() {
|
||||
return variables.length;
|
||||
return functions.length;
|
||||
}
|
||||
|
||||
public void setVariablesLength(int length) {
|
||||
variables = Arrays.copyOf(variables, length);
|
||||
functions = Arrays.copyOf(functions, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String getSymbol();
|
||||
|
||||
@Override
|
||||
public boolean isSolved() throws Error {
|
||||
for (Function variable : variables) {
|
||||
public boolean isSolved() {
|
||||
for (Function variable : functions) {
|
||||
if (!variable.isSolved()) {
|
||||
return false;
|
||||
}
|
||||
@ -83,7 +83,7 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
return !isSolvable();
|
||||
}
|
||||
|
||||
protected abstract boolean isSolvable() throws Error;
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
|
||||
public Function setParent(Function value) {
|
||||
@ -121,11 +121,11 @@ public abstract class FunctionMultipleValues implements Function {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return variables.hashCode()+883*getSymbol().hashCode();
|
||||
return functions.hashCode()+883*getSymbol().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o != null && o.hashCode() == this.hashCode();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,13 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
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.List;
|
||||
|
||||
import org.nevec.rjm.Rational;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
@ -22,8 +21,8 @@ public abstract class FunctionTwoValues implements Function {
|
||||
|
||||
protected Function parent;
|
||||
|
||||
protected Function variable1 = (Function) new Number(null, Rational.ZERO);
|
||||
protected Function variable2 = (Function) new Number(null, Rational.ZERO);
|
||||
protected Function variable1 = null;
|
||||
protected Function variable2 = null;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
@ -60,11 +59,11 @@ public abstract class FunctionTwoValues implements Function {
|
||||
public abstract String getSymbol();
|
||||
|
||||
@Override
|
||||
public boolean isSolved() throws Error {
|
||||
public boolean isSolved() {
|
||||
return (variable1.isSolved() & variable2.isSolved()) ? !isSolvable() : false;
|
||||
}
|
||||
|
||||
protected abstract boolean isSolvable() throws Error;
|
||||
protected abstract boolean isSolvable();
|
||||
|
||||
@Override
|
||||
public abstract List<Function> solveOneStep() throws Error;
|
||||
@ -91,7 +90,7 @@ public abstract class FunctionTwoValues implements Function {
|
||||
if (drawSignum()) {
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
||||
dx += glGetStringWidth(getSymbol());
|
||||
dx += glGetStringWidth(Utils.getFont(small), getSymbol());
|
||||
}
|
||||
variable2.draw(dx + x, ln - variable2.getLine() + y);
|
||||
}
|
||||
@ -113,12 +112,15 @@ public abstract class FunctionTwoValues implements Function {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
// try {
|
||||
// return solve().toString();
|
||||
return "TODO: fare una nuova alternativa a solve().toString()";
|
||||
// } catch (Error e) {
|
||||
// return e.id.toString();
|
||||
// }
|
||||
String val1 = "null";
|
||||
String val2 = "null";
|
||||
if (variable1 != null) {
|
||||
val1 = variable1.toString();
|
||||
}
|
||||
if (variable2 != null) {
|
||||
val2 = variable2.toString();
|
||||
}
|
||||
return val1+getSymbol()+val2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -137,7 +139,7 @@ public abstract class FunctionTwoValues implements Function {
|
||||
}
|
||||
|
||||
protected int calcWidth() {
|
||||
return variable1.getWidth() + 1 + (drawSignum() ? glGetStringWidth(getSymbol()) : 0) + variable2.getWidth();
|
||||
return variable1.getWidth() + 1 + (drawSignum() ? glGetStringWidth(Utils.getFont(small), getSymbol()) : 0) + variable2.getWidth();
|
||||
}
|
||||
|
||||
protected int calcHeight() {
|
||||
@ -167,7 +169,5 @@ public abstract class FunctionTwoValues implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o != null && o.hashCode() == this.hashCode();
|
||||
}
|
||||
public abstract boolean equals(Object o);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class Joke implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolved() throws Error {
|
||||
public boolean isSolved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class Joke implements Function {
|
||||
if (jokesFont[joke] >= 0) {
|
||||
return Display.Render.glGetStringWidth(PIDisplay.fonts[jokesFont[joke]], jokes[joke]);
|
||||
} else {
|
||||
return Display.Render.glGetStringWidth(jokes[joke]);
|
||||
return Display.Render.glGetStringWidth(Utils.getFont(small), jokes[joke]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class Joke implements Function {
|
||||
if (jokesFont[joke] >= 0) {
|
||||
return PIDisplay.fonts[jokesFont[joke]].charH;
|
||||
} else {
|
||||
return Display.Render.glGetCurrentFontHeight();
|
||||
return Utils.getFont(small).charH;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,8 +86,11 @@ public class Joke implements Function {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean small = false;
|
||||
|
||||
@Override
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.Variable;
|
||||
import org.warp.picalculator.math.rules.ExponentRule15;
|
||||
import org.warp.picalculator.math.rules.NumberRule1;
|
||||
import org.warp.picalculator.math.rules.NumberRule2;
|
||||
import org.warp.picalculator.math.rules.NumberRule6;
|
||||
import org.warp.picalculator.math.rules.SyntaxRule1;
|
||||
|
||||
public class Multiplication extends FunctionTwoValues {
|
||||
|
||||
public Multiplication(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
if (value1 instanceof Variable && value2 instanceof Variable == false) {
|
||||
variable1 = value2;
|
||||
variable2 = value1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,22 +28,31 @@ public class Multiplication extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
if (SyntaxRule1.compare(this)) return true;
|
||||
if (NumberRule1.compare(this)) return true;
|
||||
if (NumberRule2.compare(this)) return true;
|
||||
if (NumberRule6.compare(this)) return true;
|
||||
if (ExponentRule15.compare(this)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
List<Function> result = new ArrayList<>();
|
||||
if (NumberRule1.compare(this)) {
|
||||
if (SyntaxRule1.compare(this)) {
|
||||
result = SyntaxRule1.execute(this);
|
||||
} else if (NumberRule1.compare(this)) {
|
||||
result = NumberRule1.execute(this);
|
||||
} else if (NumberRule2.compare(this)) {
|
||||
result = NumberRule2.execute(this);
|
||||
} else if (NumberRule6.compare(this)) {
|
||||
result = NumberRule6.execute(this);
|
||||
} else if (ExponentRule15.compare(this)) {
|
||||
result = ExponentRule15.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).multiply((Number)variable2));
|
||||
} else {
|
||||
@ -83,19 +96,7 @@ public class Multiplication extends FunctionTwoValues {
|
||||
if (!(tmpVar[0] instanceof Number)) {
|
||||
ok[val] = true;
|
||||
} else {
|
||||
if (((Number) tmpVar[val]).term.isBigInteger(false)) { // TODO: prima era tmpVar[0], ma crashava. RICONTROLLARE! La logica potrebbe essere sbagliata
|
||||
if (((Number) tmpVar[val]).term.toBigInteger(true).compareTo(new BigInteger("1")) == 0) {
|
||||
if (((Number) tmpVar[val]).term.toNumeroAvanzato().getVariableY().count() > 0) {
|
||||
ok[val] = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ok[val] = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (tmpVar[val] instanceof Power) {
|
||||
@ -114,6 +115,11 @@ public class Multiplication extends FunctionTwoValues {
|
||||
break;
|
||||
} else if (tmpVar[val] instanceof Joke) {
|
||||
break;
|
||||
} else if (tmpVar[val] instanceof Negative) {
|
||||
if (val == 1) {
|
||||
break;
|
||||
}
|
||||
ok[val] = true;
|
||||
} else if (tmpVar[val] instanceof Expression) {
|
||||
ok[0] = true;
|
||||
ok[1] = true;
|
||||
@ -125,6 +131,8 @@ public class Multiplication extends FunctionTwoValues {
|
||||
}
|
||||
} else if (tmpVar[val] instanceof AnteriorFunction) {
|
||||
tmpVar[val] = ((AnteriorFunction) tmpVar[val]).variable;
|
||||
} else {
|
||||
ok[val] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,4 +143,17 @@ public class Multiplication extends FunctionTwoValues {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Multiplication) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
if (variable1.equals(f.variable1) && variable2.equals(f.variable2)) {
|
||||
return true;
|
||||
} else if (variable1.equals(f.variable2) && variable2.equals(f.variable1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -3,14 +3,11 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.nevec.rjm.Rational;
|
||||
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.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.NumberRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
|
||||
@ -31,12 +28,12 @@ public class Negative extends AnteriorFunction {
|
||||
variable.generateGraphics();
|
||||
|
||||
height = getVariable().getHeight();
|
||||
width = Display.Render.glGetStringWidth("-") + getVariable().getWidth();
|
||||
width = Display.Render.glGetStringWidth(Utils.getFont(small), "-") + getVariable().getWidth();
|
||||
line = getVariable().getLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable instanceof Number) return true;
|
||||
if (ExpandRule1.compare(this)) return true;
|
||||
if (ExpandRule5.compare(this)) return true;
|
||||
@ -93,4 +90,12 @@ public class Negative extends AnteriorFunction {
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Negative) {
|
||||
return ((Negative)o).variable.equals(variable);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,72 +1,45 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3f;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glFillRect;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.MathContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.BigDecimalMath;
|
||||
import org.nevec.rjm.NumeroAvanzato;
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.nevec.rjm.Rational;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.Variables;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
|
||||
public class Number implements Function {
|
||||
|
||||
private Function parent;
|
||||
protected NumeroAvanzatoVec term = NumeroAvanzatoVec.ZERO;
|
||||
protected BigInteger term;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int line;
|
||||
protected boolean small;
|
||||
|
||||
public Number(Function parent, NumeroAvanzatoVec val) {
|
||||
|
||||
public Number(Function parent, BigInteger val) {
|
||||
this.parent = parent;
|
||||
term = val;
|
||||
}
|
||||
|
||||
public Number(Function parent, String s) throws Error {
|
||||
this.parent = parent;
|
||||
term = new NumeroAvanzatoVec(new NumeroAvanzato(Utils.getRational(s), Rational.ONE));
|
||||
this(parent, new BigInteger(s));
|
||||
}
|
||||
|
||||
public Number(Function parent, Rational r) {
|
||||
this.parent = parent;
|
||||
term = new NumeroAvanzatoVec(new NumeroAvanzato(r, Rational.ONE));
|
||||
public Number(Function parent, int s) {
|
||||
this(parent, BigInteger.valueOf(s));
|
||||
}
|
||||
|
||||
public Number(Function parent, BigInteger r) {
|
||||
this.parent = parent;
|
||||
term = new NumeroAvanzatoVec(new NumeroAvanzato(new Rational(r, BigInteger.ONE), Rational.ONE));
|
||||
}
|
||||
|
||||
public Number(Function parent, BigDecimal r) {
|
||||
this.parent = parent;
|
||||
term = new NumeroAvanzatoVec(new NumeroAvanzato(Utils.getRational(r), Rational.ONE));
|
||||
}
|
||||
|
||||
public Number(Function parent, NumeroAvanzato numeroAvanzato) {
|
||||
this.parent = parent;
|
||||
term = new NumeroAvanzatoVec(numeroAvanzato);
|
||||
}
|
||||
|
||||
public NumeroAvanzatoVec getTerm() {
|
||||
public BigInteger getTerm() {
|
||||
return term;
|
||||
}
|
||||
|
||||
public void setTerm(NumeroAvanzatoVec val) {
|
||||
public void setTerm(BigInteger val) {
|
||||
term = val;
|
||||
}
|
||||
|
||||
@ -82,12 +55,12 @@ public class Number implements Function {
|
||||
return toString();
|
||||
}
|
||||
|
||||
public Number add(Number f) throws Error {
|
||||
public Number add(Number f) {
|
||||
Number ret = new Number(this.parent, getTerm().add(f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Number multiply(Number f) throws Error {
|
||||
public Number multiply(Number f) {
|
||||
Number ret = new Number(this.parent, getTerm().multiply(f.getTerm()));
|
||||
return ret;
|
||||
}
|
||||
@ -98,30 +71,16 @@ public class Number implements Function {
|
||||
}
|
||||
|
||||
public Number pow(Number f) throws Error {
|
||||
Number ret = new Number(this.parent, NumeroAvanzatoVec.ONE);
|
||||
if (f.getTerm().isBigInteger(true)) {
|
||||
for (BigInteger i = BigInteger.ZERO; i.compareTo(f.getTerm().toBigInteger(true)) < 0; i = i.add(BigInteger.ONE)) {
|
||||
ret = ret.multiply(new Number(this.parent, getTerm()));
|
||||
}
|
||||
} else if (getTerm().isRational(true) && f.getTerm().isRational(false) && f.getTerm().toRational(false).compareTo(Rational.HALF) == 0) {
|
||||
// Rational originalExponent = f.getTerm().toRational();
|
||||
// Rational rootExponent = new Rational(originalExponent.denom(),
|
||||
// originalExponent.numer());
|
||||
Rational numberToRoot = getTerm().toRational(true);
|
||||
NumeroAvanzato na = new NumeroAvanzato(Rational.ONE, numberToRoot);
|
||||
na = na.setVariableX(getTerm().toNumeroAvanzato().getVariableY().multiply(getTerm().toNumeroAvanzato().getVariableZ()));
|
||||
na = na.setVariableY(new Variables());
|
||||
na = na.setVariableZ(getTerm().toNumeroAvanzato().getVariableZ());
|
||||
ret = new Number(this.parent, na);
|
||||
} else {
|
||||
ret = new Number(this.parent, BigDecimalMath.pow(getTerm().BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2)), f.getTerm().BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2))));
|
||||
Number ret = new Number(this.parent, BigInteger.ONE);
|
||||
for (BigInteger i = BigInteger.ZERO; i.compareTo(f.getTerm()) < 0; i = i.add(BigInteger.ONE)) {
|
||||
ret = ret.multiply(new Number(this.parent, getTerm()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getTerm().toFancyString();
|
||||
return getTerm().toString();
|
||||
}
|
||||
|
||||
// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) {
|
||||
@ -135,103 +94,17 @@ public class Number implements Function {
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
|
||||
if (getTerm().isBigInteger(false)) {
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
String t = toString();
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
String t = toString();
|
||||
|
||||
if (t.startsWith("-")) {
|
||||
if (drawMinus) {
|
||||
if (t.startsWith("-")) {
|
||||
if (drawMinus) {
|
||||
|
||||
} else {
|
||||
t = t.substring(1);
|
||||
}
|
||||
}
|
||||
glDrawStringLeft(x+1, y, t);
|
||||
} else if (getTerm().isRational(false)) {
|
||||
small = true;
|
||||
Display.Render.glSetFont(Utils.getFont(true));
|
||||
Rational r = getTerm().toRational(false);
|
||||
boolean minus = false;
|
||||
int minusw = 0;
|
||||
int minush = 0;
|
||||
String numerator = r.numer().toString();
|
||||
if (numerator.startsWith("-")) {
|
||||
minus = true;
|
||||
numerator = numerator.substring(1);
|
||||
}
|
||||
int w1 = glGetStringWidth(numerator);
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
int w2 = glGetStringWidth(r.denom().toString());
|
||||
int maxw;
|
||||
if (w1 > w2) {
|
||||
maxw = 1 + w1 + 1;
|
||||
} else {
|
||||
maxw = 1 + w2 + 1;
|
||||
t = t.substring(1);
|
||||
}
|
||||
if (minus) {
|
||||
if (drawMinus) {
|
||||
minusw = glGetStringWidth("-");
|
||||
minush = Utils.getFontHeight(small);
|
||||
maxw += minusw;
|
||||
glDrawStringLeft(x, y + h1 + 1 + 1 - (minush / 2), "-");
|
||||
}
|
||||
}
|
||||
glDrawStringLeft((int) (x + minusw + 1 + (maxw - w1) / 2d), y, numerator);
|
||||
glDrawStringLeft((int) (x + minusw + 1 + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1, r.denom().toString());
|
||||
glColor3f(0, 0, 0);
|
||||
glFillRect(x + minusw + 1, y + h1 + 1, maxw, 1);
|
||||
} else if (getTerm().toFancyString().contains("/")) {
|
||||
small = true;
|
||||
Display.Render.glSetFont(Utils.getFont(true));
|
||||
String r = getTerm().toFancyString();
|
||||
String numer = r.substring(0, r.lastIndexOf("/"));
|
||||
String denom = r.substring(numer.length() + 1, r.length());
|
||||
if (numer.startsWith("(") && numer.endsWith(")")) {
|
||||
numer = numer.substring(1, numer.length() - 1);
|
||||
}
|
||||
boolean minus = false;
|
||||
if (numer.startsWith("-")) {
|
||||
minus = true;
|
||||
numer = numer.substring(1);
|
||||
}
|
||||
int w1 = glGetStringWidth(numer.toString());
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
int w2 = glGetStringWidth(denom.toString());
|
||||
int maxw;
|
||||
if (w1 > w2) {
|
||||
maxw = w1 + 2;
|
||||
} else {
|
||||
maxw = w2 + 2;
|
||||
}
|
||||
int minusw = 0;
|
||||
int minush = 0;
|
||||
if (minus) {
|
||||
if (drawMinus) {
|
||||
minusw = glGetStringWidth("-") + 1;
|
||||
minush = Utils.getFontHeight(small);
|
||||
maxw += minusw;
|
||||
glDrawStringLeft(x, y + h1 + 1 + 1 - (minush / 2), "-");
|
||||
}
|
||||
}
|
||||
glDrawStringLeft((int) (x + minusw + 1 + (maxw - w1) / 2d), y, numer);
|
||||
glDrawStringLeft((int) (x + minusw + 1 + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1, denom);
|
||||
glColor3f(0, 0, 0);
|
||||
glFillRect(x + minusw + 1, y + h1 + 1, maxw, 1);
|
||||
} else {
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
String r = getTerm().toFancyString();
|
||||
|
||||
if (r.startsWith("-")) {
|
||||
if (drawMinus) {
|
||||
|
||||
} else {
|
||||
r = r.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
glDrawStringLeft(x+1, y, r.toString());
|
||||
}
|
||||
glDrawStringLeft(x+1, y, t);
|
||||
}
|
||||
|
||||
public int getHeight(boolean drawMinus) {
|
||||
@ -248,23 +121,8 @@ public class Number implements Function {
|
||||
}
|
||||
|
||||
private int calcHeight() {
|
||||
if (getTerm().isBigInteger(false)) {
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1;
|
||||
} else if (getTerm().isRational(false)) {
|
||||
small = true;
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
int h2 = Utils.getFontHeight(small);
|
||||
return h1 + 3 + h2;
|
||||
} else if (getTerm().toFancyString().contains("/")) {
|
||||
small = true;
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
int h2 = Utils.getFontHeight(small);
|
||||
return h1 + 3 + h2;
|
||||
} else {
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1;
|
||||
}
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1;
|
||||
}
|
||||
@Override
|
||||
public int getWidth() {
|
||||
@ -272,84 +130,15 @@ public class Number implements Function {
|
||||
}
|
||||
|
||||
public int calcWidth() {
|
||||
if (getTerm().isBigInteger(false)) {
|
||||
String t = toString();
|
||||
if (t.startsWith("-")) {
|
||||
if (drawMinus) {
|
||||
String t = toString();
|
||||
if (t.startsWith("-")) {
|
||||
if (drawMinus) {
|
||||
|
||||
} else {
|
||||
t = t.substring(1);
|
||||
}
|
||||
}
|
||||
return glGetStringWidth(t)+1;
|
||||
} else if (getTerm().isRational(false)) {
|
||||
Rational r = getTerm().toRational(false);
|
||||
boolean minus = false;
|
||||
String numerator = r.numer().toString();
|
||||
if (numerator.startsWith("-")) {
|
||||
minus = true;
|
||||
numerator = numerator.substring(1);
|
||||
}
|
||||
int w1 = glGetStringWidth(numerator);
|
||||
int w2 = glGetStringWidth(r.denom().toString());
|
||||
int maxw;
|
||||
if (w1 > w2) {
|
||||
maxw = 1 + w1 + 1;
|
||||
} else {
|
||||
maxw = 1 + w2 + 1;
|
||||
}
|
||||
if (minus) {
|
||||
if (drawMinus) {
|
||||
maxw += glGetStringWidth("-");
|
||||
}
|
||||
}
|
||||
return maxw + 1;
|
||||
} else if (getTerm().toFancyString().contains("/")) {
|
||||
String r = getTerm().toFancyString();
|
||||
String numer = r.substring(0, r.lastIndexOf("/"));
|
||||
String denom = r.substring(numer.length() + 1, r.length());
|
||||
if (numer.startsWith("(") && numer.endsWith(")")) {
|
||||
numer = numer.substring(1, numer.length() - 1);
|
||||
}
|
||||
boolean minus = false;
|
||||
if (numer.startsWith("-")) {
|
||||
minus = true;
|
||||
numer = numer.substring(1);
|
||||
}
|
||||
int w1 = glGetStringWidth(numer.toString());
|
||||
int w2 = glGetStringWidth(denom.toString());
|
||||
int maxw;
|
||||
if (w1 > w2) {
|
||||
maxw = w1 + 1;
|
||||
} else {
|
||||
maxw = w2 + 1;
|
||||
}
|
||||
if (minus) {
|
||||
if (drawMinus) {
|
||||
maxw += glGetStringWidth("-");
|
||||
}
|
||||
}
|
||||
return maxw + 2;
|
||||
} else {
|
||||
String r = getTerm().toFancyString();
|
||||
if (r.startsWith("-")) {
|
||||
if (drawMinus) {
|
||||
|
||||
} else {
|
||||
r = r.substring(1);
|
||||
}
|
||||
}
|
||||
return glGetStringWidth(r.toString())+1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean soloIncognitaSemplice() {
|
||||
if (this.getTerm().isBigInteger(true)) {
|
||||
if (this.getTerm().toBigInteger(true).compareTo(BigInteger.ONE) == 0 && this.getTerm().toNumeroAvanzato().getVariableY().count() > 0) {
|
||||
return true;
|
||||
t = t.substring(1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return glGetStringWidth(Utils.getFont(small), t)+1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -358,20 +147,7 @@ public class Number implements Function {
|
||||
}
|
||||
|
||||
private int calcLine() {
|
||||
if (getTerm().isBigInteger(false)) {
|
||||
return Utils.getFontHeight(small) / 2;
|
||||
} else if (getTerm().isRational(false)) {
|
||||
small = true;
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1 + 1;
|
||||
} else if (getTerm().toFancyString().contains("/")) {
|
||||
small = true;
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1 + 1;
|
||||
} else {
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1 / 2;
|
||||
}
|
||||
return Utils.getFontHeight(small) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -406,17 +182,15 @@ public class Number implements Function {
|
||||
public boolean equals(Object o) {
|
||||
if (o != null & term != null) {
|
||||
if (o instanceof Number) {
|
||||
NumeroAvanzatoVec nav = ((Number) o).getTerm();
|
||||
if (term.isBigInteger(true) & nav.isBigInteger(true)) {
|
||||
boolean na1 = term.toBigInteger(true).compareTo(BigInteger.ZERO) == 0;
|
||||
boolean na2 = nav.toBigInteger(true).compareTo(BigInteger.ZERO) == 0;
|
||||
if (na1 == na2) {
|
||||
if (na1 == true) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
BigInteger nav = ((Number) o).getTerm();
|
||||
boolean na1 = term.compareTo(BigInteger.ZERO) == 0;
|
||||
boolean na2 = nav.compareTo(BigInteger.ZERO) == 0;
|
||||
if (na1 == na2) {
|
||||
if (na1 == true) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return nav.compareTo(term) == 0;
|
||||
}
|
||||
|
@ -4,11 +4,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExponentRule1;
|
||||
import org.warp.picalculator.math.rules.ExponentRule2;
|
||||
import org.warp.picalculator.math.rules.ExponentRule3;
|
||||
import org.warp.picalculator.math.rules.ExponentRule4;
|
||||
import org.warp.picalculator.math.rules.FractionsRule4;
|
||||
import org.warp.picalculator.math.rules.FractionsRule5;
|
||||
import org.warp.picalculator.math.rules.UndefinedRule1;
|
||||
|
||||
public class Power extends FunctionTwoValues {
|
||||
|
||||
@ -22,13 +26,15 @@ public class Power extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
if (((Number)variable2).getTerm().hasVariables()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (UndefinedRule1.compare(this)) return true;
|
||||
if (ExponentRule1.compare(this)) return true;
|
||||
if (ExponentRule2.compare(this)) return true;
|
||||
if (ExponentRule3.compare(this)) return true;
|
||||
if (ExponentRule4.compare(this)) return true;
|
||||
if (FractionsRule4.compare(this)) return true;
|
||||
if (FractionsRule5.compare(this)) return true;
|
||||
return false;
|
||||
@ -50,12 +56,22 @@ public class Power extends FunctionTwoValues {
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
result.add((Function) ((Number)variable1).pow((Number)variable2));
|
||||
if (UndefinedRule1.compare(this)) {
|
||||
result.addAll(UndefinedRule1.execute(this));
|
||||
} else if (ExponentRule1.compare(this)) {
|
||||
result.addAll(ExponentRule1.execute(this));
|
||||
} else if (ExponentRule2.compare(this)) {
|
||||
result.addAll(ExponentRule2.execute(this));
|
||||
} else if (ExponentRule3.compare(this)) {
|
||||
result.addAll(ExponentRule3.execute(this));
|
||||
} else if (ExponentRule4.compare(this)) {
|
||||
result.addAll(ExponentRule4.execute(this));
|
||||
} else if (FractionsRule4.compare(this)) {
|
||||
result.addAll(FractionsRule4.execute(this));
|
||||
} else if (FractionsRule5.compare(this)) {
|
||||
result.addAll(FractionsRule5.execute(this));
|
||||
} else if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
result.add((Function) ((Number)variable1).pow((Number)variable2));
|
||||
} else {
|
||||
List<Function> l1 = new ArrayList<Function>();
|
||||
List<Function> l2 = new ArrayList<Function>();
|
||||
@ -105,4 +121,13 @@ public class Power extends FunctionTwoValues {
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Power) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class PrioritaryMultiplication extends FunctionTwoValues {
|
||||
|
||||
public PrioritaryMultiplication(Function parent, Function value1, Function value2) {
|
||||
super(parent, value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return MathematicalSymbols.PRIORITARY_MULTIPLICATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
if (variable1 == null || variable2 == null) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).multiply((Number)variable2));
|
||||
} else {
|
||||
List<Function> l1 = new ArrayList<Function>();
|
||||
List<Function> l2 = new ArrayList<Function>();
|
||||
if (variable1.isSolved()) {
|
||||
l1.add(variable1);
|
||||
} else {
|
||||
l1.addAll(variable1.solveOneStep());
|
||||
}
|
||||
if (variable2.isSolved()) {
|
||||
l2.add(variable2);
|
||||
} else {
|
||||
l2.addAll(variable2.solveOneStep());
|
||||
}
|
||||
|
||||
Function[][] results = Utils.joinFunctionsResults(l1, l2);
|
||||
|
||||
for (Function[] f : results) {
|
||||
result.add(new PrioritaryMultiplication(this.parent, (Function)f[0], (Function)f[1]));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean drawSignum() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -2,12 +2,11 @@ package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
@ -36,11 +35,9 @@ public class Root extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
if ((((Number)variable2).pow(new Number(this.parent, NumeroAvanzatoVec.ONE).divide((Number) variable1)).getTerm().isBigInteger(true))) {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -49,7 +46,7 @@ public class Root extends FunctionTwoValues {
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1.isSolved() & variable2.isSolved()) {
|
||||
Number exponent = new Number(this.parent, NumeroAvanzatoVec.ONE);
|
||||
Number exponent = new Number(this.parent, BigInteger.ONE);
|
||||
exponent = exponent.divide((Number) variable1);
|
||||
result.add(((Number)variable2).pow(exponent));
|
||||
} else {
|
||||
@ -115,4 +112,13 @@ public class Root extends FunctionTwoValues {
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Root) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ package org.warp.picalculator.math.functions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.nevec.rjm.Rational;
|
||||
import org.nevec.rjm.BigIntegerMath;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
@ -32,9 +31,9 @@ public class RootSquare extends AnteriorFunction {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable instanceof Number) {
|
||||
if ((((Number)variable).pow(new Number(this.parent, new Rational(1, 2))).getTerm().isBigInteger(true))) {
|
||||
if (BigIntegerMath.isqrt(((Number) variable).term).pow(2).compareTo(((Number) variable).term) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -50,7 +49,7 @@ public class RootSquare extends AnteriorFunction {
|
||||
if (variable.isSolved()) {
|
||||
try {
|
||||
Number var = (Number) getVariable();
|
||||
result.add(var.pow(new Number(this.parent, new Rational(1, 2))));
|
||||
result.add(new Number(this.getParent(), BigIntegerMath.isqrt(var.term)));
|
||||
} catch(NullPointerException ex) {
|
||||
throw new Error(Errors.ERROR);
|
||||
} catch(NumberFormatException ex) {
|
||||
@ -96,4 +95,12 @@ public class RootSquare extends AnteriorFunction {
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof RootSquare) {
|
||||
return ((RootSquare) o).variable.equals(variable);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzato;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.Variable;
|
||||
import org.warp.picalculator.math.Variables;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.ExpandRule5;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule5;
|
||||
import org.warp.picalculator.math.rules.VariableRule1;
|
||||
import org.warp.picalculator.math.rules.VariableRule2;
|
||||
import org.warp.picalculator.math.rules.VariableRule3;
|
||||
|
||||
public class Subtraction extends FunctionTwoValues {
|
||||
|
||||
@ -24,10 +27,17 @@ public class Subtraction extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
if (VariableRule1.compare(this)) return true;
|
||||
if (VariableRule2.compare(this)) return true;
|
||||
if (VariableRule3.compare(this)) return true;
|
||||
if (NumberRule3.compare(this)) return true;
|
||||
if (ExpandRule1.compare(this)) return true;
|
||||
if (ExpandRule5.compare(this)) return true;
|
||||
if (NumberRule5.compare(this)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -37,7 +47,21 @@ public class Subtraction extends FunctionTwoValues {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if (VariableRule1.compare(this)) {
|
||||
result = VariableRule1.execute(this);
|
||||
} else if (VariableRule2.compare(this)) {
|
||||
result = VariableRule2.execute(this);
|
||||
} else if (VariableRule3.compare(this)) {
|
||||
result = VariableRule3.execute(this);
|
||||
} else if (NumberRule3.compare(this)) {
|
||||
result = NumberRule3.execute(this);
|
||||
} else if (ExpandRule1.compare(this)) {
|
||||
result = ExpandRule1.execute(this);
|
||||
} else if (ExpandRule5.compare(this)) {
|
||||
result = ExpandRule5.execute(this);
|
||||
} else if (NumberRule5.compare(this)) {
|
||||
result = NumberRule5.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(this.parent, "-1"))));
|
||||
} else {
|
||||
List<Function> l1 = new ArrayList<Function>();
|
||||
@ -61,5 +85,13 @@ public class Subtraction extends FunctionTwoValues {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Subtraction) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,21 +1,24 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzato;
|
||||
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.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.Variable;
|
||||
import org.warp.picalculator.math.Variables;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule5;
|
||||
import org.warp.picalculator.math.rules.NumberRule7;
|
||||
import org.warp.picalculator.math.rules.SyntaxRule1;
|
||||
import org.warp.picalculator.math.rules.SyntaxRule2;
|
||||
import org.warp.picalculator.math.rules.VariableRule1;
|
||||
import org.warp.picalculator.math.rules.VariableRule2;
|
||||
import org.warp.picalculator.math.rules.VariableRule3;
|
||||
import org.warp.picalculator.math.rules.methods.SumMethod1;
|
||||
|
||||
public class Sum extends FunctionTwoValues {
|
||||
|
||||
@ -29,10 +32,18 @@ public class Sum extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
if (SyntaxRule2.compare(this)) return true;
|
||||
if (VariableRule1.compare(this)) return true;
|
||||
if (VariableRule2.compare(this)) return true;
|
||||
if (VariableRule3.compare(this)) return true;
|
||||
if (NumberRule3.compare(this)) return true;
|
||||
if (NumberRule5.compare(this)) return true;
|
||||
if (NumberRule7.compare(this)) return true;
|
||||
if (SumMethod1.compare(this)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -42,15 +53,31 @@ public class Sum extends FunctionTwoValues {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if ((parent == null || parent.getParent() == null) && ((Number)variable1).term.isBigInteger(false) & ((Number)variable2).term.isBigInteger(false)) {
|
||||
if (((Number)variable1).term.toBigInteger(false).compareTo(new BigInteger("2")) == 0 && ((Number)variable2).term.toBigInteger(false).compareTo(new BigInteger("2")) == 0) {
|
||||
if (SyntaxRule2.compare(this)) {
|
||||
result = SyntaxRule2.execute(this);
|
||||
} else if (VariableRule1.compare(this)) {
|
||||
result = VariableRule1.execute(this);
|
||||
} else if (VariableRule2.compare(this)) {
|
||||
result = VariableRule2.execute(this);
|
||||
} else if (VariableRule3.compare(this)) {
|
||||
result = VariableRule3.execute(this);
|
||||
} else if (NumberRule3.compare(this)) {
|
||||
result = NumberRule3.execute(this);
|
||||
} else if (NumberRule5.compare(this)) {
|
||||
result = NumberRule5.execute(this);
|
||||
} else if (NumberRule7.compare(this)) {
|
||||
result = NumberRule7.execute(this);
|
||||
} else if (SumMethod1.compare(this)) {
|
||||
result = SumMethod1.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if ((parent == null || parent.getParent() == null)) {
|
||||
if (((Number)variable1).term.compareTo(new BigInteger("2")) == 0 && ((Number)variable2).term.compareTo(new BigInteger("2")) == 0) {
|
||||
result.add(new Joke(Joke.FISH));
|
||||
return result;
|
||||
} else if (((Number)variable1).term.toBigInteger(false).compareTo(new BigInteger("20")) == 0 && ((Number)variable2).term.toBigInteger(false).compareTo(new BigInteger("20")) == 0) {
|
||||
} else if (((Number)variable1).term.compareTo(new BigInteger("20")) == 0 && ((Number)variable2).term.compareTo(new BigInteger("20")) == 0) {
|
||||
result.add(new Joke(Joke.TORNADO));
|
||||
return result;
|
||||
} else if (((Number)variable1).term.toBigInteger(false).compareTo(new BigInteger("29")) == 0 && ((Number)variable2).term.toBigInteger(false).compareTo(new BigInteger("29")) == 0) {
|
||||
} else if (((Number)variable1).term.compareTo(new BigInteger("29")) == 0 && ((Number)variable2).term.compareTo(new BigInteger("29")) == 0) {
|
||||
result.add(new Joke(Joke.SHARKNADO));
|
||||
return result;
|
||||
}
|
||||
@ -91,23 +118,6 @@ public class Sum extends FunctionTwoValues {
|
||||
height = calcHeight();
|
||||
line = calcLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
// glColor3f(127, 127-50+new Random().nextInt(50), 255);
|
||||
// glFillRect(x,y,width,height);
|
||||
// glColor3f(0, 0, 0);
|
||||
|
||||
int ln = getLine();
|
||||
int dx = 0;
|
||||
variable1.draw(dx + x, ln - variable1.getLine() + y);
|
||||
dx += variable1.getWidth();
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
dx += 1;
|
||||
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
||||
dx += glGetStringWidth(getSymbol());
|
||||
variable2.draw(dx + x, ln - variable2.getLine() + y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
@ -119,7 +129,20 @@ public class Sum extends FunctionTwoValues {
|
||||
int dx = 0;
|
||||
dx += variable1.getWidth();
|
||||
dx += 1;
|
||||
dx += glGetStringWidth(getSymbol());
|
||||
dx += glGetStringWidth(Utils.getFont(small), getSymbol());
|
||||
return dx += variable2.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Sum) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
if (variable1.equals(f.variable1) && variable2.equals(f.variable2)) {
|
||||
return true;
|
||||
} else if (variable1.equals(f.variable2) && variable2.equals(f.variable1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glGetStringWidth;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -9,9 +9,12 @@ import java.util.List;
|
||||
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.device.graphicengine.Display;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.ExpandRule1;
|
||||
import org.warp.picalculator.math.rules.NumberRule3;
|
||||
import org.warp.picalculator.math.rules.NumberRule4;
|
||||
import org.warp.picalculator.math.rules.NumberRule5;
|
||||
|
||||
public class SumSubtraction extends FunctionTwoValues {
|
||||
|
||||
@ -25,10 +28,14 @@ public class SumSubtraction extends FunctionTwoValues {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() throws Error {
|
||||
protected boolean isSolvable() {
|
||||
if (variable1 instanceof Number & variable2 instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
if (NumberRule3.compare(this)) return true;
|
||||
if (ExpandRule1.compare(this)) return true;
|
||||
if (NumberRule4.compare(this)) return true;
|
||||
if (NumberRule5.compare(this)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -38,7 +45,15 @@ public class SumSubtraction extends FunctionTwoValues {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if (NumberRule3.compare(this)) {
|
||||
result = NumberRule3.execute(this);
|
||||
} else if (ExpandRule1.compare(this)) {
|
||||
result = ExpandRule1.execute(this);
|
||||
} else if (NumberRule4.compare(this)) {
|
||||
result = NumberRule4.execute(this);
|
||||
} else if (NumberRule5.compare(this)) {
|
||||
result = NumberRule5.execute(this);
|
||||
} else if (variable1.isSolved() & variable2.isSolved()) {
|
||||
result.add(((Number)variable1).add((Number)variable2));
|
||||
result.add(((Number)variable1).add(((Number)variable2).multiply(new Number(this.parent, "-1"))));
|
||||
} else {
|
||||
@ -90,7 +105,7 @@ public class SumSubtraction extends FunctionTwoValues {
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
dx += 1;
|
||||
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
|
||||
dx += glGetStringWidth(getSymbol());
|
||||
dx += glGetStringWidth(Utils.getFont(small), getSymbol());
|
||||
variable2.draw(dx + x, ln - variable2.getLine() + y);
|
||||
}
|
||||
|
||||
@ -104,7 +119,16 @@ public class SumSubtraction extends FunctionTwoValues {
|
||||
int dx = 0;
|
||||
dx += variable1.getWidth();
|
||||
dx += 1;
|
||||
dx += glGetStringWidth(getSymbol());
|
||||
dx += glGetStringWidth(Utils.getFont(small), getSymbol());
|
||||
return dx += variable2.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof SumSubtraction) {
|
||||
FunctionTwoValues f = (FunctionTwoValues) o;
|
||||
return variable1.equals(f.variable1) && variable2.equals(f.variable2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class Undefined implements Function {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolved() throws Error {
|
||||
public boolean isSolved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ public class Undefined implements Function {
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
width = Display.Render.glGetStringWidth("UNDEFINED");
|
||||
width = Display.Render.glGetStringWidth(Utils.getFont(small), "UNDEFINED");
|
||||
height = Utils.getFontHeight(small);
|
||||
line = height/2;
|
||||
}
|
||||
@ -74,5 +74,13 @@ public class Undefined implements Function {
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Undefined) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
144
src/org/warp/picalculator/math/functions/Variable.java
Normal file
144
src/org/warp/picalculator/math/functions/Variable.java
Normal file
@ -0,0 +1,144 @@
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
|
||||
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;
|
||||
|
||||
public Variable(Function parent, char val) {
|
||||
this.parent = parent;
|
||||
var = val;
|
||||
}
|
||||
|
||||
public Variable(Function parent, String s) throws Error {
|
||||
this(parent, s.charAt(0));
|
||||
}
|
||||
|
||||
public char getChar() {
|
||||
return var;
|
||||
}
|
||||
|
||||
public void setChar(char val) {
|
||||
var = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
line = calcLine();
|
||||
height = calcHeight();
|
||||
width = calcWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSymbol() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ""+getChar();
|
||||
}
|
||||
|
||||
// public void draw(int x, int y, PIDisplay g, boolean small, boolean drawMinus) {
|
||||
// boolean beforedrawminus = this.drawMinus;
|
||||
// this.drawMinus = drawMinus;
|
||||
// draw(x, y, small);
|
||||
// this.drawMinus = beforedrawminus;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
Display.Render.glSetFont(Utils.getFont(small));
|
||||
glDrawStringLeft(x+1, y, toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
private int calcHeight() {
|
||||
int h1 = Utils.getFontHeight(small);
|
||||
return h1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int calcWidth() {
|
||||
return glGetStringWidth(Utils.getFont(small), toString())+1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLine() {
|
||||
return line;
|
||||
}
|
||||
|
||||
private int calcLine() {
|
||||
return Utils.getFontHeight(small) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Variable clone() {
|
||||
Cloner cloner = new Cloner();
|
||||
return cloner.deepClone(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSmall(boolean small) {
|
||||
this.small = small;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
List<Function> result = new ArrayList<>();
|
||||
result.add(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Variable) {
|
||||
return ((Variable) o).getChar() == var;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Function setParent(Function value) {
|
||||
parent = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function getParent() {
|
||||
return parent;
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ public class Equation extends FunctionTwoValues {
|
||||
}
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (variable1.isSolved() & variable2.isSolved()) {
|
||||
if (((Number)variable2).getTerm().isBigInteger(false) && ((Number)variable2).getTerm().toBigInteger(false).compareTo(new BigInteger("0")) == 0) {
|
||||
if (((Number)variable2).getTerm().compareTo(new BigInteger("0")) == 0) {
|
||||
result.add(this);
|
||||
} else {
|
||||
Equation e = new Equation(this.parent, null, null);
|
||||
|
@ -33,7 +33,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
|
||||
@Override
|
||||
protected boolean isSolvable() {
|
||||
if (variables.length >= 1) {
|
||||
if (functions.length >= 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -42,12 +42,12 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
@Override
|
||||
public List<Function> solveOneStep() throws Error {
|
||||
List<Function> ret = new ArrayList<>();
|
||||
if (variables.length == 1) {
|
||||
if (variables[0].isSolved()) {
|
||||
ret.add(variables[0]);
|
||||
if (functions.length == 1) {
|
||||
if (functions[0].isSolved()) {
|
||||
ret.add(functions[0]);
|
||||
return ret;
|
||||
} else {
|
||||
List<Function> l = variables[0].solveOneStep();
|
||||
List<Function> l = functions[0].solveOneStep();
|
||||
for (Function f : l) {
|
||||
if (f instanceof Number) {
|
||||
ret.add(f);
|
||||
@ -58,7 +58,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
if (f.isSolved() == false) {
|
||||
List<Function> partial = f.solveOneStep();
|
||||
for (Function fnc : partial) {
|
||||
@ -72,13 +72,13 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
|
||||
@Override
|
||||
public void generateGraphics() {
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
f.setSmall(false);
|
||||
f.generateGraphics();
|
||||
}
|
||||
|
||||
width = 0;
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
if (f.getWidth() > width) {
|
||||
width = f.getWidth();
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
width += 5;
|
||||
|
||||
height = 3;
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
height += f.getHeight()+spacing;
|
||||
}
|
||||
height = height - spacing + 2;
|
||||
@ -102,7 +102,7 @@ public class EquationsSystem extends FunctionMultipleValues {
|
||||
final int marginBottom = (h - 3 - 2) / 2 + marginTop;
|
||||
final int spazioSopra = h - marginBottom;
|
||||
int dy = marginTop;
|
||||
for (Function f : variables) {
|
||||
for (Function f : functions) {
|
||||
f.draw(x + 5, y + dy);
|
||||
dy+=f.getHeight()+spacing;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.warp.picalculator.math.functions.equations;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3f;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawLine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -55,7 +55,6 @@ public class EquationsSystemPart extends AnteriorFunction {
|
||||
final int spazioSotto = (h - 3 - 2) / 2 + paddingTop;
|
||||
final int spazioSopra = h - spazioSotto;
|
||||
variable.draw(x + 5, y + paddingTop);
|
||||
glColor3f(0, 0, 0);
|
||||
glDrawLine(x + 2, y + 0, x + 3, y + 0);
|
||||
glDrawLine(x + 1, y + 1, x + 1, y + spazioSotto / 2);
|
||||
glDrawLine(x + 2, y + spazioSotto / 2 + 1, x + 2, y + spazioSotto - 1);
|
||||
|
@ -78,7 +78,7 @@ public class ExpandRule1 {
|
||||
if (fnc instanceof Sum) {
|
||||
Function a = ((Sum) fnc).getVariable1();
|
||||
Function b = ((Sum) fnc).getVariable2();
|
||||
Subtraction fnc2 = new Subtraction(((Negative) f).getParent(), null, b);
|
||||
Subtraction fnc2 = new Subtraction(f.getParent(), null, b);
|
||||
fnc2.setVariable1(new Negative(fnc2, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new Subtraction(f.getParent(), null, null);
|
||||
@ -102,11 +102,11 @@ public class ExpandRule1 {
|
||||
result.add(fnc2);
|
||||
}
|
||||
} else if (fnc instanceof SumSubtraction) {
|
||||
Function a = ((Subtraction) fnc).getVariable1();
|
||||
Function b = ((Subtraction) fnc).getVariable2();
|
||||
Sum fnc2 = new Sum(((Negative) f).getParent(), null, b);
|
||||
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(((Negative) f).getParent(), null, b);
|
||||
Subtraction fnc3 = new Subtraction(f.getParent(), null, b);
|
||||
fnc3.setVariable1(new Negative(fnc2, a));
|
||||
if (fromSubtraction > 0) {
|
||||
subtraction = new SumSubtraction(f.getParent(), null, null);
|
||||
@ -117,8 +117,10 @@ public class ExpandRule1 {
|
||||
subtraction.setVariable1(((FunctionTwoValues)f).getVariable1());
|
||||
subtraction.setVariable2(fnc3);
|
||||
result.add(subtraction);
|
||||
result.add(subtraction);
|
||||
} else {
|
||||
result.add(fnc2);
|
||||
result.add(fnc2);
|
||||
}
|
||||
}
|
||||
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.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
@ -18,13 +19,15 @@ public class ExpandRule5 {
|
||||
public static boolean compare(Function f) {
|
||||
if (f instanceof Negative) {
|
||||
Negative fnc = (Negative) f;
|
||||
if (fnc.getVariable() instanceof Negative) {
|
||||
return true;
|
||||
if (fnc.getVariable() instanceof Expression) {
|
||||
Expression e = (Expression)fnc.getVariable();
|
||||
return e.getVariablesLength() == 1 && e.getVariable(0) instanceof Negative;
|
||||
}
|
||||
} else if (f instanceof Subtraction) {
|
||||
Subtraction fnc = (Subtraction) f;
|
||||
if (fnc.getVariable2() instanceof Negative) {
|
||||
return true;
|
||||
if (fnc.getVariable2() instanceof Expression) {
|
||||
Expression e = (Expression)fnc.getVariable2();
|
||||
return e.getVariablesLength() == 1 && e.getVariable(0) instanceof Negative;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -36,10 +39,10 @@ public class ExpandRule5 {
|
||||
|
||||
if (f instanceof Negative) {
|
||||
Negative fnc = (Negative) f;
|
||||
result.add(((Negative)fnc.getVariable()).getVariable().setParent(f.getParent()));
|
||||
result.add(((Negative)((Expression)fnc.getVariable()).getVariable(0)).getVariable().setParent(f.getParent()));
|
||||
} else if (f instanceof Subtraction) {
|
||||
Subtraction fnc = (Subtraction) f;
|
||||
result.add(((Negative)fnc.getVariable2()).getVariable().setParent(f.getParent()));
|
||||
result.add(((Negative)((Expression)fnc.getVariable2()).getVariable(0)).getVariable().setParent(f.getParent()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
32
src/org/warp/picalculator/math/rules/ExponentRule1.java
Normal file
32
src/org/warp/picalculator/math/rules/ExponentRule1.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Exponent rule<br>
|
||||
* <b>1^a=1</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1().equals(new Number(null, 1))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
42
src/org/warp/picalculator/math/rules/ExponentRule15.java
Normal file
42
src/org/warp/picalculator/math/rules/ExponentRule15.java
Normal file
@ -0,0 +1,42 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Exponent rule<br>
|
||||
* <b>a*a=a^2</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule15 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Multiplication fnc = (Multiplication) f;
|
||||
if (fnc.getVariable1().equals(fnc.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
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);
|
||||
expr.addFunctionToEnd(a);
|
||||
Number two = new Number(p, 2);
|
||||
p.setVariable1(expr);
|
||||
p.setVariable2(two);
|
||||
result.add(p);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
32
src/org/warp/picalculator/math/rules/ExponentRule2.java
Normal file
32
src/org/warp/picalculator/math/rules/ExponentRule2.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Exponent rule<br>
|
||||
* <b>a^1=a</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable2().equals(new Number(null, 1))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(((Power)f).getVariable1().setParent(f.getParent()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
32
src/org/warp/picalculator/math/rules/ExponentRule3.java
Normal file
32
src/org/warp/picalculator/math/rules/ExponentRule3.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Exponent rule<br>
|
||||
* <b>a^0=1</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule3 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable2().equals(new Number(null, 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
53
src/org/warp/picalculator/math/rules/ExponentRule4.java
Normal file
53
src/org/warp/picalculator/math/rules/ExponentRule4.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Exponent rule<br>
|
||||
* <b>(a*b)^n=a^n*b^n</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class ExponentRule4 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1() instanceof Expression && ((Expression) fnc.getVariable1()).getVariablesLength() == 1 && ((Expression) fnc.getVariable1()).getVariable(0) instanceof Multiplication && fnc.getVariable2() instanceof Number) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Power fnc = (Power) f;
|
||||
Expression expr = (Expression) fnc.getVariable1();
|
||||
Multiplication mult = (Multiplication) expr.getVariable(0);
|
||||
Function a = mult.getVariable1();
|
||||
Function b = mult.getVariable2();
|
||||
Number n = (Number) fnc.getVariable2();
|
||||
Multiplication retMult = new Multiplication(f.getParent(), null, null);
|
||||
Power p1 = new Power(retMult, null, null);
|
||||
Expression e1 = new Expression(p1);
|
||||
e1.addFunctionToEnd(a);
|
||||
p1.setVariable1(e1);
|
||||
p1.setVariable2(n);
|
||||
Power p2 = new Power(retMult, null, null);
|
||||
Expression e2 = new Expression(p2);
|
||||
e2.addFunctionToEnd(b);
|
||||
p2.setVariable1(e2);
|
||||
p2.setVariable2(n);
|
||||
retMult.setVariable1(p1);
|
||||
retMult.setVariable2(p2);
|
||||
result.add(retMult);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,11 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Fractions rule<br>
|
||||
@ -19,31 +16,25 @@ import org.warp.picalculator.Error;
|
||||
public class FractionsRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
try {
|
||||
if (f instanceof Division) {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1() instanceof Number) {
|
||||
Number numb1 = (Number) fnc.getVariable1();
|
||||
if (numb1.equals(new Number(null, "0"))) {
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb2 = (Number) fnc.getVariable2();
|
||||
if (numb2.equals(new Number(null, "0"))) {
|
||||
return false;
|
||||
}
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1() instanceof Number) {
|
||||
Number numb1 = (Number) fnc.getVariable1();
|
||||
if (numb1.equals(new Number(null, 0))) {
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb2 = (Number) fnc.getVariable2();
|
||||
if (numb2.equals(new Number(null, 0))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Number(f.getParent(), "0"));
|
||||
result.add(new Number(f.getParent(), 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,11 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Fractions rule<br>
|
||||
@ -19,18 +16,12 @@ import org.warp.picalculator.Error;
|
||||
public class FractionsRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
try {
|
||||
if (f instanceof Division) {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, "1"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,37 +1,31 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
/**
|
||||
* Fractions rule<br>
|
||||
* <b>a / 1 = a</b>
|
||||
* <b>a / a = 1</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class FractionsRule3 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
if (f instanceof Division) {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1().equals(fnc.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable1().equals(fnc.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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(new Number(f.getParent(), 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,12 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzato;
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
/**
|
||||
* Fractions rule<br>
|
||||
@ -19,14 +16,12 @@ import org.warp.picalculator.Error;
|
||||
*/
|
||||
public class FractionsRule4 {
|
||||
|
||||
public static boolean compare(Function f) throws Error {
|
||||
if (f instanceof Power) {
|
||||
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"))) {
|
||||
return true;
|
||||
}
|
||||
public static boolean compare(Function f) {
|
||||
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))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -1,16 +1,13 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.nevec.rjm.NumeroAvanzato;
|
||||
import org.nevec.rjm.NumeroAvanzatoVec;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
/**
|
||||
* Fractions rule<br>
|
||||
@ -20,14 +17,12 @@ import org.warp.picalculator.Error;
|
||||
*/
|
||||
public class FractionsRule5 {
|
||||
|
||||
public static boolean compare(Function f) throws Error {
|
||||
if (f instanceof Power) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
||||
Number n2 = (Number) fnc.getVariable2();
|
||||
if (n2.getTerm().compareTo(new NumeroAvanzatoVec(NumeroAvanzato.ZERO)) < 0) {
|
||||
return true;
|
||||
}
|
||||
public static boolean compare(Function f) {
|
||||
Power fnc = (Power) f;
|
||||
if (fnc.getVariable1() instanceof Division && fnc.getVariable2() instanceof Number) {
|
||||
Number n2 = (Number) fnc.getVariable2();
|
||||
if (n2.getTerm().compareTo(BigInteger.ZERO) < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -1,14 +1,12 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a * 0 = 0</b>
|
||||
@ -18,24 +16,18 @@ import org.warp.picalculator.Error;
|
||||
public class NumberRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
try {
|
||||
if (f instanceof Multiplication) {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, "0"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, "0"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a * 1 = a</b>
|
||||
@ -18,24 +16,18 @@ import org.warp.picalculator.Error;
|
||||
public class NumberRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
try {
|
||||
if (f instanceof Multiplication) {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, "1"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, "1"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, 1))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -47,14 +39,14 @@ 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(null, 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(null, 1))) {
|
||||
a = mult.getVariable1();
|
||||
aFound = true;
|
||||
}
|
||||
|
59
src/org/warp/picalculator/math/rules/NumberRule3.java
Normal file
59
src/org/warp/picalculator/math/rules/NumberRule3.java
Normal file
@ -0,0 +1,59 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a - a = 0</b><br>
|
||||
* <b>-a + a = 0</b><br>
|
||||
* <b>a ± a = {0, 2a}</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule3 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
if (f instanceof Subtraction) {
|
||||
Subtraction sub = (Subtraction) f;
|
||||
if (sub.getVariable1().equals(sub.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
} else if (f instanceof Sum) {
|
||||
Sum sub = (Sum) f;
|
||||
if (sub.getVariable1() instanceof Negative) {
|
||||
Negative neg = (Negative) sub.getVariable1();
|
||||
if (neg.getVariable().equals(sub.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (f instanceof SumSubtraction) {
|
||||
SumSubtraction sub = (SumSubtraction) f;
|
||||
if (sub.getVariable1().equals(sub.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
if (f instanceof SumSubtraction) {
|
||||
Multiplication mul = new Multiplication(f.getParent(), null, null);
|
||||
mul.setVariable1(new Number(null, 2));
|
||||
mul.setVariable2(f);
|
||||
result.add(mul);
|
||||
}
|
||||
result.add(new Number(f.getParent(), 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
34
src/org/warp/picalculator/math/rules/NumberRule4.java
Normal file
34
src/org/warp/picalculator/math/rules/NumberRule4.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a ± b = {a+b, a-b}</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule4 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
if (f instanceof SumSubtraction) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
SumSubtraction ss = (SumSubtraction) f;
|
||||
result.add(new Sum(f.getParent(), ss.getVariable1(), ss.getVariable2()));
|
||||
result.add(new Subtraction(f.getParent(), ss.getVariable1(), ss.getVariable2()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
44
src/org/warp/picalculator/math/rules/NumberRule5.java
Normal file
44
src/org/warp/picalculator/math/rules/NumberRule5.java
Normal file
@ -0,0 +1,44 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a + 0 = a</b><br>
|
||||
* <b>0 + a = a</b><br>
|
||||
* <b>a - 0 = a</b><br>
|
||||
* <b>0 - a = a</b><br>
|
||||
* <b>a ± 0 = a</b><br>
|
||||
* <b>0 ± a = a</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
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))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
FunctionTwoValues fnc = (FunctionTwoValues) f;
|
||||
Function a = fnc.getVariable1();
|
||||
if (a.equals(new Number(null, 0))) {
|
||||
a = fnc.getVariable2();
|
||||
}
|
||||
result.add(a.setParent(f.getParent()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
63
src/org/warp/picalculator/math/rules/NumberRule6.java
Normal file
63
src/org/warp/picalculator/math/rules/NumberRule6.java
Normal file
@ -0,0 +1,63 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a * -1 = -a</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule6 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (mult.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable2();
|
||||
if (numb.equals(new Number(null, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Function a = null;
|
||||
boolean aFound = false;
|
||||
Multiplication mult = (Multiplication) f;
|
||||
if (aFound == false & mult.getVariable1() instanceof Number) {
|
||||
Number numb = (Number) mult.getVariable1();
|
||||
if (numb.equals(new Number(null, -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))) {
|
||||
a = mult.getVariable1();
|
||||
aFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
Negative minus = new Negative(f.getParent(), null);
|
||||
minus.setVariable(a);
|
||||
|
||||
result.add(minus);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
32
src/org/warp/picalculator/math/rules/NumberRule7.java
Normal file
32
src/org/warp/picalculator/math/rules/NumberRule7.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
|
||||
/**
|
||||
* Number rule<br>
|
||||
* <b>a + a = 2a</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class NumberRule7 {
|
||||
|
||||
public static boolean compare(Sum f) {
|
||||
return f.getVariable1().equals(f.getVariable2());
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication mult = new Multiplication(f.getParent(), null, null);
|
||||
mult.setVariable1(new Number(null, 2));
|
||||
mult.setVariable2(f.getVariable1());
|
||||
result.add(mult);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
49
src/org/warp/picalculator/math/rules/SyntaxRule1.java
Normal file
49
src/org/warp/picalculator/math/rules/SyntaxRule1.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
|
||||
/**
|
||||
* Syntax rule<br>
|
||||
* <b>(a*b)*c=a*(b*c)</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class SyntaxRule1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
FunctionTwoValues m = (FunctionTwoValues) f;
|
||||
if (m instanceof Multiplication & m.getVariable1() instanceof Multiplication) {
|
||||
return true;
|
||||
} else if (m instanceof Sum & m.getVariable1() instanceof Sum) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
FunctionTwoValues mOut = (FunctionTwoValues) f;
|
||||
Function a = ((FunctionTwoValues)mOut.getVariable1()).getVariable1();
|
||||
Function b = ((FunctionTwoValues)mOut.getVariable1()).getVariable2();
|
||||
Function c = mOut.getVariable2();
|
||||
FunctionTwoValues mIn;
|
||||
if (f instanceof Multiplication) {
|
||||
mIn = new Multiplication(mOut, null, null);
|
||||
} else {
|
||||
mIn = new Sum(mOut, null, null);
|
||||
}
|
||||
mOut.setVariable1(a);
|
||||
mIn.setVariable1(b);
|
||||
mIn.setVariable2(c);
|
||||
mOut.setVariable2(mIn);
|
||||
result.add(mOut);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
53
src/org/warp/picalculator/math/rules/SyntaxRule2.java
Normal file
53
src/org/warp/picalculator/math/rules/SyntaxRule2.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
|
||||
/**
|
||||
* Syntax rule<br>
|
||||
* <b>a+(b+c)=(a+b)+c</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class SyntaxRule2 {
|
||||
|
||||
public static boolean compare(Sum f) {
|
||||
if (f.getVariable2() instanceof Sum) {
|
||||
return true;
|
||||
}
|
||||
if (f.getVariable2() instanceof Expression) {
|
||||
Expression e = (Expression) f.getVariable2();
|
||||
if (e.getVariablesLength() == 1 && e.getVariable(0) instanceof Sum) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Sum f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Function a = f.getVariable1();
|
||||
Function b, c;
|
||||
if (f.getVariable2() instanceof Sum) {
|
||||
b = ((Sum)f.getVariable2()).getVariable1();
|
||||
c = ((Sum)f.getVariable2()).getVariable2();
|
||||
} else {
|
||||
b = ((Sum)((Expression)f.getVariable2()).getVariable(0)).getVariable1();
|
||||
c = ((Sum)((Expression)f.getVariable2()).getVariable(0)).getVariable2();
|
||||
}
|
||||
Sum mIn = new Sum(f, null, null);
|
||||
f.setVariable1(mIn);
|
||||
mIn.setVariable1(a);
|
||||
mIn.setVariable2(b);
|
||||
f.setVariable2(c);
|
||||
result.add(f);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
33
src/org/warp/picalculator/math/rules/UndefinedRule1.java
Normal file
33
src/org/warp/picalculator/math/rules/UndefinedRule1.java
Normal file
@ -0,0 +1,33 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
import org.warp.picalculator.math.functions.Undefined;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
/**
|
||||
* Undefined rule<br>
|
||||
* <b>0^0=undefined</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
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))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
result.add(new Undefined(f.getParent()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Undefined;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Undefined;
|
||||
|
||||
/**
|
||||
* Undefined rule<br>
|
||||
@ -18,18 +17,12 @@ import org.warp.picalculator.Error;
|
||||
public class UndefinedRule2 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
try {
|
||||
if (f instanceof Division) {
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, "0"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Division fnc = (Division) f;
|
||||
if (fnc.getVariable2() instanceof Number) {
|
||||
Number numb = (Number) fnc.getVariable2();
|
||||
if (numb.equals(new Number(null, 0))) {
|
||||
return true;
|
||||
}
|
||||
} catch (Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
58
src/org/warp/picalculator/math/rules/VariableRule1.java
Normal file
58
src/org/warp/picalculator/math/rules/VariableRule1.java
Normal file
@ -0,0 +1,58 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
|
||||
/**
|
||||
* Variable rule<br>
|
||||
* <b>ax+bx=(a+b)*x (a,b NUMBER; x VARIABLE|MULTIPLICATION)</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class VariableRule1 {
|
||||
|
||||
public static boolean compare(FunctionTwoValues fnc) {
|
||||
if (fnc.getVariable1() instanceof Multiplication & fnc.getVariable2() instanceof Multiplication) {
|
||||
Multiplication m1 = (Multiplication) fnc.getVariable1();
|
||||
Multiplication m2 = (Multiplication) fnc.getVariable2();
|
||||
if (m1.getVariable2().equals(m2.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication m1 = (Multiplication) fnc.getVariable1();
|
||||
Multiplication m2 = (Multiplication) fnc.getVariable2();
|
||||
Function a = m1.getVariable1();
|
||||
Function b = m2.getVariable1();
|
||||
Function x = m1.getVariable2();
|
||||
|
||||
Multiplication retm = new Multiplication(fnc.getParent(), null, null);
|
||||
Expression rete = new Expression(retm);
|
||||
FunctionTwoValues rets;
|
||||
if (fnc instanceof Sum){
|
||||
rets = new Sum(rete, null, null);
|
||||
} else {
|
||||
rets = new Subtraction(rete, null, null);
|
||||
}
|
||||
rets.setVariable1(a);
|
||||
rets.setVariable2(b);
|
||||
rete.addFunctionToEnd(rets);
|
||||
retm.setVariable1(rete);
|
||||
retm.setVariable2(x);
|
||||
result.add(retm);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
57
src/org/warp/picalculator/math/rules/VariableRule2.java
Normal file
57
src/org/warp/picalculator/math/rules/VariableRule2.java
Normal file
@ -0,0 +1,57 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
|
||||
/**
|
||||
* Variable rule<br>
|
||||
* <b>ax+x=(a+1)*x (a,b NUMBER; x VARIABLES)</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class VariableRule2 {
|
||||
|
||||
public static boolean compare(FunctionTwoValues fnc) {
|
||||
if (fnc.getVariable1() instanceof Multiplication) {
|
||||
Multiplication m1 = (Multiplication) fnc.getVariable1();
|
||||
if (m1.getVariable2().equals(fnc.getVariable2())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication m1 = (Multiplication) fnc.getVariable1();
|
||||
Function a = m1.getVariable1();
|
||||
Function x = fnc.getVariable2();
|
||||
|
||||
Multiplication retm = new Multiplication(fnc.getParent(), null, null);
|
||||
Expression rete = new Expression(retm);
|
||||
|
||||
FunctionTwoValues rets;
|
||||
if (fnc instanceof Sum) {
|
||||
rets = new Sum(rete, null, null);
|
||||
} else {
|
||||
rets = new Subtraction(rete, null, null);
|
||||
}
|
||||
rets.setVariable1(a);
|
||||
rets.setVariable2(new Number(rets, 1));
|
||||
rete.addFunctionToEnd(rets);
|
||||
retm.setVariable1(rete);
|
||||
retm.setVariable2(x);
|
||||
result.add(retm);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
57
src/org/warp/picalculator/math/rules/VariableRule3.java
Normal file
57
src/org/warp/picalculator/math/rules/VariableRule3.java
Normal file
@ -0,0 +1,57 @@
|
||||
package org.warp.picalculator.math.rules;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
|
||||
/**
|
||||
* Variable rule<br>
|
||||
* <b>x+ax=(a+1)*x (a,b NUMBER; x VARIABLES)</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class VariableRule3 {
|
||||
|
||||
public static boolean compare(FunctionTwoValues fnc) {
|
||||
if (fnc.getVariable2() instanceof Multiplication) {
|
||||
Multiplication m2 = (Multiplication) fnc.getVariable2();
|
||||
if (m2.getVariable2().equals(fnc.getVariable1())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(FunctionTwoValues fnc) throws Error {
|
||||
ArrayList<Function> result = new ArrayList<>();
|
||||
Multiplication m2 = (Multiplication) fnc.getVariable2();
|
||||
Function a = m2.getVariable1();
|
||||
Function x = fnc.getVariable1();
|
||||
|
||||
Multiplication retm = new Multiplication(fnc.getParent(), null, null);
|
||||
Expression rete = new Expression(retm);
|
||||
FunctionTwoValues rets;
|
||||
if (fnc instanceof Sum) {
|
||||
rets = new Sum(rete, null, null);
|
||||
} else {
|
||||
rets = new Subtraction(rete, null, null);
|
||||
}
|
||||
|
||||
rets.setVariable1(new Number(rets, 1));
|
||||
rets.setVariable2(a);
|
||||
rete.addFunctionToEnd(rets);
|
||||
retm.setVariable1(rete);
|
||||
retm.setVariable2(x);
|
||||
result.add(retm);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
114
src/org/warp/picalculator/math/rules/methods/SumMethod1.java
Normal file
114
src/org/warp/picalculator/math/rules/methods/SumMethod1.java
Normal file
@ -0,0 +1,114 @@
|
||||
package org.warp.picalculator.math.rules.methods;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import org.warp.picalculator.math.functions.FunctionTwoValues;
|
||||
import org.warp.picalculator.math.functions.Negative;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
|
||||
/**
|
||||
* Sum method<br>
|
||||
* <b>13+sqrt(2)+5X+1 = 14+sqrt(2)+5X</b>
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
public class SumMethod1 {
|
||||
|
||||
public static boolean compare(Function f) {
|
||||
return (f instanceof Sum || f instanceof Subtraction) && ((FunctionTwoValues)f).getVariable1().isSolved() && ((FunctionTwoValues)f).getVariable2().isSolved() && !(((FunctionTwoValues)f).getVariable1() instanceof Number && ((FunctionTwoValues)f).getVariable2() instanceof Number) && getFirstWorkingSumCouple(getSumElements(f)) != null;
|
||||
}
|
||||
|
||||
public static ArrayList<Function> execute(Function f) throws Error {
|
||||
Function result;
|
||||
ArrayList<Function> elements = getSumElements(f);
|
||||
int[] workingElementCouple = getFirstWorkingSumCouple(elements);
|
||||
Function elem1 = elements.get(workingElementCouple[0]);
|
||||
Function elem2 = elements.get(workingElementCouple[1]);
|
||||
|
||||
final int size = elements.size();
|
||||
Function prec = new Sum(null, 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);
|
||||
if (b instanceof Negative) {
|
||||
prec = new Subtraction(null, a, ((Negative)b).getVariable());
|
||||
a.setParent(prec);
|
||||
((FunctionTwoValues)prec).getVariable2().setParent(prec);
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigInteger.ZERO) < 0) {
|
||||
prec = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
|
||||
a.setParent(prec);
|
||||
((FunctionTwoValues)prec).getVariable2().setParent(prec);
|
||||
} else {
|
||||
prec = new Sum(null, a, b);
|
||||
a.setParent(prec);
|
||||
b.setParent(prec);
|
||||
}
|
||||
}
|
||||
}
|
||||
prec.setParent(f.getParent());
|
||||
|
||||
result = prec;
|
||||
|
||||
ArrayList<Function> results = new ArrayList<>();
|
||||
results.add(result);
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ArrayList<Function> getSumElements(Function sum) {
|
||||
ArrayList<Function> elements = new ArrayList<>();
|
||||
while (sum instanceof Sum || sum instanceof Subtraction) {
|
||||
if (sum instanceof Sum) {
|
||||
elements.add(((FunctionTwoValues) sum).getVariable2());
|
||||
} else {
|
||||
elements.add(new Negative(null, ((FunctionTwoValues) sum).getVariable2()));
|
||||
}
|
||||
sum = ((FunctionTwoValues) sum).getVariable1();
|
||||
}
|
||||
elements.add(sum);
|
||||
return elements;
|
||||
}
|
||||
|
||||
private static int[] getFirstWorkingSumCouple(ArrayList<Function> elements) {
|
||||
final int size = elements.size();
|
||||
Function a;
|
||||
Function b;
|
||||
if (elements.size() == 2) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
a = elements.get(i);
|
||||
for (int j = 0; j < size; j++) {
|
||||
b = elements.get(j);
|
||||
if (i != j) {
|
||||
Function testFunc;
|
||||
if (b instanceof Negative) {
|
||||
testFunc = new Subtraction(null, a, ((Negative)b).getVariable());
|
||||
} else if (b instanceof Number && ((Number) b).getTerm().compareTo(BigInteger.ZERO) < 0) {
|
||||
testFunc = new Subtraction(null, a, ((Number)b).multiply(new Number(null, -1)));
|
||||
} else if (a instanceof Negative) {
|
||||
testFunc = new Subtraction(null, b, ((Negative)a).getVariable());
|
||||
} else if (a instanceof Number && ((Number) a).getTerm().compareTo(BigInteger.ZERO) < 0) {
|
||||
testFunc = new Subtraction(null, b, ((Number)a).multiply(new Number(null, -1)));
|
||||
} else {
|
||||
testFunc = new Sum(null, a, b);
|
||||
}
|
||||
if (!testFunc.isSolved()) {
|
||||
return new int[]{i, j};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package org.warp.picalculator.screens;
|
||||
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
|
||||
|
@ -5,46 +5,39 @@ import static org.warp.picalculator.device.graphicengine.Display.Render.*;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.Display.Render;
|
||||
import org.warp.picalculator.device.graphicengine.RAWFont;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
|
||||
import com.rits.cloning.Cloner;
|
||||
import com.rits.cloning.FastClonerArrayList;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
|
||||
public class EquationScreen extends Screen {
|
||||
|
||||
public float endLoading;
|
||||
public volatile String equazioneCorrente = "";
|
||||
public volatile String nuovaEquazione = "";
|
||||
public volatile int caretPos = 0;
|
||||
public volatile boolean showCaret = true;
|
||||
public volatile float showCaretDelta = 0f;
|
||||
public List<Function> f;
|
||||
public List<Function> f2;
|
||||
public ArrayList<Function> f;
|
||||
public ArrayList<Function> f2;
|
||||
public int resultsCount;
|
||||
public int ew1;
|
||||
public int ew2;
|
||||
public int eh2;
|
||||
public int x1;
|
||||
public int x2;
|
||||
public boolean requiresleep1;
|
||||
public boolean requiresleep2;
|
||||
public boolean aftersleep;
|
||||
public boolean autoscroll;
|
||||
public int scrollX = 0;
|
||||
public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto
|
||||
public Error err1;
|
||||
public Error err2;
|
||||
boolean mustRefresh = true;
|
||||
boolean afterDoNextStep = false;
|
||||
|
||||
public EquationScreen() {
|
||||
super();
|
||||
@ -53,7 +46,7 @@ public class EquationScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void created() throws InterruptedException {
|
||||
endLoading = 0;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -118,20 +111,25 @@ public class EquationScreen extends Screen {
|
||||
// 1000000 + " milliseconds\n");
|
||||
}
|
||||
|
||||
public void interpreta(String eqn) throws Error {
|
||||
equazioneCorrente = eqn;
|
||||
List<Function> fncs = new ArrayList<Function>();
|
||||
fncs.add(Calculator.parseString(equazioneCorrente.replace("sqrt", "Ⓐ").replace("^", "Ⓑ")));
|
||||
public void interpreta(boolean temporary) throws Error {
|
||||
String eqn = nuovaEquazione;
|
||||
if (!temporary) {
|
||||
equazioneCorrente = eqn;
|
||||
}
|
||||
ArrayList<Function> fncs = new ArrayList<Function>();
|
||||
if (eqn.length() > 0) {
|
||||
fncs.add(Calculator.parseString(eqn.replace("sqrt", "Ⓐ").replace("^", "Ⓑ")));
|
||||
}
|
||||
f = fncs;
|
||||
for (Function f : f) {
|
||||
f.generateGraphics();
|
||||
try {
|
||||
f.generateGraphics();
|
||||
} catch (NullPointerException ex) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void solve() throws Error {
|
||||
Calculator.solve(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(float dt) {
|
||||
showCaretDelta += dt;
|
||||
@ -140,19 +138,71 @@ public class EquationScreen extends Screen {
|
||||
showCaret = !showCaret;
|
||||
showCaretDelta = 0f;
|
||||
}
|
||||
if (caretPos > nuovaEquazione.length()) {
|
||||
caretPos = nuovaEquazione.length();
|
||||
}
|
||||
|
||||
if (PIDisplay.error == null) {
|
||||
glClearColor(0xFFc5c2af);
|
||||
} else {
|
||||
glClearColor(0xFFDC3C32);
|
||||
}
|
||||
}
|
||||
|
||||
private static final RAWFont fontBig = Utils.getFont(false);
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Display.Render.glSetFont(Utils.getFont(false));
|
||||
glClearColor(0xFFCCE7D4);
|
||||
glColor3f(0, 0, 0);
|
||||
glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length()));
|
||||
Display.Render.glSetFont(fontBig);
|
||||
final int textColor = 0xFF000000;
|
||||
final int padding = 4;
|
||||
glColor(textColor);
|
||||
final String inputText = nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length());
|
||||
final boolean tooLongI = padding+glGetStringWidth(fontBig, nuovaEquazione)+padding >= Main.screenSize[0];
|
||||
int scrollI = 0;
|
||||
if (tooLongI) {
|
||||
scrollI = -scrollX;
|
||||
if (-scrollI >= Main.screenSize[0]) {
|
||||
scrollI += Main.screenSize[0];
|
||||
} else {
|
||||
scrollI = 0;
|
||||
}
|
||||
}
|
||||
glDrawStringLeft(padding+scrollI, padding+20, inputText);
|
||||
if (tooLongI) {
|
||||
glColor(clearcolor);
|
||||
glFillRect(Main.screenSize[0]-16-2, padding+20, fontBig.charH, Main.screenSize[0]);
|
||||
glColor(textColor);
|
||||
PIDisplay.drawSkinPart(Main.screenSize[0]-16, padding+20+fontBig.charH/2-16/2, 304, 0, 304+16, 16);
|
||||
}
|
||||
if (f != null) {
|
||||
int topSpacing = 0;
|
||||
for (Function f : f) {
|
||||
f.draw(2, 22+1+glGetCurrentFontHeight()+1+topSpacing);
|
||||
topSpacing += f.getHeight() + 2;
|
||||
Iterator<Function> iter = f.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Function fnc = iter.next();
|
||||
try {
|
||||
final boolean tooLong = padding+fnc.getWidth()+padding >= Main.screenSize[0];
|
||||
int scrollA = 0;
|
||||
if (tooLong) {
|
||||
scrollA = -scrollX;
|
||||
if (-scrollA >= Main.screenSize[0]) {
|
||||
scrollA += Main.screenSize[0];
|
||||
} else {
|
||||
scrollA = 0;
|
||||
}
|
||||
}
|
||||
final int y = padding+20+padding+fontBig.charH+1+topSpacing;
|
||||
fnc.draw(padding+scrollA, y);
|
||||
if (tooLong) {
|
||||
glColor(clearcolor);
|
||||
glFillRect(Main.screenSize[0]-16-2, y, fnc.getHeight(), Main.screenSize[0]);
|
||||
glColor(textColor);
|
||||
PIDisplay.drawSkinPart(Main.screenSize[0]-16, y+fnc.getHeight()/2-16/2, 304, 0, 304+16, 16);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
iter.remove();
|
||||
}
|
||||
topSpacing += fnc.getHeight() + 2;
|
||||
}
|
||||
}
|
||||
if (f2 != null) {
|
||||
@ -165,7 +215,7 @@ public class EquationScreen extends Screen {
|
||||
String resultsCountText = resultsCount+" total results".toUpperCase();
|
||||
glColor(0xFF9AAEA0);
|
||||
glSetFont(Utils.getFont(true));
|
||||
bottomSpacing += glGetCurrentFontHeight()+2;
|
||||
bottomSpacing += fontBig.charH+2;
|
||||
glDrawStringRight(Display.getWidth() - 2, Display.getHeight() - bottomSpacing, resultsCountText);
|
||||
}
|
||||
}
|
||||
@ -186,36 +236,66 @@ public class EquationScreen extends Screen {
|
||||
switch (k) {
|
||||
case SIMPLIFY:
|
||||
if (nuovaEquazione.length() > 0) {
|
||||
Calculator.simplify(this);
|
||||
try {
|
||||
try {
|
||||
if (!afterDoNextStep) {
|
||||
interpreta(false);
|
||||
f2 = f;
|
||||
afterDoNextStep = true;
|
||||
Calculator.simplify(this);
|
||||
}
|
||||
Calculator.simplify(this);
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
glClearColor(0xFFDC3C32);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case SOLVE:
|
||||
if (PIDisplay.error != null) {
|
||||
Utils.debug.println("Resetting after error...");
|
||||
PIDisplay.error = null;
|
||||
this.equazioneCorrente = null;
|
||||
this.f = null;
|
||||
this.f2 = null;
|
||||
this.resultsCount = 0;
|
||||
return true;
|
||||
} else {
|
||||
if (nuovaEquazione != equazioneCorrente && nuovaEquazione.length() > 0) {
|
||||
try {
|
||||
try {
|
||||
try {
|
||||
changeEquationScreen();
|
||||
interpreta(nuovaEquazione);
|
||||
solve();
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
if (afterDoNextStep) {
|
||||
Calculator.simplify(this);
|
||||
} else {
|
||||
if (nuovaEquazione != equazioneCorrente && nuovaEquazione.length() > 0) {
|
||||
changeEquationScreen();
|
||||
interpreta(false);
|
||||
Calculator.solve(this);
|
||||
}
|
||||
throw new Error(Errors.ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
glClearColor(0xFFDC3C32);
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -283,17 +363,16 @@ public class EquationScreen extends Screen {
|
||||
typeChar("√");
|
||||
return true;
|
||||
case POWER_OF_2:
|
||||
typeChar("^");
|
||||
typeChar("2");
|
||||
typeChar("^2");
|
||||
return true;
|
||||
case POWER_OF_x:
|
||||
typeChar("^");
|
||||
return true;
|
||||
case LETTER_X:
|
||||
typeChar("X");
|
||||
typeChar(MathematicalSymbols.variables()[23]);
|
||||
return true;
|
||||
case LETTER_Y:
|
||||
typeChar("Y");
|
||||
typeChar(MathematicalSymbols.variables()[24]);
|
||||
return true;
|
||||
case DELETE:
|
||||
if (nuovaEquazione.length() > 0) {
|
||||
@ -303,21 +382,29 @@ public class EquationScreen extends Screen {
|
||||
} else {
|
||||
nuovaEquazione = nuovaEquazione.substring(1);
|
||||
}
|
||||
try {interpreta(true);} catch (Error e) {}
|
||||
}
|
||||
afterDoNextStep = false;
|
||||
return true;
|
||||
case LEFT:
|
||||
if (caretPos > 0) {
|
||||
caretPos -= 1;
|
||||
showCaret = true;
|
||||
showCaretDelta = 0L;
|
||||
} else {
|
||||
caretPos = nuovaEquazione.length();
|
||||
}
|
||||
scrollX = glGetStringWidth(fontBig, nuovaEquazione.substring(0, caretPos)+"|||");
|
||||
showCaret = true;
|
||||
showCaretDelta = 0L;
|
||||
return true;
|
||||
case RIGHT:
|
||||
if (caretPos < nuovaEquazione.length()) {
|
||||
caretPos += 1;
|
||||
showCaret = true;
|
||||
showCaretDelta = 0L;
|
||||
} else {
|
||||
caretPos = 0;
|
||||
}
|
||||
scrollX = glGetStringWidth(fontBig, nuovaEquazione.substring(0, caretPos)+"|||");
|
||||
showCaret = true;
|
||||
showCaretDelta = 0L;
|
||||
return true;
|
||||
case RESET:
|
||||
if (PIDisplay.error != null) {
|
||||
@ -327,11 +414,59 @@ public class EquationScreen extends Screen {
|
||||
} else {
|
||||
caretPos = 0;
|
||||
nuovaEquazione="";
|
||||
afterDoNextStep = false;
|
||||
f.clear();
|
||||
return true;
|
||||
}
|
||||
case SURD_MODE:
|
||||
Calculator.surdMode = !Calculator.surdMode;
|
||||
try {
|
||||
try {
|
||||
if (Calculator.surdMode == false) {
|
||||
f2 = Calculator.solveExpression(f2);
|
||||
} else {
|
||||
equazioneCorrente = "";
|
||||
Keyboard.keyPressed(Key.SOLVE);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
if (Utils.debugOn)
|
||||
ex.printStackTrace();
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (Error e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
PIDisplay.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
return true;
|
||||
case debug1:
|
||||
PIDisplay.INSTANCE.setScreen(new EmptyScreen());
|
||||
return true;
|
||||
case HISTORY_BACK:
|
||||
if (PIDisplay.INSTANCE.canGoBack()) {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0 & Calculator.sessions[Calculator.currentSession+1] instanceof EquationScreen) {
|
||||
nuovaEquazione = equazioneCorrente;
|
||||
try {
|
||||
interpreta(true);
|
||||
} catch (Error e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
case HISTORY_FORWARD:
|
||||
if (PIDisplay.INSTANCE.canGoForward()) {
|
||||
if (equazioneCorrente != null && equazioneCorrente.length() > 0 & Calculator.sessions[Calculator.currentSession-1] instanceof EquationScreen) {
|
||||
nuovaEquazione = equazioneCorrente;
|
||||
try {
|
||||
interpreta(true);
|
||||
} catch (Error e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -342,6 +477,8 @@ public class EquationScreen extends Screen {
|
||||
EquationScreen cloned = clone();
|
||||
cloned.caretPos = cloned.equazioneCorrente.length();
|
||||
cloned.nuovaEquazione = cloned.equazioneCorrente;
|
||||
cloned.scrollX = glGetStringWidth(fontBig, cloned.equazioneCorrente);
|
||||
try {cloned.interpreta(true);} catch (Error e) {}
|
||||
PIDisplay.INSTANCE.replaceScreen(cloned);
|
||||
this.initialized = false;
|
||||
PIDisplay.INSTANCE.setScreen(this);
|
||||
@ -350,10 +487,17 @@ public class EquationScreen extends Screen {
|
||||
}
|
||||
|
||||
public void typeChar(String chr) {
|
||||
int len = chr.length();
|
||||
nuovaEquazione=nuovaEquazione.substring(0, caretPos)+chr+nuovaEquazione.substring(caretPos, nuovaEquazione.length());
|
||||
caretPos+=1;
|
||||
caretPos+=len;
|
||||
scrollX = glGetStringWidth(fontBig, nuovaEquazione.substring(0, caretPos)+"|||");
|
||||
showCaret = true;
|
||||
showCaretDelta = 0L;
|
||||
afterDoNextStep = false;
|
||||
try {
|
||||
interpreta(true);
|
||||
} catch (Error e) {
|
||||
}
|
||||
// f.clear(); //TODO: I removed this line to prevent input blanking when pressing EQUALS button and cloning this screen, but I must see why I created this part of code.
|
||||
}
|
||||
|
||||
@ -367,7 +511,7 @@ public class EquationScreen extends Screen {
|
||||
public EquationScreen clone() {
|
||||
EquationScreen es = this;
|
||||
EquationScreen es2 = new EquationScreen();
|
||||
es2.endLoading = es.endLoading;
|
||||
es2.scrollX = es.scrollX;
|
||||
es2.nuovaEquazione = es.nuovaEquazione;
|
||||
es2.equazioneCorrente = es.equazioneCorrente;
|
||||
es2.showCaret = es.showCaret;
|
||||
@ -376,19 +520,10 @@ public class EquationScreen extends Screen {
|
||||
es2.f = Utils.cloner.deepClone(es.f);
|
||||
es2.f2 = Utils.cloner.deepClone(es.f2);
|
||||
es2.resultsCount = es.resultsCount;
|
||||
es2.ew1 = es.ew1;
|
||||
es2.ew2 = es.ew2;
|
||||
es2.eh2 = es.eh2;
|
||||
es2.x1 = es.x1;
|
||||
es2.x2 = es.x2;
|
||||
es2.requiresleep1 = es.requiresleep1;
|
||||
es2.requiresleep2 = es.requiresleep2;
|
||||
es2.autoscroll = es.autoscroll;
|
||||
es2.errorLevel = es.errorLevel;
|
||||
es2.err1 = es.err1;
|
||||
es2.err2 = es.err2;
|
||||
es2.mustRefresh = es.mustRefresh;
|
||||
es2.aftersleep = es.aftersleep;
|
||||
es2.afterDoNextStep = es.afterDoNextStep;
|
||||
return es2;
|
||||
}
|
||||
|
||||
|
@ -1,25 +1,14 @@
|
||||
package org.warp.picalculator.screens;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.graphicengine.Display;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
import org.warp.picalculator.math.Calculator;
|
||||
import org.warp.picalculator.math.functions.Function;
|
||||
import static org.warp.picalculator.device.PIDisplay.fonts;
|
||||
import static org.warp.picalculator.device.PIDisplay.glyphsHeight;
|
||||
import static org.warp.picalculator.device.PIDisplay.colore;
|
||||
import static org.warp.picalculator.device.PIDisplay.fonts;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringCenter;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glSetFont;
|
||||
|
||||
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;
|
||||
|
||||
public class LoadingScreen extends Screen {
|
||||
|
||||
@ -28,6 +17,7 @@ public class LoadingScreen extends Screen {
|
||||
public float loadingTextTranslation = 0.0f;
|
||||
public boolean loadingTextTranslationTopToBottom = true;
|
||||
private boolean loading;
|
||||
private static final String titleString = "PICalculator by Andrea Cavalli";
|
||||
|
||||
public LoadingScreen() {
|
||||
super();
|
||||
@ -60,7 +50,7 @@ public class LoadingScreen extends Screen {
|
||||
}
|
||||
|
||||
endLoading += dt;
|
||||
if (endLoading >= 1) {
|
||||
if (endLoading >= 2) {
|
||||
loading = false;
|
||||
PIDisplay.INSTANCE.setScreen(new EquationScreen());
|
||||
}
|
||||
@ -71,15 +61,15 @@ public class LoadingScreen extends Screen {
|
||||
public void render() {
|
||||
glSetFont(fonts[2]);
|
||||
colore(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2) - 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
|
||||
glDrawStringCenter((Main.screenSize[0] / 2) - 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), titleString);
|
||||
colore(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2) + 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
|
||||
glDrawStringCenter((Main.screenSize[0] / 2) + 1,(int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), titleString);
|
||||
colore(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 - 1 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 - 1 + loadingTextTranslation), titleString);
|
||||
colore(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + 1 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + 1 + loadingTextTranslation), titleString);
|
||||
colore(1.0f, 0.5f, 0.0f, 1.0f);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), "ANDREA CAVALLI'S CALCULATOR");
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (int) ((Main.screenSize[1]/ 2) - 25 + loadingTextTranslation), titleString);
|
||||
colore(0.0f, 0.0f, 0.0f, 0.75f);
|
||||
glSetFont(fonts[0]);
|
||||
glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 11, "LOADING");
|
||||
|
@ -1,6 +1,10 @@
|
||||
package org.warp.picalculator.screens;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.getMatrixOfImage;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glClearColor;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawSkin;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glDrawStringLeft;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glSetFont;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
@ -9,8 +13,8 @@ import javax.imageio.ImageIO;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.device.PIDisplay;
|
||||
import org.warp.picalculator.device.graphicengine.Screen;
|
||||
|
||||
public class MarioScreen extends Screen {
|
||||
@ -33,7 +37,7 @@ public class MarioScreen extends Screen {
|
||||
|
||||
public MarioScreen() {
|
||||
super();
|
||||
canBeInHistory = true;
|
||||
canBeInHistory = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,7 +75,7 @@ public class MarioScreen extends Screen {
|
||||
boolean rightPressed = Keyboard.isKeyDown(2, 5);
|
||||
boolean leftPressed = Keyboard.isKeyDown(2, 3);
|
||||
boolean jumpPressed = Keyboard.isKeyDown(2, 1);
|
||||
if ((leftPressed | rightPressed) == (leftPressed & rightPressed)) {
|
||||
if ((leftPressed || rightPressed) == (leftPressed & rightPressed)) {
|
||||
walking = false;
|
||||
walkAnimation = 0;
|
||||
} else {
|
||||
@ -130,6 +134,8 @@ public class MarioScreen extends Screen {
|
||||
marioPos[1] -= dt*marioForces[1];
|
||||
}
|
||||
marioForces[0] *= 0.75;
|
||||
|
||||
glClearColor(0xff9290ff);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +145,6 @@ public class MarioScreen extends Screen {
|
||||
glDrawStringLeft(0, 20, "ERROR");
|
||||
} else {
|
||||
glSetFont(PIDisplay.fonts[0]);
|
||||
glClearColor(0xff9290ff);
|
||||
glDrawSkin(groundSize[0], ground, 0, 25+25, 0, 0, 16, 16, false);
|
||||
glDrawSkin(groundSize[0], ground, 16, 25+25, 0, 0, 16, 16, false);
|
||||
glDrawSkin(groundSize[0], ground, 16*2, 25+25, 0, 0, 16, 16, false);
|
||||
|
@ -1,11 +1,13 @@
|
||||
package org.warp.picalculator.screens;
|
||||
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.*;
|
||||
import static org.warp.picalculator.device.graphicengine.Display.Render.glColor3i;
|
||||
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.PIDisplay;
|
||||
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;
|
||||
|
||||
@ -30,11 +32,11 @@ public class SolveEquationScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
glColor4f(0, 0, 0, 64);
|
||||
glColor4i(0, 0, 0, 64);
|
||||
glDrawStringCenter(Main.screenSize[0]/2+1, Main.screenSize[1]/4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
glDrawStringCenter(Main.screenSize[0]/2, Main.screenSize[1]/4+1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
glDrawStringCenter(Main.screenSize[0]/2+1, Main.screenSize[1]/4+1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
glColor3f(255, 0, 0);
|
||||
glColor3i(255, 0, 0);
|
||||
glDrawStringCenter(Main.screenSize[0]/2, Main.screenSize[1]/4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@ -54,7 +56,7 @@ public class SolveEquationScreen extends Screen {
|
||||
case LETTER_X:
|
||||
PIDisplay.INSTANCE.goBack();
|
||||
try {
|
||||
Calculator.solve('X');
|
||||
Calculator.solveExpression('X');
|
||||
} catch (Error e) {
|
||||
Screen scr = PIDisplay.INSTANCE.getScreen();
|
||||
if (scr instanceof EquationScreen) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user