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

Author Topic: scale(float factor)  (Read 4098 times)

0 Members and 1 Guest are viewing this topic.

Wes

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
scale(float factor)
« on: March 27, 2016, 11:26:02 pm »
Currently, sf::Transformable has:
setScale(const sf::Vector2f& factors);
scale(const sf::Vector2f& factors);
The scale function is conveniently equivalent to setScale(getScale() * factors)

For added convenience sf::Transformable also has:
setScale(float factorX, float factorY);
scale(float factorX, float factorY);
These functions do the same thing, but they construct the factor-vector for you out of factorX and factorY.
Instead of doing scale(sf::Vector2f(x, y)), you can do scale(x, y)

In my opinion, for additional convenience, sf::Transformable should also have:
setScale(float factor);
scale(float factor);
These functions would do the same thing as the other convenience functions, except both parameters of the factor-vector would be factor.
scale(2) would be the same as scale(2, 2)
setScale(2) would be the same as setScale(2, 2)

If people agree, I'd be more than happy to make a pull-request.
« Last Edit: March 28, 2016, 01:22:51 am by Wes »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: scale(float factor)
« Reply #1 on: March 28, 2016, 09:04:10 am »
A long time ago, when we discussed about these overloads, we all agreed that the best thing was to limit them to the minimum. It is even likely that the (x, y) overloads will vanish one day, now that the C++11 syntax f({x, y}) is widely available.
Laurent Gomila - SFML developer

Wes

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: scale(float factor)
« Reply #2 on: March 29, 2016, 09:41:35 pm »
I thought there had to be a reason this feature didn't exist yet. It was too obvious. Thanks anyways ;)

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: scale(float factor)
« Reply #3 on: August 11, 2016, 04:49:17 pm »
nah. Overloads are what makes a library convenient and easy to use. Imagine in CSS if we had to specify all margins every time ? we would get bloatings everywhere :

.myclass{margin: 10px 10px 10px 10px}

instead of that, they were smart and overloaded this attribute to make clean shortcuts possible :

.myclass{margin: 10px}   = 10px for all directions
.myclass{margin: 10px 20px}   = 10px for top & bottom, 20px for left & right

imo, SFML should follow this practice : making life easy and clean for the developer who uses it. I liked SFML, but too much bad choices are made

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: scale(float factor)
« Reply #4 on: August 11, 2016, 06:10:11 pm »
You can wrap it into function like that.  :D
template<typename T>
sf::Vector2<T> Factor(T v)
{
        return {v, v};
}

// ...

auto vec = Factor(2.f);
sprite.scale(vec);
// or
sprite.scale(Factor(sqrt(0.5f)));
// etc.

 

anything