/**
 * Projet: PaintRevolution
 * <p>Title:UnRectangle.java </p>
 * <p>Description:Classe qui instancie un objet de type UnRectangle </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Societe: IUT NANCY CHARLEMAGNE II</p>
 * @author VIGNERON GEOFFROY && GANGANELLI DORIAN
 * @version 3.0
 */


public class UnRectangle extends UnQuadrilatere {

  /**
   * Constructeur de la classe qui initialise les points représentant
   * les sommets de la figure.
   */
  public UnRectangle() {
    tab_mem = new UnPoint[4];
    tab_mem[0] = new UnPoint( (int)(Math.random()*600) , (int)(Math.random()*600) );
    tab_mem[2] = new UnPoint( (int)(Math.random()*600) , (int)(Math.random()*600) );
    UnPoint p3 = new UnPoint( tab_mem[2].rendreX() , tab_mem[0].rendreY() );
    UnPoint p4 = new UnPoint( tab_mem[0].rendreX() , tab_mem[2].rendreY() );
    tab_mem[1] = p3;
    tab_mem[3] = p4;
  }

  /**
   * Constructeur intermédiaire qui crée un petit rectangle de 40x40 pixels, exclusivement destiné
   * à la manipulation de l'un des points fondamentaux d'une figure. Ce rectangle sera supprimé
   * une fois la manipulation terminée avec la souris.
   * @param p point fondamental auquel sera associé le rectangle
   */
  public UnRectangle(UnPoint p){
    tab_mem = new UnPoint[4];
    tab_mem[0] = new UnPoint( p.rendreX() -20, p.rendreY() +20 );
    tab_mem[2] = new UnPoint( p.rendreX() +20, p.rendreY() -20 );
    UnPoint p3 = new UnPoint( tab_mem[2].rendreX() , tab_mem[0].rendreY() );
    UnPoint p4 = new UnPoint( tab_mem[0].rendreX() , tab_mem[2].rendreY() );
    tab_mem[1] = p3;
    tab_mem[3] = p4;
  }

  /**
   * Méthode qui permet de récupérer le nombre de point fondamentaux nécessaires pour construire
   * un le rectangle, c'est à dire le nombre de points de saisie.
   * @return un entier représentant ce nombre de point
   */
  public int nbPoints(){
    return 2;
  }

  /**
   * Méthode qui permet de modifier les points d'une figure
   * @param tab_saisie tableau contenant les nouveaux points
   */
  public void modifierPoints( UnPoint[] tab_saisie ){
    if (tab_saisie.length == 2) {
      tab_mem[0] = tab_saisie[0];
      tab_mem[2] = tab_saisie[1];
      tab_mem[1] = new UnPoint( tab_mem[2].rendreX() , tab_mem[0].rendreY() );
      tab_mem[3] = new UnPoint( tab_mem[0].rendreX() , tab_mem[2].rendreY() );
    }
  }

}
