public boolean intersectsCircle(double pointX, double pointY, double radius) {
        double halfWidth = getWidth() / 2;
        double halfHeight = getHeight() / 2;

        double centerDistanceX = Math.abs(pointX - getCenterX());
        double centerDistanceY = Math.abs(pointY - getCenterY());

        // is the circle is far enough away from the rectangle?
        if (centerDistanceX > halfWidth + radius) {
            return false;
        } else if (centerDistanceY > halfHeight + radius) {
            return false;
        }

        // is the circle close enough to the rectangle?
        if (centerDistanceX <= halfWidth) {
            return true;
        } else if (centerDistanceY <= halfHeight) {
            return true;
        }

        double cornerDistanceX = centerDistanceX - halfWidth;
        double cornerDistanceY = centerDistanceY - halfHeight;
        return cornerDistanceX * cornerDistanceX + cornerDistanceY * cornerDistanceY <= radius * radius;
    }
@Test
    public void intersectsCircleTest() {
        Rectangle rectangle1 = create(1, 2, 3, 4);

        Assert.assertTrue(rectangle1.intersectsCircle(1, 2, 0));
        Assert.assertTrue(rectangle1.intersectsCircle(1, 2, 1));
        Assert.assertTrue(rectangle1.intersectsCircle(1, 2, 10));

        Assert.assertTrue(rectangle1.intersectsCircle(2, 3, 0));
        Assert.assertTrue(rectangle1.intersectsCircle(2, 3, 1));
        Assert.assertTrue(rectangle1.intersectsCircle(2, 3, 10));

        Assert.assertTrue(rectangle1.intersectsCircle(3.5, 4, 0.5));
        Assert.assertTrue(rectangle1.intersectsCircle(3, 4.5, 0.5));

        Assert.assertTrue(rectangle1.intersectsCircle(4, 4, 1));
        Assert.assertTrue(rectangle1.intersectsCircle(4, 4, 10));

        Assert.assertFalse(rectangle1.intersectsCircle(0, 0, 0));
        Assert.assertFalse(rectangle1.intersectsCircle(0, 1, 0));
        Assert.assertFalse(rectangle1.intersectsCircle(0, 1, 1));

        Assert.assertFalse(rectangle1.intersectsCircle(3.5, 4, 0.49999));
        Assert.assertFalse(rectangle1.intersectsCircle(3, 4.5, 0.49999));

        Assert.assertFalse(rectangle1.intersectsCircle(4, 5, 1));
        Assert.assertFalse(rectangle1.intersectsCircle(4, 5, 1.4));
    }