public Point2D testHandles(double x, double y, Shape selected, double scale) {

		if (selected instanceof Line) {

			Line line = (Line) selected;

			if ((x - line.getX1()) * (x - line.getX1()) + (y - line.getY1())
					* (y - line.getY1()) <= (3 / scale) * (3 / scale)) {

				double x1 = line.getX1();
				double y1 = line.getY1();
				line.setX1(line.getX2());
				line.setY1(line.getY2());
				line.setX2(x1);
				line.setY2(y1);

				return new Point2D.Double(line.getX2(), line.getY2());
			} else if ((x - line.getX2()) * (x - line.getX2())
					+ (y - line.getY2()) * (y - line.getY2()) <= (3 / scale)
					* (3 / scale)) {
				return new Point2D.Double(line.getX2(), line.getY2());
			}
		}

		Point2D point = Transformation.worldToObject(selected, x, y);
		x = point.getX();
		y = point.getY();

		if (selected instanceof Square) {

			Square square = (Square) selected;

			if ((x + square.getSize() / 2) * (x + square.getSize() / 2)
					+ (y + square.getSize() / 2) * (y + square.getSize() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(square,
						square.getSize() / 2, square.getSize() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x - square.getSize() / 2) * (x - square.getSize() / 2)
					+ (y + square.getSize() / 2) * (y + square.getSize() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(square,
						-square.getSize() / 2, square.getSize() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x + square.getSize() / 2) * (x + square.getSize() / 2)
					+ (y - square.getSize() / 2) * (y - square.getSize() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(square,
						square.getSize() / 2, -square.getSize() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x - square.getSize() / 2) * (x - square.getSize() / 2)
					+ (y - square.getSize() / 2) * (y - square.getSize() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(square,
						-square.getSize() / 2, -square.getSize() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			}
		} else if (selected instanceof Rectangle) {

			Rectangle rectangle = (Rectangle) selected;

			if ((x + rectangle.getWidth() / 2) * (x + rectangle.getWidth() / 2)
					+ (y + rectangle.getHeight() / 2)
					* (y + rectangle.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {

				Point2D world = Transformation.objectToWorld(rectangle,
						rectangle.getWidth() / 2, rectangle.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x - rectangle.getWidth() / 2)
					* (x - rectangle.getWidth() / 2)
					+ (y + rectangle.getHeight() / 2)
					* (y + rectangle.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(rectangle,
						-rectangle.getWidth() / 2, rectangle.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x + rectangle.getWidth() / 2)
					* (x + rectangle.getWidth() / 2)
					+ (y - rectangle.getHeight() / 2)
					* (y - rectangle.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(rectangle,
						rectangle.getWidth() / 2, -rectangle.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x - rectangle.getWidth() / 2)
					* (x - rectangle.getWidth() / 2)
					+ (y - rectangle.getHeight() / 2)
					* (y - rectangle.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(rectangle,
						-rectangle.getWidth() / 2, -rectangle.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			}
		} else if (selected instanceof Circle) {

			Circle circle = (Circle) selected;

			if ((x + circle.getRadius()) * (x + circle.getRadius())
					+ (y + circle.getRadius()) * (y + circle.getRadius()) <= (3 / scale)
					* (3 / scale)) {
				return new Point2D.Double(selected.getX() + circle.getRadius(),
						selected.getY() + circle.getRadius());
			} else if ((x - circle.getRadius()) * (x - circle.getRadius())
					+ (y + circle.getRadius()) * (y + circle.getRadius()) <= (3 / scale)
					* (3 / scale)) {
				return new Point2D.Double(selected.getX() - circle.getRadius(),
						selected.getY() + circle.getRadius());
			} else if ((x + circle.getRadius()) * (x + circle.getRadius())
					+ (y - circle.getRadius()) * (y - circle.getRadius()) <= (3 / scale)
					* (3 / scale)) {
				return new Point2D.Double(selected.getX() + circle.getRadius(),
						selected.getY() - circle.getRadius());
			} else if ((x - circle.getRadius()) * (x - circle.getRadius())
					+ (y - circle.getRadius()) * (y - circle.getRadius()) <= (3 / scale)
					* (3 / scale)) {
				return new Point2D.Double(selected.getX() - circle.getRadius(),
						selected.getY() - circle.getRadius());
			}
		} else if (selected instanceof Ellipse) {

			Ellipse ellipse = (Ellipse) selected;

			if ((x + ellipse.getWidth() / 2) * (x + ellipse.getWidth() / 2)
					+ (y + ellipse.getHeight() / 2)
					* (y + ellipse.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(ellipse,
						ellipse.getWidth() / 2, ellipse.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x - ellipse.getWidth() / 2)
					* (x - ellipse.getWidth() / 2)
					+ (y + ellipse.getHeight() / 2)
					* (y + ellipse.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(ellipse,
						-ellipse.getWidth() / 2, ellipse.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x + ellipse.getWidth() / 2)
					* (x + ellipse.getWidth() / 2)
					+ (y - ellipse.getHeight() / 2)
					* (y - ellipse.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(ellipse,
						ellipse.getWidth() / 2, -ellipse.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			} else if ((x - ellipse.getWidth() / 2)
					* (x - ellipse.getWidth() / 2)
					+ (y - ellipse.getHeight() / 2)
					* (y - ellipse.getHeight() / 2) <= (3 / scale)
					* (3 / scale)) {
				Point2D world = Transformation.objectToWorld(ellipse,
						-ellipse.getWidth() / 2, -ellipse.getHeight() / 2);
				return new Point2D.Double(world.getX(), world.getY());
			}
		} else if (selected instanceof Triangle) {

			Triangle triangle = (Triangle) selected;

			if ((x - triangle.getX1()) * (x - triangle.getX1())
					+ (y - triangle.getY1()) * (y - triangle.getY1()) <= (3 / scale)
					* (3 / scale)) {
				triangle.setCornerSelected(0);
				return new Point2D.Double(triangle.getX1(), triangle.getY1());
			} else if ((x - triangle.getX2()) * (x - triangle.getX2())
					+ (y - triangle.getY2()) * (y - triangle.getY2()) <= (3 / scale)
					* (3 / scale)) {
				triangle.setCornerSelected(1);
				return new Point2D.Double(triangle.getX2(), triangle.getY2());
			} else if ((x - triangle.getX3()) * (x - triangle.getX3())
					+ (y - triangle.getY3()) * (y - triangle.getY3()) <= (3 / scale)
					* (3 / scale)) {
				triangle.setCornerSelected(2);
				return new Point2D.Double(triangle.getX3(), triangle.getY3());
			}
		}

		return null;
	}