Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Just-a-little-shorter way of getting corners of Rect<T>  (Read 3616 times)

0 Members and 1 Guest are viewing this topic.

jstasiak

  • Newbie
  • *
  • Posts: 2
    • View Profile
Just-a-little-shorter way of getting corners of Rect<T>
« on: April 12, 2010, 01:29:48 pm »
In my code I pretty often use rects and calculate their corners, this is why I use a subclass of Rect<T> class to get following behaviour:

Code: [Select]

template <typename T>
sf::Vector2<T> Rect<T>::GetP1() const
{
return Vector2<T>(Left, Top);
}

template <typename T>
sf::Vector2<T> Rect<T>::GetP2() const
{
return Vector2<T>(Right, Bottom);
}


I believe it could be useful to add it to SFML. It makes code like
Code: [Select]

Rectangle(rect.left, rect.top, rect.right, rect.bottom, ...);
// or
Rectangle(Vector2f(rect.left, rect.top), Vector2f(rect.right, rect.bottom), ...);

a little shorter:
Code: [Select]

Rectangle(rect.GetP1(), rect.GetP2(), ...);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Just-a-little-shorter way of getting corners of Rect<T>
« Reply #1 on: April 12, 2010, 01:32:50 pm »
Hi

Why should it be in SFML? You can easily write functions on top of the sf::Rect structure (without creating your own subclass, which is a bad solution by the way).
Code: [Select]
template <typename T>
sf::Vector2<T> TopLeft(const sf::Rect<T>& rect) const
{
   return Vector2<T>(rect.Left, rect.Top);
}

template <typename T>
sf::Vector2<T> BottomRight(const sf::Rect<T>& rect) const
{
   return Vector2<T>(rect.Right, rect.Bottom);
}

The point is that a lot of people will need a lot of different shortcuts/features for sf::Rect. I don't want to end up with a bloated class so I just define the minimal stuff and let you do whatever you want with it.
Laurent Gomila - SFML developer

jstasiak

  • Newbie
  • *
  • Posts: 2
    • View Profile
Just-a-little-shorter way of getting corners of Rect<T>
« Reply #2 on: April 12, 2010, 02:28:19 pm »
Solution is as good as it fit my needs - ergo it is good solution dispite your opinion. :)
My point is - if a lot of people need a lot (different) of shortcuts - maybe one should take most wanted and put into SFML? Libraries are to make life easier and to programmers code less as far as I remember - but it's only my $0.03.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Just-a-little-shorter way of getting corners of Rect<T>
« Reply #3 on: April 12, 2010, 02:52:06 pm »
I understand your point of view. However this feature is not part of the "most wanted" ones so far ;)
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Just-a-little-shorter way of getting corners of Rect<T>
« Reply #4 on: April 13, 2010, 04:39:13 pm »
I thought rects in 2.0 were going to be w,h,x,y?

If so I think I will switch to 2.0 because I don't have to convert all my rect code.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Just-a-little-shorter way of getting corners of Rect<T>
« Reply #5 on: April 13, 2010, 04:54:51 pm »
Quote
I thought rects in 2.0 were going to be w,h,x,y?

They are.
Laurent Gomila - SFML developer

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Just-a-little-shorter way of getting corners of Rect<T>
« Reply #6 on: April 13, 2010, 05:51:50 pm »
Quote from: "Laurent"
Quote
I thought rects in 2.0 were going to be w,h,x,y?

They are.


Awesome man, good job.

Yeah, forget this corner stuff. I'm building a rect, not a rhombus.

 

anything