[quote]QUESTION: In this method, why did we have to divide both center.x & center.y by 2.0? I understand that we’re trying to find the center of the point, but the division is confusing me.
The division by 2.0 is necessary to put the point at the center of the rectangle.
To understand this, consider the three cases below (in the rectangular coordinate system):
The point coincides with the the origin:
center.x = bounds.origin.x;
center.y = bounds.origin.y;
The point is at the corner diagonally opposite the origin:
center.x = bounds.origin.x + bounds.size.width;
center.y = bounds.origin.y + bounds.size.height;
The point is now at the center of the rectangle:
center.x = bounds.origin.x + bounds.size.width / 2.0;
center.y = bounds.origin.y + bounds.size.height / 2.0;
If this did not help, try answering the following question.
Imagine an ant at the the corner of a desk (with width W and height H.)
To move to the center of the desk, how much does the ant need to move horizontally across and then vertically up (or vertically up and then horizontally across)?