Ádám Bozzay
Ádám Bozzay

Reputation: 609

Rectangle2D.contains() not working?

new Rectangle2D.Double(0, 2, 4, 2).contains(1, 1)

This gives me false. Why? The point should be inside of the rectangle. Maybe I'm tired and it's probably trivial, but I don't get it.

Upvotes: 0

Views: 783

Answers (2)

BackSlash
BackSlash

Reputation: 22243

You specified:

new Rectangle2D.Double(
    0, //x
    2, //y
    4, //width
    2  //height
);

So, the rectangle will begin at 0,2 and extend to 4,4. 1,1 is outside the rectangle, as the contains method is not relative to the rectangle starting position, but it's based on the absolute coordinates space.

enter image description here

Upvotes: 5

Patricia
Patricia

Reputation: 2865

Rectangle2D.Double(double x, double y, double w, double h)

means that you place the rectangle in Point (0,2) and it extends from there. So it covers not (1,1) because at y it begins at 2.

Upvotes: 2

Related Questions