rayon = r;
}
- void dessiner(Piletransformations pile) {
-
+ public void dessiner(Piletransformations pile) {
+ String className = this.getClass().getSimpleName();
+ Point pTrans = pile.getCurrentTransformation();
+ Point pOriTrans = pOri.additionner(pTrans);
+ System.out.println(className + " " + pOri.toString() + "->" + pOriTrans.toString() + " " + rayon);
}
- void deplacer(Point p) {
-
+ public void deplacer(Point p) {
+ pOri = pOri.additionner(p);
}
-
+
}
public static void main(String[] args) {
+ Point p1 = new Point(1, 2);
+ Point p2 = new Point(2, 7);
+ Point p3 = p1.additionner(p2);
+
+ System.out.println(p1.toString());
+ System.out.println(p2.toString());
+ System.out.println(p3.toString());
+
+ Point p4 = new Point(4, 5);
+ Point p5 = new Point(2, 3);
+ Segment segment = new Segment(p4, p5);
+ Cercle cercle = new Cercle(p4, 5.2);
+
+ Piletransformations trans = new Piletransformations(10);
+ trans.display();
+
+ segment.dessiner(trans);
+ cercle.dessiner(trans);
+ boolean rt = trans.empiler(p1);
+ trans.display();
+ segment.dessiner(trans);
+ cercle.dessiner(trans);
+ rt = trans.empiler(p2);
+ trans.display();
+ segment.dessiner(trans);
+ cercle.dessiner(trans);
+
+ segment.deplacer(p1);
+ cercle.deplacer(p1);
+ segment.dessiner(trans);
+ cercle.dessiner(trans);
+
}
}
Point.java \
Segment.java \
Cercle.java \
+ Piletransformations.java \
Main.java
#
--- /dev/null
+
+class Piletransformations {
+ private Point[] transformations;
+ private int currentTransformation;
+
+ Piletransformations(int size) {
+ transformations = new Point[size];
+ for (int i = 0; i < transformations.length; i++) {
+ transformations[i] = new Point(0, 0);
+ }
+ currentTransformation = 0;
+ }
+
+ public Point getCurrentTransformation() {
+ if (isEmpty()) {
+ return transformations[currentTransformation];
+ } else {
+ return transformations[currentTransformation - 1];
+ }
+ }
+
+ private boolean isEmpty() {
+ return (currentTransformation == 0);
+ }
+
+ private boolean isFull() {
+ return (currentTransformation >= transformations.length);
+ }
+
+ public boolean empiler(Point p) {
+ boolean rtVal = false;
+ if (isEmpty()) {
+ transformations[currentTransformation] = p;
+ currentTransformation++;
+ rtVal = true;
+ } else if (!isFull()) {
+ transformations[currentTransformation] = transformations[currentTransformation - 1].additionner(p);
+ currentTransformation++;
+ rtVal = true;
+ }
+ return rtVal;
+ }
+
+ public Point depiler() {
+ if(!isEmpty()) {
+ currentTransformation--;
+ return transformations[currentTransformation];
+ } else {
+ return transformations[currentTransformation];
+ }
+ }
+
+ public void display() {
+ System.out.println("----");
+ for (int i = 0; i < transformations.length; i++) {
+ System.out.println(transformations[i].toString());
+ }
+ }
+
+}
private double y;
Point() {
+ /*
+ * FIXME: init to (0,0)?
+ */
}
Point (double x, double y) {
return y;
}
- public Point additionner(Point p1) {
- return new Point(p1.getX() + getX(), p1.getY() + getX());
+ public Point additionner(Point p) {
+ Point pNew = new Point(p.getX() + getX(), p.getY() + getY());
+ return pNew;
}
public String toString() {
pDest = pD;
}
- void dessiner(Piletransformations pile) {
-
+ public void dessiner(Piletransformations pile) {
+ String className = this.getClass().getSimpleName();
+ Point pTrans = pile.getCurrentTransformation();
+ Point pOriTrans = pOri.additionner(pTrans);
+ Point pDestTrans = pDest.additionner(pTrans);
+ System.out.println(className + " " + pOri.toString()+ "->" + pOriTrans.toString() + " " + pDest.toString() + "->" + pDestTrans.toString());
}
- void deplacer(Point p) {
-
+ public void deplacer(Point p) {
+ pOri = pOri.additionner(p);
+ pDest = pDest.additionner(p);
}
}