/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Capitulo_6.Dibujo2;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author calderon
 */

public class Cuadro implements Figura{
    private int x0, y0, x1, y1;
    Color c;

    @Override
    public void set(int x0, int y0, int x1, int y1, Color c) {
        int dx;
        
        this.x0 = x0;
        this.y0 = y0;
        this.x1 = x1;
        this.y1 = y1;
        
        dx = Math.abs(x0 - x1) > Math.abs(y0-y1) ? Math.abs(x0 - x1) : Math.abs(y0 - y1);  

               
        if(this.x0 > this.x1) {  
            this.x1 = this.x0;
            this.x0 = this.x1 -dx;
        }
        else
            this.x1 = this.x0 + dx;
        
        if(this.y0 > this.y1) {
            this.y1 = this.y0;
            this.y0 = this.y1 -dx;
        }
        else
            this.y1 = this.y0 + dx;

              
        this.c = c;        
    }

    @Override
    public void dibuja(Graphics g) {
        g.setColor(c);
        g.drawRect(x0, y0, Math.abs(x0-x1), Math.abs(y0-y1));
    }    
}    