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 1/1 (revert to my Android Calculator App)
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 26, 2024
1 parent 292eb51 commit 1a33127
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ public AlgebraicFormulaSyntaxException(Tree algebraicTree) {

public AlgebraicFormulaSyntaxException(String s, AlgebraicTree algebraicTree) {
this(s);
///System.err.println(algebricTree);
System.err.println(algebraicTree);
}
}
35 changes: 34 additions & 1 deletion src/main/java/one/empty3/library1/tree/AlgebraicTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,40 @@ public boolean addFunctionDefinition(TreeNode t, String values)
return false;
}

public boolean addFunctionBody(TreeNode t2, String substring) {
public boolean addFunctionBody(TreeNode src, String values) {

TreeNode tBraced;
int i = 0;
int count = 0;
while (i < values.length()) {
values = addSpaces(values, i);
if (i >= values.length())
break;
if (values.charAt(i) == ')') {
count--;
} else if (values.charAt(i) == '(') {
count++;
} else if (i < 1)
return false;

if (i == values.length() - 1 && count == 0 && values.charAt(i) == ')') {
String subsubstring = values.substring(1, values.length() - 1);
TreeTreeNodeType mathFunctionTreeNodeType = new TreeTreeNodeType(
subsubstring, parametersValues
);
TreeNode t2 = new TreeNode(src, new Object[]{subsubstring, parametersValues, ""}, mathFunctionTreeNodeType);
try {
if (!add(t2, subsubstring))
return false;
} catch (AlgebraicFormulaSyntaxException e) {
return false;
}
src.getChildren().add(t2);
}


i++;
}
return false;
}

Expand Down
80 changes: 80 additions & 0 deletions src/main/java/one/empty3/library1/tree/Class.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
*
* * Copyright (c) 2024. Manuel Daniel Dahmen
* *
* *
* * Copyright 2024 Manuel Daniel Dahmen
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*
*/

package one.empty3.library1.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Class {
private String name;
private List<Variable> variableList = new ArrayList<>();
private List<Method> methodList = new ArrayList<>();

public Class() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Variable> getVariableList() {
return variableList;
}

public void setVariableList(List<Variable> variableList) {
this.variableList = variableList;
}

public List<Method> getMethodList() {
return methodList;
}

public void setMethodList(List<Method> methodList) {
this.methodList = methodList;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Class aClass = (Class) o;

if (!Objects.equals(variableList, aClass.variableList))
return false;
return Objects.equals(methodList, aClass.methodList);
}

@Override
public int hashCode() {
int result = variableList != null ? variableList.hashCode() : 0;
result = 31 * result + (methodList != null ? methodList.hashCode() : 0);
return result;
}
}
93 changes: 93 additions & 0 deletions src/main/java/one/empty3/library1/tree/Method.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
*
* * Copyright (c) 2024. Manuel Daniel Dahmen
* *
* *
* * Copyright 2024 Manuel Daniel Dahmen
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*
*/

package one.empty3.library1.tree;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Method {
private String name;
private Variable ofClass;
private List<Variable> variableList = new ArrayList<>();
private List<ListInstructions.Instruction> instructions = new ArrayList<>();

public Method() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Variable getOfClass() {
return ofClass;
}

public void setOfClass(Variable ofClass) {
this.ofClass = ofClass;
}

public List<Variable> getVariableList() {
return variableList;
}

public void setVariableList(List<Variable> variableList) {
this.variableList = variableList;
}

public List<ListInstructions.Instruction> getInstructions() {
return instructions;
}

public void setInstructions(List<ListInstructions.Instruction> instructions) {
this.instructions = instructions;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Method method = (Method) o;

if (!Objects.equals(name, method.name)) return false;
if (!Objects.equals(ofClass, method.ofClass)) return false;
if (!Objects.equals(variableList, method.variableList))
return false;
return Objects.equals(instructions, method.instructions);
}

@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (ofClass != null ? ofClass.hashCode() : 0);
result = 31 * result + (variableList != null ? variableList.hashCode() : 0);
result = 31 * result + (instructions != null ? instructions.hashCode() : 0);
return result;
}
}
48 changes: 48 additions & 0 deletions src/main/java/one/empty3/library1/tree/Variable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* * Copyright (c) 2024. Manuel Daniel Dahmen
* *
* *
* * Copyright 2024 Manuel Daniel Dahmen
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*
*/

package one.empty3.library1.tree;

public class Variable {
private String name;
private Class value;

public Variable() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Class getValue() {
return value;
}

public void setValue(Class value) {
this.value = value;
}
}
15 changes: 15 additions & 0 deletions src/test/java/one/empty3/library1/tree/TestAlgebraicTreeVector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,21 @@ class TestAlgebraicTreeVector() {
)
}

@Test
fun testForFunctionWithSpaces() {
val r = 12.0
val vars = HashMap<String, Double>()
vars["r"] = r
val algebraicTree = AlgebraicTree(
"func1(a, b, c) {\n" +
"d = c+b/a\n" +
"\n" +
"}\n"
)
algebraicTree.construct()
algebraicTree.eval()
}

@Test
fun testTextCalculator3() {
val listInstructions: ListInstructions = ListInstructions()
Expand Down

0 comments on commit 1a33127

Please sign in to comment.