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

Skip to content

Commit 937c7e2

Browse files
committed
Another pass at fixing simplification.
svn path=/branches/v1_0_maint/; revision=8691
1 parent 97e9ec1 commit 937c7e2

5 files changed

Lines changed: 24 additions & 37 deletions

File tree

Binary file not shown.
-33 Bytes
Loading

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

Lines changed: 6 additions & 5 deletions
Loading

lib/matplotlib/tests/test_simplification.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_fft_peaks():
141141

142142
print len(simplified)
143143

144-
assert len(simplified) == 17
144+
assert len(simplified) == 20
145145

146146
def test_start_with_moveto():
147147
# Should be entirely clipped away to a single MOVETO
@@ -212,8 +212,8 @@ def test_clipper():
212212

213213
@image_comparison(baseline_images=['para_equal_perp'])
214214
def test_para_equal_perp():
215-
x = np.array([0, 1, 2, 1, 0, -1, 0, 1])
216-
y = np.array([1, 1, 2, 1, 0, -1, 0, 0])
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)
217217

218218
fig = plt.figure()
219219
ax = fig.add_subplot(111)

src/path_converters.h

Lines changed: 15 additions & 29 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,36 +676,25 @@ 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

685-
if (perpdNorm2 == paradNorm2) {
682+
m_lastMax = false;
683+
if (totdot > 0.0)
684+
{
685+
if (paradNorm2 > m_dnorm2Max)
686+
{
687+
m_lastMax = true;
688+
m_dnorm2Max = paradNorm2;
689+
m_nextX = *x;
690+
m_nextY = *y;
691+
}
692+
}
693+
else
694+
{
686695
_push(&m_lastx, &m_lasty);
687696
_push(x, y);
688697
break;
689-
} else {
690-
m_lastMax = false;
691-
if (totdot >= 0.0)
692-
{
693-
if (paradNorm2 > m_dnorm2Max)
694-
{
695-
m_lastMax = true;
696-
m_dnorm2Max = paradNorm2;
697-
m_nextX = *x;
698-
m_nextY = *y;
699-
}
700-
}
701-
else
702-
{
703-
if (paradNorm2 < m_dnorm2Min)
704-
{
705-
m_dnorm2Min = paradNorm2;
706-
m_nextX = *x;
707-
m_nextY = *y;
708-
}
709-
}
710698
}
711699

712700
m_lastx = *x;
@@ -770,7 +758,6 @@ class PathSimplifier : protected EmbeddedQueue<9>
770758
double m_origdy;
771759
double m_origdNorm2;
772760
double m_dnorm2Max;
773-
double m_dnorm2Min;
774761
bool m_lastMax;
775762
double m_nextX;
776763
double m_nextY;
@@ -805,7 +792,6 @@ class PathSimplifier : protected EmbeddedQueue<9>
805792
m_origdNorm2 = m_origdx * m_origdx + m_origdy * m_origdy;
806793

807794
m_dnorm2Max = m_origdNorm2;
808-
m_dnorm2Min = 0.0;
809795
m_lastMax = true;
810796
m_lastWrittenX = m_queue[m_queue_write-1].x;
811797
m_lastWrittenY = m_queue[m_queue_write-1].y;

0 commit comments

Comments
 (0)