Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Intermediate Swift Properties Computed Properties

Confused in regards to how to get centerX and Y as well as Center Value

At 6:00 We add width of the rectangle divided by 2,"Why do we divide by 2?

Also, at 8:03 why subtract width and height from centervalue x and y to get origin x and y?

1 Answer

Deysha Rivera
Deysha Rivera
5,088 Points

We divide by 2, because the center of the rectangle is at the half of the length and half of the width. This "gets" us the center value.

The second part is not explained very well. We are changing the origin (originally 0,0) to match the center value of the rectangle, so we subtract what we know about the rectangle's center in order to shift it.