package math.geometry;

import math.matrix.Vector2D;

/**
 * Work with rectangles.
 * As a specialization of {@link Tetragon Tetragon class}
 * 
 * @author Daniel Weschke
 *
 */
public class Rectangle extends Tetragon{
	
	/**
	 * Create empty rectangle.
	 */
	public Rectangle(){
		super();
	}
	
	/**
	 * Create rectangle with given length and width.  
	 * @param l length (x)
	 * @param w width (y)
	 */
	public Rectangle(double l, double w){
		polygon.set(1, new Point2D(l,0));
		polygon.set(2, new Point2D(l,w));
		polygon.set(3, new Point2D(0,w));		
	}
	
	/** 
	 * Create rectangle by a vector and orthogonal width.
	 * @param v vector through origin as directed length
	 * @param w orthogonal width
	 */
	public Rectangle(Vector2D v, double w){
		polygon.set(1, (Point2D) get(1).displace(v));
		polygon.set(2, (Point2D) get(1).displace(v.orthogonalScalarMultiplication(w)));
		polygon.set(3, (Point2D) get(3).displace(v.orthogonalScalarMultiplication(w)));
	}
	
	/**
	 * Positioned rectangle created by vector as directed length and orthogonal width. 
	 * @param p position / point
	 * @param v vector as directed length
	 * @param w orthogonal width
	 */
	public Rectangle(Point2D p, Vector2D v, double w){
		polygon.set(0, p);
		polygon.set(1, (Point2D) p.displace(v));
		polygon.set(2, (Point2D) get(1).displace(v.orthogonalScalarMultiplication(w)));
		polygon.set(3, (Point2D) p.displace(v.orthogonalScalarMultiplication(w)));
	}
}
