Deprecation Warnings on Floats

Chris Barker wrote:
DrawLine( int(round(x1)), int(round(y1)), int(round(x2)),
int(round(y2)))

Yeach!

What I would recomend, instead, is to put the int() call where you
compute the value, rather than when you make the DC calls.

-Chris

Yup, darn ugly. And when you have to calculate legend placement, tick
points, axis labels, etc. it is all through the code. The problem with just
applying it where the value is computed is that it will result in wrong
values being calculated later due to scaling and offset. Therefore, to not
introduce any bugs in the code they should be converted in the method as you
have shown (or maybe int(x1+.5) would be faster way to round).

For me rounding does not add that much value as the error is only at most
1/2 pixel. Just truncating to an integer would be fine.

Robin, could you think some more about this? Maybe there is an easier way
that wont cause maintenance problems.

One thought that I had was subclassing wx.wxBufferedDC and then overriding
the offending methods to change the arguments to ints before sending them
on. Seems like a hack and I don't see a similar way for the printout.

Regards,

Gordon Williams

Gordon,

Why not create a wrapper function (or method in the DC object?) called
something like DrawLineFloat(...) and put the conversions to ints in the
wrapper? Then do a search/replace to change calls with float arguments from
DrawLine to the name of the wrapper.

Jim Wanner

···

-----Original Message-----
From: Gordon Williams [mailto:g_will@cyberus.ca]
Sent: Friday, August 29, 2003 8:49 AM
To: wxPython List
Subject: Re: [wxPython-users] Deprecation Warnings on Floats

Chris Barker wrote:
DrawLine( int(round(x1)), int(round(y1)), int(round(x2)),
int(round(y2)))

Yeach!

What I would recomend, instead, is to put the int() call where you
compute the value, rather than when you make the DC calls.

-Chris

Yup, darn ugly. And when you have to calculate legend placement, tick
points, axis labels, etc. it is all through the code. The problem with just
applying it where the value is computed is that it will result in wrong
values being calculated later due to scaling and offset. Therefore, to not
introduce any bugs in the code they should be converted in the method as you
have shown (or maybe int(x1+.5) would be faster way to round).

For me rounding does not add that much value as the error is only at most
1/2 pixel. Just truncating to an integer would be fine.

Robin, could you think some more about this? Maybe there is an easier way
that wont cause maintenance problems.

One thought that I had was subclassing wx.wxBufferedDC and then overriding
the offending methods to change the arguments to ints before sending them
on. Seems like a hack and I don't see a similar way for the printout.

Regards,

Gordon Williams

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Gordon Williams wrote:

Robin, could you think some more about this? Maybe there is an easier way
that wont cause maintenance problems.

I'll keep it in mind, but no promises.

One thought that I had was subclassing wx.wxBufferedDC and then overriding
the offending methods to change the arguments to ints before sending them
on. Seems like a hack and I don't see a similar way for the printout.

Perhaps better would be to create a decorator class that is constructed with a DC of whatever type, and wraps the methods you need and simply forwards the rest to the real DC.

class FloatDCWrapper:
  def __init__(self, aDC):
    self.theDC = aDC

  def DrawLine(self, x1, y1, x2, y2):
    self.theDC.DrawLine(int(round(x1)), int(round(y1)),
      int(round(x2)), int(round(y2)))

  And so on...

···

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