dc.DrawLinesFromBuffer demo and test to intc data type. Updated documentation.

This commit is contained in:
arjones6
2021-12-15 11:07:18 -05:00
parent 232542ba3e
commit efbea6a275
3 changed files with 27 additions and 6 deletions

View File

@@ -22,8 +22,9 @@ def TestLinesFromBuffer(dc, log):
y2 = np.sin(vs * 16 * np.pi) * w/2 * vs + h/2
pts1 = np.append(x1, y1, 1).astype('int32')
pts2 = np.append(x2, y2, 1).astype('int32')
# Data has to be the same size as a C integer
pts1 = np.append(x1, y1, 1).astype('intc')
pts2 = np.append(x2, y2, 1).astype('intc')
dc.SetPen(wx.BLACK_PEN)
t1 = time.time()
@@ -110,9 +111,16 @@ the python buffer protocol.
DrawLinesFromBuffer(pyBuff)
</pre>
The buffer object needs to provide an array of C integers organized as
x, y point pairs. The size of a C integer is platform dependent.
With numpy, the intc data type will provide the appropriate element size.
If called with an object that doesn't support
the python buffer protocol, or if the underlying element size does not
match the size of a wxPoint, a TypeError exception is raised.
match the size of a C integer, a TypeError exception is raised. If
the buffer provided has float data with the same element size as a
C integer, no error will be raised, but the lines will not be drawn
in the appropriate places.
"""

View File

@@ -481,7 +481,19 @@ def run():
c.addPyMethod('DrawLinesFromBuffer', '(self, pyBuff)',
doc="""\
Implementation of DrawLines that can use numpy arrays, or anything else that uses the
python buffer protocol, directly.
python buffer protocol directly without any element conversion. This provides a
significant performance increase over the standard DrawLines function.
The pyBuff argument needs to provide an array of C integers organized as
x, y point pairs. The size of a C integer is platform dependent.
With numpy, the intc data type will provide the appropriate element size.
If called with an object that doesn't support
the python buffer protocol, or if the underlying element size does not
match the size of a C integer, a TypeError exception is raised. If
the buffer provided has float data with the same element size as a
C integer, no error will be raised, but the lines will not be drawn
in the appropriate places.
:param pyBuff: A python buffer containing integer pairs
""",

View File

@@ -48,8 +48,9 @@ class dcDrawLists_Tests(wtc.WidgetTestCase):
ys.shape = ys.size, 1
pts = np.append(xs, ys, 1)
dc.DrawLinesFromBuffer(pts.astype('int32'))
self.assertRaises(TypeError, dc.DrawLinesFromBuffer, pts.astype('int64'))
dc.DrawLinesFromBuffer(pts.astype('intc'))
self.assertRaises(TypeError, dc.DrawLinesFromBuffer,
pts.astype('int64') if np.intc(1).nbytes != np.int64(1).nbytes else pts.astype('int32'))
self.assertRaises(TypeError, dc.DrawLinesFromBuffer, pts.tolist())
del dc