wxRealPoint::operator* truncates to int before assigning to the new point

object, which seems dumb. So let's make our own implementation which
preserves the floating point result.
This commit is contained in:
Robin Dunn
2018-09-25 12:42:22 -07:00
parent f170a77808
commit 8f07ca5c28
3 changed files with 13 additions and 2 deletions

View File

@@ -306,10 +306,16 @@ def run():
c.addItem(etgtools.WigCode("""\
wxRealPoint operator+(const wxRealPoint& other);
wxRealPoint operator-(const wxRealPoint& other);
wxRealPoint operator*(double d);
wxRealPoint operator/(int i);
"""))
# wxRealPoint::operator* truncates to int before assigning to the new point
# object, which seems dumb. So let's make our own implementation which
# preserves the floating point result.
c.addCppMethod('wxRealPoint*', '__mul__', '(double d)', isSlot=True,
body="""\
return new wxRealPoint(self->x * d, self->y * d);
""")
# wxRealPoint typemap
c.convertFromPyObject = tools.convertTwoDoublesTemplate('wxRealPoint')

View File

@@ -1236,6 +1236,7 @@ class CppMethodDef(MethodDef):
self.cppSignature = cppSignature
self.virtualCatcherCode = virtualCatcherCode
self.isCore = _globalIsCore
self.isSlot = False
self.__dict__.update(kw)
@staticmethod

View File

@@ -865,7 +865,11 @@ from .%s import *
else:
if pnames:
pnames = ', ' + pnames
stream.write('%s(sipCpp%s);\n' % (fname, pnames))
if method.isSlot:
argname = 'a0'
else:
argname = 'sipCpp'
stream.write('%s(%s%s);\n' % (fname, argname, pnames))
else:
stream.write('%s(%s);\n' % (fname, pnames))
stream.write('%sPy_END_ALLOW_THREADS\n' % (indent+' '*4))