package cse1030.test2;
import cse1030.drawing.Point2D;
/**
* A line shape. Each line is defined by the position of
* its two end points. The bounding box for
* a line is the rectangle with opposite corners located
* at the end points of the line. The line end points
* cannot be changed after the line is created.
*
* @author CSE1030_F13_14
*
*/
public class Line extends Shape {
private Point2D p1;
private Point2D p2;
/**
* Create a line with end points p1
and p2
.
*
* @param p1 one end point of the line
* @param p2 the other end point of the line
*/
public Line(Point2D p1, Point2D p2) {
super();
this.width = Math.abs(p1.getX() - p2.getX());
this.height = Math.abs(p1.getY() - p2.getY());
this.position.setX((p1.getX() + p2.getX()) / 2);
this.position.setY((p1.getY() + p2.getY()) / 2);
this.p1 = new Point2D(p1);
this.p2 = new Point2D(p2);
}
/**
* Returns the first end point of the line.
*
* @return the first end point of the line
*/
public Point2D getPoint1() {
return new Point2D(this.p1);
}
/**
* Returns the second end point of the line.
*
* @return the second end point of the line
*/
public Point2D getPoint2() {
return new Point2D(this.p2);
}
/**
* Returns zero (the area of the line).
*
* @return 0
* @see cse1030.test2.Shape#getArea()
*/
public double getArea() {
return 0.;
}
}