@@ -163,6 +163,7 @@ class PathNanRemover : protected EmbeddedQueue<4>
163163 VertexSource *m_source;
164164 bool m_remove_nans;
165165 bool m_has_curves;
166+ bool valid_segment_exists;
166167
167168 public:
168169 /* has_curves should be true if the path contains bezier curve
@@ -172,7 +173,9 @@ class PathNanRemover : protected EmbeddedQueue<4>
172173 PathNanRemover (VertexSource &source, bool remove_nans, bool has_curves)
173174 : m_source(&source), m_remove_nans(remove_nans), m_has_curves(has_curves)
174175 {
175- // empty
176+ // ignore all close/end_poly commands until after the first valid
177+ // (nan-free) command is encountered
178+ valid_segment_exists = false ;
176179 }
177180
178181 inline void rewind (unsigned path_id)
@@ -202,8 +205,11 @@ class PathNanRemover : protected EmbeddedQueue<4>
202205 are found along the way, the queue is emptied, and
203206 the next curve segment is handled. */
204207 code = m_source->vertex (x, y);
205- if (code == agg::path_cmd_stop ||
206- code == (agg::path_cmd_end_poly | agg::path_flags_close)) {
208+ if (code == agg::path_cmd_stop) {
209+ return code;
210+ }
211+ if (code == (agg::path_cmd_end_poly | agg::path_flags_close)
212+ && valid_segment_exists) {
207213 return code;
208214 }
209215
@@ -224,6 +230,7 @@ class PathNanRemover : protected EmbeddedQueue<4>
224230 }
225231
226232 if (!has_nan) {
233+ valid_segment_exists = true ;
227234 break ;
228235 }
229236
0 commit comments