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

Skip to content

Commit 1e1ad3b

Browse files
committed
Change simplification algorithm so it always returns points from the original data, rather than extrapolated ones. This is somewhat experimental.
svn path=/trunk/matplotlib/; revision=6814
1 parent 24dde83 commit 1e1ad3b

1 file changed

Lines changed: 19 additions & 34 deletions

File tree

src/agg_py_path_iterator.h

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ class SimplifyPath
142142
m_do_clipping(width > 0.0 && height > 0.0),
143143
m_origdx(0.0), m_origdy(0.0),
144144
m_origdNorm2(0.0), m_dnorm2Max(0.0), m_dnorm2Min(0.0),
145-
m_haveMin(false), m_lastMax(false), m_maxX(0.0), m_maxY(0.0),
146-
m_minX(0.0), m_minY(0.0), m_lastWrittenX(0.0), m_lastWrittenY(0.0)
145+
m_lastMax(false), m_nextX(0.0), m_nextY(0.0),
146+
m_lastWrittenX(0.0), m_lastWrittenY(0.0)
147147
#if DEBUG_SIMPLIFY
148148
, m_pushed(0), m_skipped(0)
149149
#endif
@@ -302,13 +302,12 @@ class SimplifyPath
302302
//set all the variables to reflect this new orig vector
303303
m_dnorm2Max = m_origdNorm2;
304304
m_dnorm2Min = 0.0;
305-
m_haveMin = false;
306305
m_lastMax = true;
307306

308-
m_lastx = m_maxX = *x;
309-
m_lasty = m_maxY = *y;
310-
m_lastWrittenX = m_minX = m_lastx;
311-
m_lastWrittenY = m_minY = m_lasty;
307+
m_nextX = m_lastWrittenX = m_lastx;
308+
m_nextY = m_lastWrittenY = m_lasty;
309+
m_lastx = *x;
310+
m_lasty = *y;
312311
#if DEBUG_SIMPLIFY
313312
m_skipped++;
314313
#endif
@@ -358,18 +357,17 @@ class SimplifyPath
358357
{
359358
m_lastMax = true;
360359
m_dnorm2Max = paradNorm2;
361-
m_maxX = m_lastWrittenX + paradx;
362-
m_maxY = m_lastWrittenY + parady;
360+
m_nextX = *x;
361+
m_nextY = *y;
363362
}
364363
}
365364
else
366365
{
367-
m_haveMin = true;
368366
if (paradNorm2 > m_dnorm2Min)
369367
{
370368
m_dnorm2Min = paradNorm2;
371-
m_minX = m_lastWrittenX + paradx;
372-
m_minY = m_lastWrittenY + parady;
369+
m_nextX = *x;
370+
m_nextY = *y;
373371
}
374372
}
375373

@@ -394,17 +392,12 @@ class SimplifyPath
394392
}
395393

396394
// Fill the queue with the remaining vertices if we've finished the
397-
// path in the above loop. Mark the path as done, so we don't call
398-
// m_source->vertex again and segfault.
395+
// path in the above loop.
399396
if (cmd == agg::path_cmd_stop)
400397
{
401398
if (m_origdNorm2 != 0.0)
402399
{
403-
if (m_haveMin)
404-
{
405-
queue_push(agg::path_cmd_line_to, m_minX, m_minY);
406-
}
407-
queue_push(agg::path_cmd_line_to, m_maxX, m_maxY);
400+
queue_push(agg::path_cmd_line_to, m_nextX, m_nextY);
408401
}
409402
queue_push(agg::path_cmd_stop, 0.0, 0.0);
410403
}
@@ -459,12 +452,9 @@ class SimplifyPath
459452
double m_origdNorm2;
460453
double m_dnorm2Max;
461454
double m_dnorm2Min;
462-
bool m_haveMin;
463455
bool m_lastMax;
464-
double m_maxX;
465-
double m_maxY;
466-
double m_minX;
467-
double m_minY;
456+
double m_nextX;
457+
double m_nextY;
468458
double m_lastWrittenX;
469459
double m_lastWrittenY;
470460

@@ -517,11 +507,7 @@ class SimplifyPath
517507

518508
inline void _push(double* x, double* y)
519509
{
520-
if (m_haveMin)
521-
{
522-
queue_push(agg::path_cmd_line_to, m_minX, m_minY);
523-
}
524-
queue_push(agg::path_cmd_line_to, m_maxX, m_maxY);
510+
queue_push(agg::path_cmd_line_to, m_nextX, m_nextY);
525511

526512
//if we clipped some segments between this line and the next line
527513
//we are starting, we also need to move to the last point.
@@ -546,12 +532,11 @@ class SimplifyPath
546532

547533
m_dnorm2Max = m_origdNorm2;
548534
m_dnorm2Min = 0.0;
549-
m_haveMin = false;
550535
m_lastMax = true;
551-
m_lastx = m_maxX = *x;
552-
m_lasty = m_maxY = *y;
553-
m_lastWrittenX = m_minX = m_lastx;
554-
m_lastWrittenY = m_minY = m_lasty;
536+
m_lastWrittenX = m_queue[m_queue_write-1].x;
537+
m_lastWrittenY = m_queue[m_queue_write-1].y;
538+
m_lastx = m_nextX = *x;
539+
m_lasty = m_nextY = *y;
555540

556541
m_clipped = false;
557542
#if DEBUG_SIMPLIFY

0 commit comments

Comments
 (0)