package model;

import java.awt.geom.Point2D;

/**
 * Represents a Rectangle.
 * @author florian
 */
public class Rectangle {
	private Point2D.Double topleft;
	private double width;
	private double height;
	
	/**
	 * Creates a rectangle with the following parameters:
	 * @param topleft The point to the top left of the rectangle.
	 * @param width The width of the rectangle.
	 * @param height The height of the rectangle.
	 */
	public Rectangle(Point2D.Double topleft, double width, double height){
		this.topleft = topleft;
		this.width = width;
		this.height = height;
	}
	
	/**
	 * Creates a rectangle with the following parameters:
	 * @param topY The y-coordinate of the top left point of the rectangle.
	 * @param leftX The x-coordinate of the top left point of the rectangle.
	 * @param width The width of the rectangle.
	 * @param height The height of the rectangle.
	 */
	public Rectangle(double topY, double leftX, double width, double height){
		this.topleft = new Point2D.Double(leftX, topY);
		this.width = width;
		this.height = height;
	}
	
	/**
	 * Checks two rectangles on whether or not they do collide.
	 * @param r1 The first rectangle to check.
	 * @param r2 The second rectangle to check.
	 * @return true if and only if the rectangles do collide.
	 */
	public static boolean collide(Rectangle r1, Rectangle r2){
		if(r1.height + r1.topleft.y < r2.topleft.y)
			return false;
		if(r2.height + r2.topleft.y < r1.topleft.y)
			return false;
		if(r1.width + r1.topleft.x < r2.topleft.x)
			return false;
		if(r2.width + r2.topleft.x < r1.topleft.x)
			return false;
		return true;
	}
	
	/**
	 * Checks if this rectangle does collide with the specified other rectangle r.
	 * @param r The rectangle to check.
	 * @return true if and only if the rectangles do collide.
	 */
	public boolean collidesWith(Rectangle r){
		return collide(this, r);
	}
}

@@ -139,27 +139,27 @@
 nt2D.Double 
-top
+bot
 left;%0A%09priva
@@ -272,19 +272,19 @@
  @param 
-top
+bot
 left The
@@ -293,27 +293,30 @@
 oint to the 
+bot
 to
-p
+m
  left of the
@@ -457,19 +457,19 @@
 .Double 
-top
+bot
 left, do
@@ -507,21 +507,21 @@
 his.
-top
+bot
 left = 
-top
+bot
 left
@@ -665,35 +665,38 @@
 ordinate of the 
+bot
 to
-p
+m
  left point of t
@@ -750,19 +750,22 @@
  of the 
+bot
 to
-p
+m
  left po
@@ -965,19 +965,19 @@
 %0A%09%09this.
-top
+bot
 left = n
@@ -1354,27 +1354,27 @@
 height + r1.
-top
+bot
 left.y %3C r2.
@@ -1369,27 +1369,27 @@
 left.y %3C r2.
-top
+bot
 left.y)%0A%09%09%09r
@@ -1417,27 +1417,27 @@
 height + r2.
-top
+bot
 left.y %3C r1.
@@ -1432,27 +1432,27 @@
 left.y %3C r1.
-top
+bot
 left.y)%0A%09%09%09r
@@ -1479,27 +1479,27 @@
 .width + r1.
-top
+bot
 left.x %3C r2.
@@ -1494,27 +1494,27 @@
 left.x %3C r2.
-top
+bot
 left.x)%0A%09%09%09r
@@ -1545,19 +1545,19 @@
 th + r2.
-top
+bot
 left.x %3C
@@ -1560,19 +1560,19 @@
 .x %3C r1.
-top
+bot
 left.x)%0A

Change anchor point of rectangles