Float and int casts: annoying


#1

Surely there’s got to be a better way?

      g.drawLine (float (x + r.getX ()), float (r.getY ()), float (x + r.getX ()), float (r.getBottom ()));
      g.drawLine (float (r.getX ()), float (y + r.getY ()), float (r.getRight ()), float (y + r.getY ()));

#2

g.drawLine (Line<int> (x + r.getX(), r.getY(), x + r.getX(), r.getBottom()).toFloat());?
Or presuming “r” is a Rectangle create a float version of that first (Rectangle::toFloat()) and use it directly?

I tend to do most of drawing operations these days using Rectangles so the above code would look something like:

Rectangle<float> r2 (r.translated (x, 0).toFloat()) g.drawLine (Line<float> (r2.getTopLeft(), r2.getBottomLeft()));

I think it explains the drawing operation quite clearly as well.