-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Sprite rotation function names #970
Comments
You should provide a bit more context on this. I assume you're talking about the One concern I have here is the inability to overload based on angle type if they are both Maybe what we really want is an |
Forcing the user to stick to one measurement unit, degrees or radians, from outside the class is less error prone. If the internals expect something else they can be converted. For non-mathy types, like Mathy-types can have a degrees implementation for ease-of-use like so: float CosDegrees(float degrees)
{
const auto radians = MathUtils::ConvertDegreesToRadians(degrees);
return std::cos(radians);
}
float SinDegrees(float degrees)
{
const auto radians = MathUtils::ConvertDegreesToRadians(degrees);
return std::sin(radians);
}
float Atan2Degrees(float y, float x)
{
const auto radians = std::atan2(y, x);
return MathUtils::ConvertRadiansToDegrees(radians);
} |
I think my point may have been missed. An Example: renderer.drawImageRotated(image, Angle::FromDegrees(90));
renderer.drawImageRotated(image, Angle::FromRadians(Math::Pi / 2)); Example: float SinDegrees(Angle angle)
{
return std::sin(angle.radians());
} |
That seems to be adding undue complexity of an entire class where there doesn't need to be; as well as punting the conversion to the user where it could easily be used incorrectly. Just by looking at the examples, I couldn't tell you what |
That's the point though. You don't need to know the internal representation of It also avoids having to create overloads for different angle types. Not that you could create overloads with either this nor the previous idea, since there is only one type, and hence no type distinction to provide an overload. I suppose I should say there's no need for near duplicate functions for every consumer of At any rate, the simpler solution is to just not worry about different angle measures and define only one correct type, and try to use that everywhere. Internally, I think radian measure makes the most sense. It's the natural measure of angles, and allows for the highest efficiency of use. For user input, degree makes sense, and can be converted on the fly when loading data, or when presenting data to the user. What I don't want, is to provide multiple functions for every possible consumer of angles. |
I totally agree. User-facing should be degrees (again, except for the trig functions, i.e. |
I'm a little torn here as I'm not sure if I like the idea of an Angle class, though considering the direction we've taken with NAS2D so far, it would make sense. The user can specify their Angle in whatever unit they want and internally functions that use Angle would handle it in whatever way is most efficient. At the moment all angle parameters are generally expected to be in degrees. That's was the easiest way for me to think about it so that's how the functions ultimately handle them. Going with the example in the first post, I wonder if it would make sense to expect all functions/parameters in degrees but offer a stand-alone function that can convert to radians as needed? Now that I think about it those functions already exist in the Trig.h file. It's a bit crude but it suited my needs at the time. |
I think that solution is still suitable, and is the one I'm leaning towards. Have just a single correct way to specify angles, and separate helper methods to convert between angle measures. No need to start adding overloads everywhere to handle either angle measure when it can just be a separate wrapped call. That's basically what we already have, and I'm fine with that. |
The
rotation
functions in the Sprite class have poor and potentially confusing names and arguments.Refactoring as
is much more clear and less confusing.
The text was updated successfully, but these errors were encountered: