public static double angleToRect(Rectangle rect, Point2D p2){
		int side = rect.outcode(p2);
		//Sides
		if (side == Rectangle.OUT_BOTTOM){
			return 90;
		}
		if (side == Rectangle.OUT_LEFT){
			return 180;
		}
		if (side == Rectangle.OUT_TOP){
			return -90;
		}
		if (side == Rectangle.OUT_RIGHT){
			return 0;
		}
		//Corners
		Point2D p = null;
		if (side == (Rectangle.OUT_TOP | Rectangle.OUT_LEFT)){
			p = new Point2D.Double(rect.getMinX(), rect.getMinY());
		}
		if (side == (Rectangle.OUT_TOP| Rectangle.OUT_RIGHT)){
			p = new Point2D.Double(rect.getMaxX(), rect.getMinY());
		}
		if (side == (Rectangle.OUT_BOTTOM | Rectangle.OUT_RIGHT)){
			p = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
		}
		if (side == (Rectangle.OUT_BOTTOM | Rectangle.OUT_LEFT)){
			p = new Point2D.Double(rect.getMinX(), rect.getMaxY());
		}
		if (p == null){
			return 0;
		}
		return AngleMath.adjustAngle(Math.toDegrees(Math.atan2(p.getY()-p2.getY(), p.getX()-p2.getX()))+180);
	}