I am trying to figure out if a specified point is inside of a rectangle. I am given the center of the rectangle (represented as (x,y)). And also the height and width of the rectangle. I tried a piece of code I found, but I think it's wrong, because the answer is not the way it should be. Here is an example of my code:
bool Rectangle2D::contains(double x, double y) const
{
double pointX = x;
double pointY = y;
// This is the piece of code I found
if (pointX >= this->x && pointX <= this->x + this->width &&
pointY >= this->y && pointY <= this->y + this->height)
returntrue;
elsereturnfalse;
}
I run the contains function, and it returns true if the specified point (x,y) is inside the rectangle. My rectangle is Rectangle2D r1(2, 2, 5.5, 4.9); and the instance function is r1.contains(3, 3). So with that information I have a rectangle with a center at (2,2), height=5.5, width=4.9, and a point at (3,3). Is it inside, upon, or outside?