Speed up arrayToQPath when connect='pairs'

As discussed earlier, the process of QDataStream >> QPainterPath is
quite slow, so this commit makes an improvement on QPainterPath creation
for the case of connect='pairs' by using a naive method of moving the
path and drawing a line on the path.  This was the fastest method
identified during testing.
This commit is contained in:
Ogi Moore 2021-05-24 20:27:53 -07:00
parent aaae0b9e1c
commit d62d3b182f

View File

@ -14,8 +14,11 @@ import struct
import sys
import warnings
import math
import functools
import itertools
import numpy as np
from numpy.lib import recfunctions as rfn
from .util.cupy_helper import getCupy
from .util.numba_helper import getNumbaFunctions
@ -1759,8 +1762,18 @@ def arrayToQPath(x, y, connect='all', finiteCheck=True):
path.addPolygon(polygon)
return path
elif eq(connect, 'pairs'):
arr[:]['c'][::2] = 0
arr[:]['c'][1::2] = 1 # connect every 2nd point to every 1st one
xs = arr['x'].tolist()
ys = arr['y'].tolist()
lineTo = path.lineTo
moveTo = path.moveTo
for elementType, x, y in zip(
itertools.cycle((moveTo, lineTo)),
xs,
ys
):
elementType(x, y)
return path
elif eq(connect, 'finite'):
# Let's call a point with either x or y being nan is an invalid point.
# A point will anyway not connect to an invalid point regardless of the