floats passed to DC methods expecting longs

Chris Barker wrote:

To speak for someone else, Gordon Williams ended up creating a wrapper
class to the DCs in wxPyPlot, so he could pass in floats, and the
wrapper converted them. I'm sure he'd prefer wxPython do it for him.

路路路

------------

I very rarely look at this list, but this thread caught my attention :wink: Ha!

I think that it would make the code cleaner and clearer if there was
automatic conversion between floats and ints, but I can also understand the
argument about forcing the programmer to do the "right thing" up front.

Truth be known, I would prefer that the DrawxxxList methods would take a
float and then round it to an int rather than truncate it. I would strongly
expect that this is what users would both expect and want - draw the line,
point, etc. at the closest pixel location and not at the truncated pixel
point. I can't think of a reason why a user would want to use a truncated
number instead of a rounded number. In other words the "right thing" above
would be to round the ints. This would also hide the internals from the
user - DrawXXX would do what the user would expect it to do - and then you
wouldn't have to explain in the docs that the program is using ints
internally and that it gets truncated rather than rounded, blaa, blaa,
blaa...

Ints would work faster than floats because they wouldn't go through the
rounding process, but I would expect that you can make the rounding process
faster in the DC than the user could externally even if they were using
something like numeric. I don't know how much of an impact rounding would
have on plotting speed, but that would have to be considered.

So, my preferred options
1) Allow only ints, forcing the user to do what he wants,
2) Allow floats but round instead of truncate,
with 2) preferred over 1).

Regards,

Gordon Williams

Gordon Williams wrote:

Truth be known, I would prefer that the DrawxxxList methods would take a
float and then round it to an int rather than truncate it. I would strongly
expect that this is what users would both expect and want - draw the line,
point, etc. at the closest pixel location and not at the truncated pixel
point. I can't think of a reason why a user would want to use a truncated
number instead of a rounded number. In other words the "right thing" above
would be to round the ints. This would also hide the internals from the
user - DrawXXX would do what the user would expect it to do - and then you
wouldn't have to explain in the docs that the program is using ints
internally and that it gets truncated rather than rounded, blaa, blaa,
blaa...

Ints would work faster than floats because they wouldn't go through the
rounding process, but I would expect that you can make the rounding process
faster in the DC than the user could externally even if they were using
something like numeric. I don't know how much of an impact rounding would
have on plotting speed, but that would have to be considered.

So, my preferred options
1) Allow only ints, forcing the user to do what he wants,
2) Allow floats but round instead of truncate,
with 2) preferred over 1).

Looking at it from a little different conceptual viewpoint, there's not much difference between the above options and allowing floats with truncation but forcing the user to use round() if that is what he wants, which is what we have now, and is also equivallent to what we had before... Also, remember that this isn't just for wx.DC methods, but is the code generated by SWIG to convert a PyObject to a C int (or long, short, unsigneds, etc.) everywhere in wxPython.

路路路

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!