Skip to content

Commit

Permalink
+ Mesh Editor.
Browse files Browse the repository at this point in the history
#2 ExportAs ok
Improving TreeNode. Addition vectors 0/1
Game works again.
TextDialog in feature processing
Include spaces in AlgebraicTree formulas.

Signed-off-by: Manuel Daniel Dahmen <[email protected]>
  • Loading branch information
manuelddahmen committed Jan 23, 2024
1 parent 68cffe1 commit ae93b29
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
52 changes: 27 additions & 25 deletions src/main/java/one/empty3/library1/tree/ListInstructions.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import one.empty3.library.StructureMatrix;

public class ListInstructions {
HashMap<String, Double> currentParamsValues = new HashMap<>();
HashMap<String, String> currentParamsValuesVec = new HashMap<>();
HashMap<String, StructureMatrix<Double>> currentParamsValuesVecComputed = new HashMap<>();
private HashMap<String, Double> currentParamsValues = new HashMap<>();
private HashMap<String, String> currentParamsValuesVec = new HashMap<>();
private HashMap<String, StructureMatrix<Double>> currentParamsValuesVecComputed = new HashMap<>();

public String evaluate(String s) {
return "";
Expand Down Expand Up @@ -97,7 +97,7 @@ public void addInstructions(@NotNull String toString) {

String text = toString;

String[] splitLines = text.split("\\n");
String[] splitLines = text.split("\n");

for (int i = 0; i < splitLines.length; i++) {

Expand Down Expand Up @@ -157,33 +157,35 @@ public List<String> runInstructions() {
currentParamsValuesVecComputed = new HashMap<>();
int i = 0;
for (Instruction instruction : instructions) {
String key = (String) instruction.getLeftHand();
String value = (String) instruction.getExpression();
String key = (String) instruction.getLeftHand().trim();
String value = (String) instruction.getExpression().trim();


StructureMatrix<Double> resultVec = null;
Double resultDouble = null;
try {
if (value != null) {
AlgebraicTree tree = new AlgebraicTree(value);
tree.setParametersValues(currentParamsValues);
tree.setParametersValuesVec(currentParamsValuesVec);
tree.setParametersValuesVecComputed(currentParamsValuesVecComputed);

tree.construct();

resultVec = tree.eval();

if (resultVec != null) {
if (resultVec.getDim() == 1 && key != null) {
currentParamsValuesVecComputed.put(key, resultVec);
} else if (resultVec.getDim() == 0 && key != null) {
currentParamsValuesVecComputed.put(key, resultVec);
}
} else {
throw new AlgebraicFormulaSyntaxException("Result was null");
AlgebraicTree tree = new AlgebraicTree(value);
tree.setParametersValues(currentParamsValues);
tree.setParametersValuesVec(currentParamsValuesVec);
tree.setParametersValuesVecComputed(currentParamsValuesVecComputed);

tree.construct();

resultVec = tree.eval();

if (resultVec != null) {
System.out.println("key: " + key + " value: " + value + " computed: " + resultVec);
if (resultVec.getDim() == 1) {
currentParamsValuesVecComputed.put(key, resultVec);
currentParamsValuesVec.put(key, value);
} else if (resultVec.getDim() == 0) {
currentParamsValuesVecComputed.put(key, resultVec);
currentParamsValuesVec.put(key, value);
}
//System.err.println("AlgebraicTree result : " + tree);
} else {
throw new AlgebraicFormulaSyntaxException("Result was null");
}
//System.err.println("AlgebraicTree result : " + tree);
} catch (AlgebraicFormulaSyntaxException | TreeNodeEvalException |
NullPointerException e) {
e.printStackTrace();
Expand Down
19 changes: 11 additions & 8 deletions src/test/java/one/empty3/library1/tree/TestAlgebraicTreeVector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,17 @@ class TestAlgebraicTreeVector() {
@Test
fun testTextCalculator3() {
val listInstructions: ListInstructions = ListInstructions()
listInstructions.run {
addInstructions(
"x=(1,2,3)\n"
+ "y=(5,6,7)\n"
+ "z=x+y\n"
)
runInstructions()
}
listInstructions.addInstructions(
"x=(1,2,3)\n"
+ "y=(5,6,7)\n"
+ "z=x+y"
)
println(listInstructions.runInstructions())

println("x: " + listInstructions.getCurrentParamsValuesVecComputed()!!["x"]!!)
println("y: " + listInstructions.getCurrentParamsValuesVecComputed()!!["y"]!!)
println("z: " + listInstructions.getCurrentParamsValuesVecComputed()!!["z"]!!)

var assertion = false
try {
if (listInstructions.getCurrentParamsValuesVecComputed() != null &&
Expand Down

0 comments on commit ae93b29

Please sign in to comment.