SFML community forums

Help => General => Topic started by: pabloist on September 19, 2010, 08:52:05 am

Title: Rect class?
Post by: pabloist on September 19, 2010, 08:52:05 am
I don't really understand how the rect class works; the reference says

Rect (T LeftCoord, T TopCoord, T RightCoord, T BottomCoord)

but coordinates need to be pairs of numbers, right? so how does an IntRect work? That requires using single integers for each coordinate..?

I'd appreciate if someone could explain (:
Title: Rect class?
Post by: Walker on September 19, 2010, 09:02:39 am
I think other people have been confused by the use of 'coord' before but I find sf::Rect much simpler to use and understand than other rect implementations.

Left, Top, Right, Bottom refer to the positions of the 'sides' or 'edges'. Left and Right are on the X axis, Top and Bottom are on Y.

So Left is the X coordinate of the Left side/edge and Top is the Y coordinate of the Top side/edge. So the point at (Left, Top) would be the top left corner of the rect.

Hard to explain in words! Make sense though?
Title: Rect class?
Post by: Beliar on September 19, 2010, 09:04:36 am
Hmm, you got the TopLeft coordinates and the BottomRight ones, what do you need more for an Rectangle?


If you don't know what i mean, look at this:
Code: [Select]
Top/Left------------------Top/Right
    |                        |
    |                        |
    |                        |
    |                        |
Bottom/Left------------Bottom/Right
Title: Rect class?
Post by: Nexus on September 19, 2010, 03:09:46 pm
You should take a look at the sf::Rect class template in SFML 2. It uses Left, Top, Width and Height. As far as I remember, one of the decisive reasons why Laurent changed the API was the confusion coming up again and again, concerning whether Bottom/Right coordinates were inclusive or exclusive.
Title: Rect class?
Post by: pabloist on September 19, 2010, 11:53:15 pm
Thanks very much everyone (: That clears it up a lot for me.