66#include " numpy/arrayobject.h"
77#include " agg_path_storage.h"
88#include " MPL_isnan.h"
9- #include < deque >
9+ #include < queue >
1010
1111class PathIterator
1212{
@@ -134,7 +134,8 @@ class SimplifyPath
134134#if DEBUG_SIMPLIFY
135135 ~SimplifyPath ()
136136 {
137- printf (" %d %d\n " , m_pushed, m_skipped);
137+ if (m_simplify)
138+ printf (" %d %d\n " , m_pushed, m_skipped);
138139 }
139140#endif
140141
@@ -175,21 +176,29 @@ class SimplifyPath
175176 // multiple points can be emitted in a single call, and those points
176177 // will be popped from the queue in subsequent calls. The following
177178 // block will empty the queue before proceeding to the main loop below.
179+ // -- Michael Droettboom
178180 if (m_queue.size ())
179181 {
180182 const item& front = m_queue.front ();
181183 unsigned cmd = front.cmd ;
182184 *x = front.x ;
183185 *y = front.y ;
184- m_queue.pop_front ();
186+ m_queue.pop ();
187+ #if DEBUG_SIMPLIFY
188+ printf ((cmd == agg::path_cmd_move_to) ? " |" : " -" );
189+ #endif
185190 return cmd;
186191 }
187192
188193 // If the queue is now empty, and the path was fully consumed
189194 // in the last call to the main loop, return agg::path_cmd_stop to
190195 // signal that there are no more points to emit.
191- if (m_done)
196+ if (m_done) {
197+ #if DEBUG_SIMPLIFY
198+ printf (" .\n " );
199+ #endif
192200 return agg::path_cmd_stop;
201+ }
193202
194203 // The main simplification loop. The point is consume only as many
195204 // points as necessary until some have been added to the outbound
@@ -209,15 +218,15 @@ class SimplifyPath
209218 // + init
210219 if (m_moveto)
211220 {
212- m_queue.push_back (item (agg::path_cmd_move_to, *x, *y));
213221 m_lastx = *x;
214222 m_lasty = *y;
215223 m_moveto = false ;
216224 m_origdNorm2 = 0.0 ;
217225#if DEBUG_SIMPLIFY
218226 m_pushed++;
227+ printf (" |" );
219228#endif
220- break ;
229+ return agg::path_cmd_move_to ;
221230 }
222231
223232 // Don't render line segments less than one pixel long
@@ -240,6 +249,9 @@ class SimplifyPath
240249 m_lastx = *x;
241250 m_lasty = *y;
242251 m_clipped = true ;
252+ #if DEBUG_SIMPLIFY
253+ m_skipped++;
254+ #endif
243255 continue ;
244256 }
245257
@@ -252,7 +264,7 @@ class SimplifyPath
252264 {
253265 if (m_clipped)
254266 {
255- m_queue.push_back (item (agg::path_cmd_move_to, m_lastx, m_lasty));
267+ m_queue.push (item (agg::path_cmd_move_to, m_lastx, m_lasty));
256268 m_clipped = false ;
257269 }
258270
@@ -277,6 +289,9 @@ class SimplifyPath
277289 // set the last point seen
278290 m_lastx = *x;
279291 m_lasty = *y;
292+ #if DEBUG_SIMPLIFY
293+ m_skipped++;
294+ #endif
280295 continue ;
281296 }
282297
@@ -339,6 +354,9 @@ class SimplifyPath
339354
340355 m_lastx = *x;
341356 m_lasty = *y;
357+ #if DEBUG_SIMPLIFY
358+ m_skipped++;
359+ #endif
342360 continue ;
343361 }
344362
@@ -350,14 +368,14 @@ class SimplifyPath
350368 // direction we are drawing in, move back to we start drawing from
351369 // back there.
352370 if (m_haveMin)
353- m_queue.push_back (item (agg::path_cmd_line_to, m_minX, m_minY));
354- m_queue.push_back (item (agg::path_cmd_line_to, m_maxX, m_maxY));
371+ m_queue.push (item (agg::path_cmd_line_to, m_minX, m_minY));
372+ m_queue.push (item (agg::path_cmd_line_to, m_maxX, m_maxY));
355373
356374 // if we clipped some segments between this line and the next line
357375 // we are starting, we also need to move to the last point.
358376 if (m_clipped)
359377 {
360- m_queue.push_back (item (agg::path_cmd_move_to, m_lastx, m_lasty));
378+ m_queue.push (item (agg::path_cmd_move_to, m_lastx, m_lasty));
361379 }
362380 else if (!m_lastMax)
363381 {
@@ -367,11 +385,10 @@ class SimplifyPath
367385 // the line just drawn.
368386
369387 // Would be move_to if not for the artifacts
370- m_queue.push_back (item (agg::path_cmd_line_to, m_lastx, m_lasty));
388+ m_queue.push (item (agg::path_cmd_line_to, m_lastx, m_lasty));
371389 }
372390
373391 // now reset all the variables to get ready for the next line
374-
375392 m_origdx = *x - m_lastx;
376393 m_origdy = *y - m_lasty;
377394 m_origdNorm2 = m_origdx*m_origdx + m_origdy*m_origdy;
@@ -393,7 +410,7 @@ class SimplifyPath
393410 m_lastx = *x;
394411 m_lasty = *y;
395412#if DEBUG_SIMPLIFY
396- m_pushed++ ;
413+ m_pushed += m_queue. size () ;
397414#endif
398415 break ;
399416 }
@@ -406,8 +423,8 @@ class SimplifyPath
406423 if (m_origdNorm2 != 0 )
407424 {
408425 if (m_haveMin)
409- m_queue.push_back (item (agg::path_cmd_line_to, m_minX, m_minY));
410- m_queue.push_back (item (agg::path_cmd_line_to, m_maxX, m_maxY));
426+ m_queue.push (item (agg::path_cmd_line_to, m_minX, m_minY));
427+ m_queue.push (item (agg::path_cmd_line_to, m_maxX, m_maxY));
411428 }
412429 m_done = true ;
413430 }
@@ -420,11 +437,17 @@ class SimplifyPath
420437 unsigned cmd = front.cmd ;
421438 *x = front.x ;
422439 *y = front.y ;
423- m_queue.pop_front ();
440+ m_queue.pop ();
441+ #if DEBUG_SIMPLIFY
442+ printf ((cmd == agg::path_cmd_move_to) ? " |" : " -" );
443+ #endif
424444 return cmd;
425445 }
426446 else
427447 {
448+ #if DEBUG_SIMPLIFY
449+ printf (" .\n " );
450+ #endif
428451 return agg::path_cmd_stop;
429452 }
430453 }
@@ -443,7 +466,7 @@ class SimplifyPath
443466 double x;
444467 double y;
445468 };
446- typedef std::deque <item> ItemQueue;
469+ typedef std::queue <item> ItemQueue;
447470 ItemQueue m_queue;
448471 bool m_moveto;
449472 double m_lastx, m_lasty;
0 commit comments