Added jbvm arguments to build.xml + Rewrite.java now an utility class + optimized imports

This commit is contained in:
Quentin Legot 2021-03-09 18:21:13 +01:00
parent 399b7e0fe1
commit dcb4ad767b
6 changed files with 19 additions and 26 deletions

View File

@ -20,6 +20,8 @@
<target name="run" description="execution" depends="compile">
<java classname="lsystem.Main" fork="true">
<jvmarg value="-ea"/>
<jvmarg value="-XX:+UseG1GC"/>
<jvmarg value="-XX:+ParallelRefProcEnabled"/>
<classpath refid="project.classpath"/>
</java>
</target>

View File

@ -79,7 +79,7 @@ public class Parser {
}
/**
* Used by {@link Rewrite#rewrite()}
* Used by {@link Rewrite#rewrite(String, List, int)} )}
* @return a list of rules with the left and right sides separated by a {@link lsystem.utils.Pair Pair}
*/
public List<Pair<String, String>> parseRules() {

View File

@ -6,18 +6,8 @@ import java.util.List;
public class Rewrite {
private final String axiom;
private final List<Pair<String, String >> rules;
private final int recurrences;
public Rewrite(String axiom, List<Pair<String, String>> rules, int recurrences) {
this.axiom = axiom;
this.rules = rules;
this.recurrences = recurrences;
}
private String replaceRulesByID(final String rewritten) {
private static String replaceRulesByID(final String rewritten, List<Pair<String, String>> rules) {
String toRewrite = rewritten;
for(int j = 0; j < rules.size(); ++j){
Pair<String, String> pair = rules.get(j);
@ -26,7 +16,7 @@ public class Rewrite {
return toRewrite;
}
private String replaceIDByRuleApplication(final String toRewrite) {
private static String replaceIDByRuleApplication(final String toRewrite, List<Pair<String, String>> rules) {
String rewritten = toRewrite;
for(int j = 0; j < rules.size(); ++j){
rewritten = rewritten.replace("${" + j + "}", rules.get(j).getRight());
@ -34,11 +24,12 @@ public class Rewrite {
return rewritten;
}
public String rewrite() {
public static String rewrite(String axiom, List<Pair<String, String>> rules, int recurrences) {
String rewritten = axiom;
for(int i = 0; i < recurrences; ++i) {
String toRewrite = replaceRulesByID(rewritten);
rewritten = replaceIDByRuleApplication(toRewrite);
String toRewrite = replaceRulesByID(rewritten, rules);
rewritten = replaceIDByRuleApplication(toRewrite, rules);
System.out.println(i + " / " + recurrences + " : " + rewritten.length());
}
return rewritten.replace("[", "Y[");
}

View File

@ -36,6 +36,7 @@ public abstract class AbstractCanvas {
@Override
public void windowClosing(WindowEvent e) {
frame.dispose();
setVisible(false);
}
});
frame.getContentPane().add(glCanvas, BorderLayout.CENTER);

View File

@ -1,6 +1,5 @@
package lsystem.screen.main;
import lsystem.engine.Element;
import lsystem.engine.Parser;
import lsystem.engine.Rewrite;
import lsystem.screen.gl3d.GLCanvas;
@ -53,14 +52,14 @@ public class Listener implements ActionListener, KeyListener {
JOptionPane.showMessageDialog(null, "Vos règles ou votre axiome ne sont pas correctement écrites, veuillez recommencer");
new Listener(null, index, "Clear",tab);
} else {
new Thread(() -> {
Rewrite rewriter = new Rewrite(axiom, parser.parseRules(), tab.getNbIterations());
final String word = rewriter.rewrite();
System.out.println(word);
final Element parsed = Parser.parse(word);
GLCanvas canvas = new GLCanvas(parsed);
Thread thread = new Thread(() -> {
GLCanvas canvas = new GLCanvas(
Parser.parse(Rewrite.rewrite(axiom, parser.parseRules(), tab.getNbIterations()))
);
canvas.setVisible(true);
}).start();
});
thread.setDaemon(true);
thread.start();
}
break;

View File

@ -29,7 +29,7 @@ public class Tab extends JPanel{
nbIterations.setModel(new SpinnerNumberModel(1, 1, 15, 1));
JLabel itLabel = new JLabel("Nombre d'itérations : ");
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 15, 1));
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
JLabel axiome = new JLabel("Axiome :");