I'm a .NET developer trying to do c++ (ahem) and I encountered a compiler warning in here:
const auto u = (textel.character % font_glyph_column_count) * font_glyph_size; // <- all int
const auto v = (textel.character / font_glyph_column_count) * font_glyph_size; // <- all int
const auto top_left_uv = sf::Vector2f(u, v);
In the last line, where 'u' and 'v' are passed as args to the Vector ctor, the compiler says:
conversion from 'const int' to 'T', possible loss of data
Ok, .NET doesn't do this, but i looked it up and i understand that not all int32 can be represented by a float. (Now I wonder why .NET doesn't warn about this :) )
So, my .NET inspired solution is - apparently called - a "C cast", which my Resharper complains about: so, i change it to a static_cast. Okido...
const auto u = static_cast<float>(textel.character % font_glyph_column_count) * font_glyph_size;
const auto v = static_cast<float>(textel.character / font_glyph_column_count) * font_glyph_size;
const auto top_left_uv = sf::Vector2f(u, v);
But yuk! now my arithmetic code gets littered with these casts, while the juggling around of integer computation is very deliberate, and having to put the result in float-based vectors, is also necessary...
I could change eg. font_glyph_size to a float, so casting becomes implicit, but it makes more sense for it to be a discrete amount of pixels, so int...
Can this code be made prettier?