01 package fr.isae.geometry.api;
02
03 import java.util.Observable;
04 import java.util.Observer;
05
06 /**
07 * <code>Cercle</code> est une classe permettant de modeliser un
08 * cercle. Le cercle est composé de deux points.
09 *
10 * @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
11 * @version 1.0
12 */
13 public class Cercle implements Observer {
14
15 private Point centre;
16 private Point periph;
17 private double rayon;
18
19 /**
20 * Creer une instance de <code>Cercle</code>.
21 *
22 * @param centre un point representant le centre du cercle
23 * @param periph un point sur la peripherie du cercle
24 */
25 public Cercle(Point centre, Point periph) {
26 this.centre = centre;
27 this.centre.addObserver(this);
28 this.periph = periph;
29 this.periph.addObserver(this);
30 this.rayon = this.centre.distance(this.periph);
31 }
32
33 /**
34 * <code>translater</code> permet de translater le cercle.
35 *
36 * @param dx l'abscisse du vecteur de translation
37 * @param dy l'ordonnee du vecteur de translation
38 */
39 public void translater(double dx, double dy) {
40 this.centre.translater(dx, dy);
41 this.periph.translater(dx, dy);
42 }
43
44 /**
45 * <code>afficher</code> permet d'afficher le cercle.
46 */
47 public void afficher() {
48 System.out.println(this);
49 }
50
51 @Override public String toString() {
52 return this.centre + " -- " +
53 this.periph + " r: " +
54 this.rayon;
55 }
56
57 @Override public void update(Observable o, Object arg) {
58 if (o == this.centre) {
59 double[] coordTranslation = (double[]) arg;
60 this.periph.translater(coordTranslation[0],
61 coordTranslation[1]);
62 } else if (o == this.periph) {
63 this.rayon = this.centre.distance(this.periph);
64 }
65 }
66 }
|