Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 142dbe2

Browse files
committed
Fix path simplification so the path always starts with a MOVETO.
svn path=/trunk/matplotlib/; revision=7900
1 parent 46e9f6f commit 142dbe2

3 files changed

Lines changed: 43 additions & 4 deletions

File tree

lib/matplotlib/path.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1):
115115
codes = np.asarray(codes, self.code_type)
116116
assert codes.ndim == 1
117117
assert len(codes) == len(vertices)
118+
if len(codes):
119+
assert codes[0] == self.MOVETO
118120

119121
assert vertices.ndim == 2
120122
assert vertices.shape[1] == 2

lib/matplotlib/tests/test_simplification.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
import matplotlib
33
from matplotlib.testing.decorators import image_comparison, knownfailureif
44
import matplotlib.pyplot as plt
5-
from matplotlib import patches, path
65

76
from pylab import *
87
import numpy as np
9-
from matplotlib import patches, path
8+
from matplotlib import patches, path, transforms
109
nan = np.nan
1110
Path = path.Path
1211

@@ -134,6 +133,38 @@ def test_fft_peaks():
134133

135134
assert len(simplified) == 13
136135

136+
def test_start_with_moveto():
137+
# Should be entirely clipped away to a single MOVETO
138+
data = """
139+
ZwAAAAku+v9UAQAA+Tj6/z8CAADpQ/r/KAMAANlO+v8QBAAAyVn6//UEAAC6ZPr/2gUAAKpv+v+8
140+
BgAAm3r6/50HAACLhfr/ewgAAHyQ+v9ZCQAAbZv6/zQKAABepvr/DgsAAE+x+v/lCwAAQLz6/7wM
141+
AAAxx/r/kA0AACPS+v9jDgAAFN36/zQPAAAF6Pr/AxAAAPfy+v/QEAAA6f36/5wRAADbCPv/ZhIA
142+
AMwT+/8uEwAAvh77//UTAACwKfv/uRQAAKM0+/98FQAAlT/7/z0WAACHSvv//RYAAHlV+/+7FwAA
143+
bGD7/3cYAABea/v/MRkAAFF2+//pGQAARIH7/6AaAAA3jP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FPwAANb7//48/AAAsyf//lz8AACPU//+ePwAAGt///6M/AAAR6v//pj8A
158+
AAj1//+nPwAA/////w=="""
159+
160+
verts = np.fromstring(data.decode('base64'), dtype='<i4')
161+
verts = verts.reshape((len(verts) / 2, 2))
162+
path = Path(verts)
163+
segs = path.iter_segments(transforms.IdentityTransform, clip=(0.0, 0.0, 100.0, 100.0))
164+
segs = list(segs)
165+
assert len(segs) == 1
166+
assert segs[0][1] == Path.MOVETO
167+
137168
if __name__=='__main__':
138169
import nose
139170
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

src/path_converters.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,15 @@ class PathSimplifier : protected EmbeddedQueue<9>
684684
{
685685
if (m_origdNorm2 != 0.0)
686686
{
687-
queue_push(agg::path_cmd_line_to, m_nextX, m_nextY);
687+
queue_push((m_moveto || m_after_moveto) ?
688+
agg::path_cmd_move_to : agg::path_cmd_line_to,
689+
m_nextX, m_nextY);
690+
m_moveto = false;
688691
}
689-
queue_push(agg::path_cmd_line_to, m_lastx, m_lasty);
692+
queue_push((m_moveto || m_after_moveto) ?
693+
agg::path_cmd_move_to : agg::path_cmd_line_to,
694+
m_lastx, m_lasty);
695+
m_moveto = false;
690696
queue_push(agg::path_cmd_stop, 0.0, 0.0);
691697
}
692698

0 commit comments

Comments
 (0)