Skip to content

Commit e16060e

Browse files
committed
Merged revisions 8690-8691,8696-8697 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint ........ r8690 | mdboom | 2010-09-08 09:32:17 -0500 (Wed, 08 Sep 2010) | 2 lines [3058804] part of a line is not drawn ........ r8691 | mdboom | 2010-09-08 10:51:18 -0500 (Wed, 08 Sep 2010) | 2 lines Another pass at fixing simplification. ........ r8696 | ryanmay | 2010-09-11 14:02:38 -0500 (Sat, 11 Sep 2010) | 1 line Fix typo in griddata(). ........ r8697 | ryanmay | 2010-09-11 14:03:52 -0500 (Sat, 11 Sep 2010) | 1 line Handle multple calls to GTKTimer.start() by stopping any existing gtk timer id. ........ svn path=/trunk/matplotlib/; revision=8698
2 parents 39694cb + 6064c67 commit e16060e

File tree

10 files changed

+331
-21
lines changed

10 files changed

+331
-21
lines changed

lib/matplotlib/backends/backend_gtk.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class TimerGTK(TimerBase):
101101
functions add_callback and remove_callback can be used.
102102
'''
103103
def _timer_start(self):
104+
# Need to stop it, otherwise we potentially leak a timer id that will
105+
# never be stopped.
106+
self._timer_stop()
104107
self._timer = gobject.timeout_add(self._interval, self._on_timer)
105108

106109
def _timer_stop(self):
@@ -109,6 +112,7 @@ def _timer_stop(self):
109112
self._timer = None
110113

111114
def _timer_set_interval(self):
115+
# Only stop and restart it if the timer has already been started
112116
if self._timer is not None:
113117
self._timer_stop()
114118
self._timer_start()

lib/matplotlib/mlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ def griddata(x,y,z,xi,yi,interp='nn'):
27192719
# remove masked points.
27202720
if hasattr(z,'mask'):
27212721
# make sure mask is not a scalar boolean array.
2722-
if a.mask.ndim:
2722+
if z.mask.ndim:
27232723
x = x.compress(z.mask == False)
27242724
y = y.compress(z.mask == False)
27252725
z = z.compressed()
Binary file not shown.
-33 Bytes
Loading

lib/matplotlib/tests/baseline_images/test_simplification/fft_peaks.svg

Lines changed: 6 additions & 5 deletions
Loading
Binary file not shown.
19.7 KB
Loading

lib/matplotlib/tests/baseline_images/test_simplification/para_equal_perp.svg

Lines changed: 296 additions & 0 deletions
Loading

lib/matplotlib/tests/test_simplification.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def test_noise():
7373
path = transform.transform_path(path)
7474
simplified = list(path.iter_segments(simplify=(800, 600)))
7575

76+
print len(simplified)
77+
7678
assert len(simplified) == 3884
7779

7880
def test_sine_plus_noise():
@@ -90,6 +92,8 @@ def test_sine_plus_noise():
9092
path = transform.transform_path(path)
9193
simplified = list(path.iter_segments(simplify=(800, 600)))
9294

95+
print len(simplified)
96+
9397
assert len(simplified) == 876
9498

9599
@image_comparison(baseline_images=['simplify_curve'])
@@ -135,7 +139,9 @@ def test_fft_peaks():
135139
path = transform.transform_path(path)
136140
simplified = list(path.iter_segments(simplify=(800, 600)))
137141

138-
assert len(simplified) == 17
142+
print len(simplified)
143+
144+
assert len(simplified) == 20
139145

140146
def test_start_with_moveto():
141147
# Should be entirely clipped away to a single MOVETO
@@ -204,6 +210,17 @@ def test_clipper():
204210
ax.set_xlim(5, 9)
205211
fig.savefig('clipper_edge')
206212

213+
@image_comparison(baseline_images=['para_equal_perp'])
214+
def test_para_equal_perp():
215+
x = np.array([0, 1, 2, 1, 0, -1, 0, 1] + [1] * 128)
216+
y = np.array([1, 1, 2, 1, 0, -1, 0, 0] + [0] * 128)
217+
218+
fig = plt.figure()
219+
ax = fig.add_subplot(111)
220+
ax.plot(x + 1, y + 1)
221+
ax.plot(x + 1, y + 1, 'ro')
222+
fig.savefig('para_equal_perp')
223+
207224
if __name__=='__main__':
208225
import nose
209226
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

src/path_converters.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class PathSimplifier : protected EmbeddedQueue<9>
520520
m_moveto(true), m_after_moveto(false),
521521
m_lastx(0.0), m_lasty(0.0), m_clipped(false),
522522
m_origdx(0.0), m_origdy(0.0),
523-
m_origdNorm2(0.0), m_dnorm2Max(0.0), m_dnorm2Min(0.0),
523+
m_origdNorm2(0.0), m_dnorm2Max(0.0),
524524
m_lastMax(false), m_nextX(0.0), m_nextY(0.0),
525525
m_lastWrittenX(0.0), m_lastWrittenY(0.0)
526526
{
@@ -637,7 +637,6 @@ class PathSimplifier : protected EmbeddedQueue<9>
637637

638638
//set all the variables to reflect this new orig vector
639639
m_dnorm2Max = m_origdNorm2;
640-
m_dnorm2Min = 0.0;
641640
m_lastMax = true;
642641

643642
m_nextX = m_lastWrittenX = m_lastx = *x;
@@ -677,13 +676,11 @@ class PathSimplifier : protected EmbeddedQueue<9>
677676
/* check if the current vector is parallel or
678677
anti-parallel to the orig vector. If it is
679678
parallel, test if it is the longest of the vectors
680-
we are merging in that direction. If anti-p, test
681-
if it is the longest in the opposite direction (the
682-
min of our final line) */
679+
we are merging in that direction. */
683680
double paradNorm2 = paradx * paradx + parady * parady;
684681

685682
m_lastMax = false;
686-
if (totdot >= 0.0)
683+
if (totdot > 0.0)
687684
{
688685
if (paradNorm2 > m_dnorm2Max)
689686
{
@@ -695,12 +692,9 @@ class PathSimplifier : protected EmbeddedQueue<9>
695692
}
696693
else
697694
{
698-
if (paradNorm2 < m_dnorm2Min)
699-
{
700-
m_dnorm2Min = paradNorm2;
701-
m_nextX = *x;
702-
m_nextY = *y;
703-
}
695+
_push(&m_lastx, &m_lasty);
696+
_push(x, y);
697+
break;
704698
}
705699

706700
m_lastx = *x;
@@ -764,7 +758,6 @@ class PathSimplifier : protected EmbeddedQueue<9>
764758
double m_origdy;
765759
double m_origdNorm2;
766760
double m_dnorm2Max;
767-
double m_dnorm2Min;
768761
bool m_lastMax;
769762
double m_nextX;
770763
double m_nextY;
@@ -799,7 +792,6 @@ class PathSimplifier : protected EmbeddedQueue<9>
799792
m_origdNorm2 = m_origdx * m_origdx + m_origdy * m_origdy;
800793

801794
m_dnorm2Max = m_origdNorm2;
802-
m_dnorm2Min = 0.0;
803795
m_lastMax = true;
804796
m_lastWrittenX = m_queue[m_queue_write-1].x;
805797
m_lastWrittenY = m_queue[m_queue_write-1].y;

0 commit comments

Comments
 (0)