Skip to content

Commit 3b8689a

Browse files
committed
Path: change the type of the code type constants to match the type of the codes array
The matching types make comparisons between the constants and values of the codes array faster. Using the Gtk3Cairo backend with wire3d_animation_sgskip.py: Before: 9.95 fps After: 15.26 fps The main areas where this helps for the cairo case is the faster comparisons in Path.iter_segments() and in _append_paths() of the cairo backend.
1 parent 8b65fa1 commit 3b8689a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Path code types like ``Path.MOVETO`` are now ``np.uint8`` instead of ``int``
2+
````````````````````````````````````````````````````````````````````````````
3+
4+
``Path.STOP``, ``Path.MOVETO``, ``Path.LINETO``, ``Path.CURVE3``,
5+
``Path.CURVE4`` and ``Path.CLOSEPOLY`` are now of the type ``Path.code_type``
6+
(``np.uint8`` by default) instead of plain ``int``. This makes their type
7+
match the array value type of the ``Path.codes`` array.

lib/matplotlib/path.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ class Path(object):
7474
7575
"""
7676

77+
code_type = np.uint8
78+
7779
# Path codes
78-
STOP = 0 # 1 vertex
79-
MOVETO = 1 # 1 vertex
80-
LINETO = 2 # 1 vertex
81-
CURVE3 = 3 # 2 vertices
82-
CURVE4 = 4 # 3 vertices
83-
CLOSEPOLY = 79 # 1 vertex
80+
STOP = code_type(0) # 1 vertex
81+
MOVETO = code_type(1) # 1 vertex
82+
LINETO = code_type(2) # 1 vertex
83+
CURVE3 = code_type(3) # 2 vertices
84+
CURVE4 = code_type(4) # 3 vertices
85+
CLOSEPOLY = code_type(79) # 1 vertex
8486

8587
#: A dictionary mapping Path codes to the number of vertices that the
8688
#: code expects.
@@ -91,8 +93,6 @@ class Path(object):
9193
CURVE4: 3,
9294
CLOSEPOLY: 1}
9395

94-
code_type = np.uint8
95-
9696
def __init__(self, vertices, codes=None, _interpolation_steps=1,
9797
closed=False, readonly=False):
9898
"""

0 commit comments

Comments
 (0)