add comment to methods in AbstractCanvas.java and fix some
This commit is contained in:
parent
cce32f543b
commit
da67bda3a4
@ -162,7 +162,7 @@ public class Parser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add some pre condition before execute {@link Float#parseFloat(String)} like if {@code number} give a {@code +}
|
* Add some pre condition before execute {@link Float#parseFloat(String)} like if {@code number} give a {@code +}
|
||||||
* or an empty {@link String}, method will return 0.25° and {@code -} will return 0.25°
|
* or an empty {@link String}, method will return 0.25 degrees and {@code -} will return 25 degrees
|
||||||
* @param number the number which will be converted
|
* @param number the number which will be converted
|
||||||
* @return the converted float from {@code number} param
|
* @return the converted float from {@code number} param
|
||||||
* @throws NumberFormatException throw by {@link Float#parseFloat(String)}
|
* @throws NumberFormatException throw by {@link Float#parseFloat(String)}
|
||||||
|
@ -18,15 +18,28 @@ import java.awt.event.WindowAdapter;
|
|||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create an instance of the 3D window
|
||||||
|
*/
|
||||||
public abstract class AbstractCanvas {
|
public abstract class AbstractCanvas {
|
||||||
|
|
||||||
private Element lSystem;
|
private Element lSystem;
|
||||||
|
/**
|
||||||
|
* If value is {@link State#LOAD}, we currently converting the L-System to {@link Element} object
|
||||||
|
* otherwise the value is {@link State#FINISH_OR_NULL} 2 possibility:
|
||||||
|
* we waiting for end-user to give axiom and rules from {@link lsystem.screen.main.MainFrame main window}
|
||||||
|
* or we window is open and user see the representation the L-System in 3D
|
||||||
|
* @see State
|
||||||
|
*/
|
||||||
public State parsedState = State.FINISH_OR_NULL;
|
public State parsedState = State.FINISH_OR_NULL;
|
||||||
public JFrame frame;
|
public JFrame frame;
|
||||||
protected FPSAnimator animator;
|
protected FPSAnimator animator;
|
||||||
public final GLCanvas glCanvas;
|
public final GLCanvas glCanvas;
|
||||||
public GLU glu = new GLU();
|
public GLU glu = new GLU();
|
||||||
public GLUT glut = new GLUT();
|
public GLUT glut = new GLUT();
|
||||||
|
/**
|
||||||
|
* camera position, 6 dimension tab with respectively x, y and z camera pos and yaw, pitch roll camera rotation
|
||||||
|
*/
|
||||||
public float[] camera = {0f, 1f, 5f, // camera pos x,y, z
|
public float[] camera = {0f, 1f, 5f, // camera pos x,y, z
|
||||||
0f, 0f, 0f}; // camera rotation yaw(x-axis), pitch(y-axis), roll(z-axis)
|
0f, 0f, 0f}; // camera rotation yaw(x-axis), pitch(y-axis), roll(z-axis)
|
||||||
|
|
||||||
@ -44,6 +57,9 @@ public abstract class AbstractCanvas {
|
|||||||
setVisible(false);
|
setVisible(false);
|
||||||
lSystem = null;
|
lSystem = null;
|
||||||
parsedState = State.FINISH_OR_NULL;
|
parsedState = State.FINISH_OR_NULL;
|
||||||
|
// after setting lSystem to null, the object can be large (up to 4gb during our tests) and it's stored
|
||||||
|
// long time in memory
|
||||||
|
// the partial gc only clear the object itself and absolutely not all of its children from memory
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -54,6 +70,10 @@ public abstract class AbstractCanvas {
|
|||||||
|
|
||||||
protected abstract void addEventsListeners();
|
protected abstract void addEventsListeners();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if {@code bl} is true, we start the animator and then display the window
|
||||||
|
* @param bl
|
||||||
|
*/
|
||||||
public void setVisible(boolean bl) {
|
public void setVisible(boolean bl) {
|
||||||
if(bl)
|
if(bl)
|
||||||
animator.start();
|
animator.start();
|
||||||
@ -66,12 +86,22 @@ public abstract class AbstractCanvas {
|
|||||||
return lSystem;
|
return lSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get axiom and rule to rewrite and parse it to an {@link Element} object and store it in {@link AbstractCanvas#lSystem}
|
||||||
|
* @param axiom give from {@link lsystem.screen.main.Tab}
|
||||||
|
* @param rules same
|
||||||
|
* @param iterations same
|
||||||
|
* @throws NumberFormatException throw by {@link Float#parseFloat(String)}
|
||||||
|
*/
|
||||||
public void setLSystem(String axiom, List<Pair<String, String>> rules, int iterations) throws NumberFormatException {
|
public void setLSystem(String axiom, List<Pair<String, String>> rules, int iterations) throws NumberFormatException {
|
||||||
parsedState = State.LOAD;
|
parsedState = State.LOAD;
|
||||||
this.lSystem = Parser.parse(Rewrite.rewrite(axiom, rules, iterations));
|
this.lSystem = Parser.parse(Rewrite.rewrite(axiom, rules, iterations));
|
||||||
parsedState = State.FINISH_OR_NULL;
|
parsedState = State.FINISH_OR_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AbstractCanvas#parsedState
|
||||||
|
*/
|
||||||
public enum State {
|
public enum State {
|
||||||
LOAD,
|
LOAD,
|
||||||
FINISH_OR_NULL
|
FINISH_OR_NULL
|
||||||
|
@ -3,10 +3,9 @@ package lsystem.utils;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tuple containing 2 unknown type elements
|
* tuple containing 2 generic type elements
|
||||||
*
|
* @param <U> left side
|
||||||
* @param <U> left
|
* @param <K> right side
|
||||||
* @param <K> right
|
|
||||||
*/
|
*/
|
||||||
public class Pair<U, K> {
|
public class Pair<U, K> {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user