Enchanced result appearance

This commit is contained in:
Andrea Cavalli 2017-06-05 22:50:33 +02:00
parent 845e4cdfe0
commit d46a9c5df4
23 changed files with 307 additions and 83 deletions

View File

@ -198,7 +198,6 @@ public class BlockContainer implements GraphicalElement {
} }
public Block getBlock(Caret caret) { public Block getBlock(Caret caret) {
boolean found = false;
Block block = null; Block block = null;
int pos = 0; int pos = 0;
@ -208,10 +207,11 @@ public class BlockContainer implements GraphicalElement {
final int deltaCaret = caret.getRemaining(); final int deltaCaret = caret.getRemaining();
block= b.getBlock(caret); block= b.getBlock(caret);
found = found | (block != null); if (block != null) {
if (caret.getRemaining() == 0 || (found == false && deltaCaret >= 0 && caret.getRemaining() < 0)) { return block;
}
if (caret.getRemaining() == 0 || (deltaCaret >= 0 && caret.getRemaining() < 0)) {
block = getBlockAt(pos - 1); block = getBlockAt(pos - 1);
found = true;
return block; return block;
} }
} }

View File

@ -6,7 +6,7 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.math.Function; import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.parser.features.FeaturePower; import org.warp.picalculator.math.parser.features.FeaturePowerChar;
import org.warp.picalculator.math.parser.features.interfaces.Feature; import org.warp.picalculator.math.parser.features.interfaces.Feature;
public class BlockPower extends Block { public class BlockPower extends Block {
@ -78,6 +78,6 @@ public class BlockPower extends Block {
@Override @Override
public Feature toFeature(MathContext context) throws Error { public Feature toFeature(MathContext context) throws Error {
final Function exp = getExponentContainer().toFunction(context); final Function exp = getExponentContainer().toFunction(context);
return new FeaturePower(exp); return new FeaturePowerChar(exp);
} }
} }

View File

@ -11,6 +11,7 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer; import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Variable.V_TYPE; import org.warp.picalculator.math.functions.Variable.V_TYPE;
import org.warp.picalculator.math.parser.features.FeatureVariable;
import org.warp.picalculator.math.parser.features.interfaces.Feature; import org.warp.picalculator.math.parser.features.interfaces.Feature;
public class BlockVariable extends Block { public class BlockVariable extends Block {
@ -241,7 +242,6 @@ public class BlockVariable extends Block {
@Override @Override
public Feature toFeature(MathContext context) throws Error { public Feature toFeature(MathContext context) throws Error {
// TODO Auto-generated method stub return new FeatureVariable(ch, type);
return null;
} }
} }

View File

@ -93,7 +93,8 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
public Block getSelectedBlock() { public Block getSelectedBlock() {
caret.resetRemaining(); caret.resetRemaining();
return root.getBlock(caret); Block selectedBlock = root.getBlock(caret);
return selectedBlock;
} }
public void moveLeft() { public void moveLeft() {

View File

@ -14,47 +14,89 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public abstract class OutputContainer implements GraphicalElement, OutputLayout, Serializable { public abstract class OutputContainer implements GraphicalElement, OutputLayout, Serializable {
private static final long serialVersionUID = -5714825964892683571L; private static final long serialVersionUID = -5714825964892683571L;
public final BlockContainer root; public final ObjectArrayList<BlockContainer> roots;
private final Caret caret = new Caret(CaretState.HIDDEN, 0); private final Caret caret = new Caret(CaretState.HIDDEN, 0);
public OutputContainer() { public OutputContainer() {
root = new BlockContainer(); roots = new ObjectArrayList<>();
roots.add(new BlockContainer());
} }
public OutputContainer(boolean small) { public OutputContainer(boolean small) {
root = new BlockContainer(small); roots = new ObjectArrayList<>();
roots.add(new BlockContainer(small));
} }
public OutputContainer(boolean small, int minWidth, int minHeight) { public OutputContainer(boolean small, int minWidth, int minHeight) {
root = new BlockContainer(small); roots = new ObjectArrayList<>();
roots.add(new BlockContainer(small));
} }
public void setContent(ObjectArrayList<Block> blocks) { public void setContentAsSingleGroup(ObjectArrayList<Block> blocks) {
root.clear(); roots.clear();
for (Block b : blocks) { BlockContainer bcnt = new BlockContainer();
root.appendBlockUnsafe(b); for (Block block : blocks) {
bcnt.appendBlockUnsafe(block);
}
roots.add(bcnt);
recomputeDimensions();
}
public void setContentAsMultipleGroups(ObjectArrayList<ObjectArrayList<Block>> roots) {
this.roots.clear();
for (ObjectArrayList<Block> blocks : roots) {
BlockContainer bcnt = new BlockContainer();
for (Block block : blocks) {
bcnt.appendBlockUnsafe(block);
}
this.roots.add(bcnt);
}
recomputeDimensions();
}
public void setContentAsMultipleElements(ObjectArrayList<Block> elems) {
this.roots.clear();
for (Block block : elems) {
BlockContainer bcnt = new BlockContainer();
bcnt.appendBlockUnsafe(block);
this.roots.add(bcnt);
} }
recomputeDimensions(); recomputeDimensions();
} }
@Override @Override
public void recomputeDimensions() { public void recomputeDimensions() {
for (BlockContainer root : roots) {
root.recomputeDimensions(); root.recomputeDimensions();
} }
}
@Override @Override
public int getWidth() { public int getWidth() {
return root.getWidth(); int maxw = 0;
for (BlockContainer root : roots) {
int w = root.getWidth();
if (w > maxw) maxw = w;
}
return maxw;
} }
@Override @Override
public int getHeight() { public int getHeight() {
return root.getHeight(); int h = 0;
for (BlockContainer root : roots) {
h+=root.getHeight()+2;
}
if (h > 0) {
return h-2;
} else {
return h;
}
} }
@Override @Override
public int getLine() { public int getLine() {
return root.getLine(); return 0;
} }
/** /**
@ -78,11 +120,26 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
* Position relative to the window. * Position relative to the window.
*/ */
public void draw(GraphicEngine ge, Renderer r, int x, int y) { public void draw(GraphicEngine ge, Renderer r, int x, int y) {
root.draw(ge, r, x, y, caret); int offset = 0;
for (BlockContainer root : roots) {
root.draw(ge, r, x, y+offset, caret);
offset+=root.getHeight()+2;
}
} }
public void clear() { public void clear() {
root.clear(); roots.clear();
roots.add(new BlockContainer());
recomputeDimensions(); recomputeDimensions();
} }
public boolean isContentEmpty() {
for(BlockContainer root : roots) {
ObjectArrayList<Block> cnt = root.getContent();
if (cnt != null && !cnt.isEmpty()) {
return false;
}
}
return true;
}
} }

View File

@ -1,5 +1,4 @@
package org.warp.picalculator.gui.expression.containers; package org.warp.picalculator.gui.expression.containers;
public interface OutputLayout { public interface OutputLayout {
} }

View File

@ -115,7 +115,7 @@ public class MathInputScreen extends Screen {
userInput.draw(DisplayManager.engine, DisplayManager.renderer, padding, padding + 20); userInput.draw(DisplayManager.engine, DisplayManager.renderer, padding, padding + 20);
if (!result.root.getContent().isEmpty()) { if (!result.isContentEmpty()) {
result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - result.getWidth() - 2, DisplayManager.engine.getHeight() - result.getHeight() - 2); result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - result.getWidth() - 2, DisplayManager.engine.getHeight() - result.getHeight() - 2);
} }
} }
@ -203,9 +203,42 @@ public class MathInputScreen extends Screen {
calc.f2.clear(); calc.f2.clear();
} }
calc.f.add(expr); calc.f.add(expr);
ObjectArrayList<Function> resultExpression = expr.solve(); int stop = 0;
ObjectArrayList<Block> resultBlocks = MathParser.parseOutput(calc, resultExpression); boolean done = false;
result.setContent(resultBlocks); ObjectArrayList<ObjectArrayList<Function>> resultExpressions = new ObjectArrayList<>();
resultExpressions.add(new ObjectArrayList<Function>(expr.getParameters()));
while (!done && stop < 3000) {
ObjectArrayList<ObjectArrayList<Function>> newResultExpressions = new ObjectArrayList<>();
done = true;
for (ObjectArrayList<Function> resultExpr : resultExpressions) {
ObjectArrayList<Function> newResults = new ObjectArrayList<>();
for (Function f : resultExpr) {
if (f.isSimplified() == false) {
done = false;
if (f instanceof Expression) {
ObjectArrayList<Function> fncResult = ((Expression)f).solve();
for (Function resultItem : fncResult) {
newResultExpressions.add(new ObjectArrayList<Function>(new Function[] {resultItem}));
}
} else {
List<Function> fncResult = f.simplify();
for (Function resultItem : fncResult) {
newResultExpressions.add(new ObjectArrayList<Function>(new Function[] {resultItem}));
}
}
} else {
newResults.add(f);
}
}
if (newResults.isEmpty() == false) {
newResultExpressions.add(newResults);
}
}
resultExpressions = newResultExpressions;
stop++;
}
ObjectArrayList<ObjectArrayList<Block>> resultBlocks = MathParser.parseOutput(calc, resultExpressions);
result.setContentAsMultipleGroups(resultBlocks);
// showVariablesDialog(() -> { // showVariablesDialog(() -> {
// currentExpression = newExpression; // currentExpression = newExpression;
// simplify(); // simplify();

View File

@ -0,0 +1,22 @@
package org.warp.picalculator.math.parser;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Subtraction;
import org.warp.picalculator.math.parser.features.FeatureDoubleImpl;
import org.warp.picalculator.math.parser.features.interfaces.Feature;
import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble;
public class FeatureSubtraction extends FeatureDoubleImpl {
public FeatureSubtraction(Object child1, Object child2) {
super(child1, child2);
}
@Override
public Function toFunction(MathContext context) throws Error {
return new Subtraction(context, getFunction1(), getFunction2());
}
}

View File

@ -0,0 +1,21 @@
package org.warp.picalculator.math.parser;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.SumSubtraction;
import org.warp.picalculator.math.parser.features.FeatureDoubleImpl;
import org.warp.picalculator.math.parser.features.interfaces.Feature;
public class FeatureSumSubtraction extends FeatureDoubleImpl {
public FeatureSumSubtraction(Object child1, Object child2) {
super(child1, child2);
}
@Override
public SumSubtraction toFunction(MathContext context) throws Error {
return new SumSubtraction(context, getFunction1(), getFunction2());
}
}

View File

@ -32,7 +32,7 @@ import org.warp.picalculator.math.parser.features.FeatureDivision;
import org.warp.picalculator.math.parser.features.FeatureMultiplication; import org.warp.picalculator.math.parser.features.FeatureMultiplication;
import org.warp.picalculator.math.parser.features.FeatureNumber; import org.warp.picalculator.math.parser.features.FeatureNumber;
import org.warp.picalculator.math.parser.features.FeatureParenthesis; import org.warp.picalculator.math.parser.features.FeatureParenthesis;
import org.warp.picalculator.math.parser.features.FeaturePower; import org.warp.picalculator.math.parser.features.FeaturePowerChar;
import org.warp.picalculator.math.parser.features.FeatureSquareRoot; import org.warp.picalculator.math.parser.features.FeatureSquareRoot;
import org.warp.picalculator.math.parser.features.FeatureSum; import org.warp.picalculator.math.parser.features.FeatureSum;
import org.warp.picalculator.math.parser.features.FeatureVariable; import org.warp.picalculator.math.parser.features.FeatureVariable;
@ -55,23 +55,31 @@ public class MathParser {
return result; return result;
} }
public static ObjectArrayList<Block> parseOutput(MathContext context, ObjectArrayList<Function> expr) throws Error { public static ObjectArrayList<ObjectArrayList<Block>> parseOutput(MathContext context, ObjectArrayList<ObjectArrayList<Function>> resultExpressions) throws Error {
final ObjectArrayList<ObjectArrayList<Block>> result = new ObjectArrayList<>();
for (ObjectArrayList<Function> resultExpression : resultExpressions) {
final ObjectArrayList<Block> resultBlocks = new ObjectArrayList<>(); final ObjectArrayList<Block> resultBlocks = new ObjectArrayList<>();
for (Function f : resultExpression) {
for (Function f : expr) {
ObjectArrayList<Block> resultPart = f.toBlock(context); ObjectArrayList<Block> resultPart = f.toBlock(context);
if (resultPart == null) throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + f.getClass().getSimpleName()); if (resultPart == null) throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + f.getClass().getSimpleName());
resultBlocks.addAll(resultPart); resultBlocks.addAll(resultPart);
} }
result.add(resultBlocks);
return resultBlocks; }
return result;
} }
public static Function joinFeatures(final MathContext context, ObjectArrayList<Feature> features) throws Error { public static Function joinFeatures(final MathContext context, ObjectArrayList<Feature> features) throws Error {
features = fixFeatures(context, features); features = fixFeatures(context, features);
final ObjectArrayList<Function> process = makeFunctions(context, features); final ObjectArrayList<Function> process = new ObjectArrayList<>();
for (final Feature f : features) {
Function fnc = f.toFunction(context);
if (fnc == null) throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
process.add(fnc);
}
fixStack(context, process); fixStack(context, process);
@ -197,46 +205,6 @@ public class MathParser {
} while (lastLoopDidSomething); } while (lastLoopDidSomething);
} }
private static ObjectArrayList<Function> makeFunctions(MathContext context, ObjectArrayList<Feature> features)
throws Error {
final ObjectArrayList<Function> process = new ObjectArrayList<>();
for (final Feature f : features) {
if (f instanceof FeatureDivision) {
process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
} else if (f instanceof FeatureMultiplication) {
process.add(new Multiplication(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
} else if (f instanceof FeatureVariable) {
process.add(new Variable(context, ((FeatureVariable) f).ch, ((FeatureVariable) f).varType));
} else if (f instanceof FeatureSum) {
process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
} else if (f instanceof FeaturePower) {
if (process.isEmpty()) {
throw new Error(Errors.SYNTAX_ERROR, "There is a power at the beginning of the expression!");
} else {
Function prec = process.remove(process.size()-1);
process.add(new Power(context, prec, (Function) ((FeatureSingle) f).getChild()));
}
} else if (f instanceof FeatureSquareRoot) {
process.add(new RootSquare(context, (Function) ((FeatureSingle) f).getChild()));
} else if (f instanceof FeatureParenthesis) {
process.add(new Expression(context, (Function) ((FeatureSingle) f).getChild()));
// } else if (f instanceof FeatureSubtraction) {
// process.add(new Subtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
// } else if (f instanceof FeatureSumSubtraction) {
// process.add(new SumSubtraction(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
} else if (f instanceof FeatureNumber) {
process.add(new Number(context, ((FeatureNumber) f).getNumberString()));
} else if (f instanceof FeatureChar) {
//All the char features must have been changed already before
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
} else {
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
}
}
return process;
}
private static ObjectArrayList<Feature> fixFeatures(final MathContext context, ObjectArrayList<Feature> features) private static ObjectArrayList<Feature> fixFeatures(final MathContext context, ObjectArrayList<Feature> features)
throws Error { throws Error {
@ -268,6 +236,12 @@ public class MathParser {
case MathematicalSymbols.SUM: case MathematicalSymbols.SUM:
result = new FeatureSum(null, null); result = new FeatureSum(null, null);
break; break;
case MathematicalSymbols.SUM_SUBTRACTION:
result = new FeatureSumSubtraction(null, null);
break;
case MathematicalSymbols.SUBTRACTION:
result = new FeatureSubtraction(null, null);
break;
case MathematicalSymbols.MULTIPLICATION: case MathematicalSymbols.MULTIPLICATION:
result = new FeatureMultiplication(null, null); result = new FeatureMultiplication(null, null);
break; break;

View File

@ -1,5 +1,7 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.parser.features.interfaces.Feature; import org.warp.picalculator.math.parser.features.interfaces.Feature;
public class FeatureChar implements Feature { public class FeatureChar implements Feature {
@ -10,4 +12,9 @@ public class FeatureChar implements Feature {
this.ch = ch; this.ch = ch;
} }
@Override
public Function toFunction(MathContext context) {
return null;
}
} }

View File

@ -1,9 +1,18 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Division;
public class FeatureDivision extends FeatureDoubleImpl { public class FeatureDivision extends FeatureDoubleImpl {
public FeatureDivision(Object child1, Object child2) { public FeatureDivision(Object child1, Object child2) {
super(child1, child2); super(child1, child2);
} }
@Override
public Division toFunction(MathContext context) {
return new Division(context, getFunction1(), getFunction2());
}
} }

View File

@ -1,6 +1,7 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble; import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble;
import org.warp.picalculator.math.Function;
public abstract class FeatureDoubleImpl implements FeatureDouble { public abstract class FeatureDoubleImpl implements FeatureDouble {
private Object child_1; private Object child_1;
@ -30,4 +31,12 @@ public abstract class FeatureDoubleImpl implements FeatureDouble {
public void setChild2(Object obj) { public void setChild2(Object obj) {
child_2 = obj; child_2 = obj;
} }
protected Function getFunction1() {
return (Function) child_1;
}
protected Function getFunction2() {
return (Function) child_2;
}
} }

View File

@ -1,9 +1,18 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Multiplication;
public class FeatureMultiplication extends FeatureDoubleImpl { public class FeatureMultiplication extends FeatureDoubleImpl {
public FeatureMultiplication(Object child1, Object child2) { public FeatureMultiplication(Object child1, Object child2) {
super(child1, child2); super(child1, child2);
} }
@Override
public Multiplication toFunction(MathContext context) {
return new Multiplication(context, getFunction1(), getFunction2());
}
} }

View File

@ -1,5 +1,9 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Number;
import org.warp.picalculator.math.parser.features.interfaces.FeatureBasic; import org.warp.picalculator.math.parser.features.interfaces.FeatureBasic;
public class FeatureNumber implements FeatureBasic { public class FeatureNumber implements FeatureBasic {
@ -24,4 +28,9 @@ public class FeatureNumber implements FeatureBasic {
public void append(char ch) { public void append(char ch) {
numberString += ch; numberString += ch;
} }
@Override
public Number toFunction(MathContext context) throws Error {
return new Number(context, getNumberString());
}
} }

View File

@ -1,9 +1,19 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Expression;
public class FeatureParenthesis extends FeatureSingleImpl { public class FeatureParenthesis extends FeatureSingleImpl {
public FeatureParenthesis(Object child) { public FeatureParenthesis(Object child) {
super(child); super(child);
} }
@Override
public Function toFunction(MathContext context) throws Error {
return new Expression(context, this.getFunction1());
}
} }

View File

@ -1,9 +1,18 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
public class FeaturePower extends FeatureSingleImpl { import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Power;
public FeaturePower(Object child) { public class FeaturePower extends FeatureDoubleImpl {
super(child);
public FeaturePower(Object child1, Object child2) {
super(child1, child2);
}
@Override
public Power toFunction(MathContext context) throws Error {
return new Power(context, getFunction1(), getFunction2());
} }
} }

View File

@ -0,0 +1,19 @@
package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Power;
public class FeaturePowerChar extends FeatureSingleImpl {
public FeaturePowerChar(Object child) {
super(child);
}
@Override
public Function toFunction(MathContext context) throws Error {
return null;
}
}

View File

@ -1,5 +1,6 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.parser.features.interfaces.FeatureSingle; import org.warp.picalculator.math.parser.features.interfaces.FeatureSingle;
public abstract class FeatureSingleImpl implements FeatureSingle { public abstract class FeatureSingleImpl implements FeatureSingle {
@ -14,6 +15,10 @@ public abstract class FeatureSingleImpl implements FeatureSingle {
return child; return child;
} }
protected Function getFunction1() {
return (Function) child;
}
@Override @Override
public void setChild(Object obj) { public void setChild(Object obj) {
child = obj; child = obj;

View File

@ -1,9 +1,18 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.RootSquare;
public class FeatureSquareRoot extends FeatureSingleImpl { public class FeatureSquareRoot extends FeatureSingleImpl {
public FeatureSquareRoot(Object child) { public FeatureSquareRoot(Object child) {
super(child); super(child);
} }
@Override
public RootSquare toFunction(MathContext context) throws Error {
return new RootSquare(context, getFunction1());
}
} }

View File

@ -1,9 +1,18 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Sum;
public class FeatureSum extends FeatureDoubleImpl { public class FeatureSum extends FeatureDoubleImpl {
public FeatureSum(Object child1, Object child2) { public FeatureSum(Object child1, Object child2) {
super(child1, child2); super(child1, child2);
} }
@Override
public Sum toFunction(MathContext context) throws Error {
return new Sum(context, getFunction1(), getFunction2());
}
} }

View File

@ -1,5 +1,8 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.functions.Variable;
import org.warp.picalculator.math.functions.Variable.V_TYPE; import org.warp.picalculator.math.functions.Variable.V_TYPE;
public class FeatureVariable extends FeatureChar { public class FeatureVariable extends FeatureChar {
@ -11,4 +14,8 @@ public class FeatureVariable extends FeatureChar {
this.varType = varType; this.varType = varType;
} }
@Override
public Function toFunction(MathContext context) {
return new Variable(context, ch, varType);
}
} }

View File

@ -1,5 +1,11 @@
package org.warp.picalculator.math.parser.features.interfaces; package org.warp.picalculator.math.parser.features.interfaces;
import org.warp.picalculator.Error;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
public abstract interface Feature { public abstract interface Feature {
public Function toFunction(MathContext context) throws Error;
} }