1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 // Permission to copy, use, modify, sell and distribute this software
6 // is granted provided this copyright notice appears in all copies.
7 // This software is provided "as is" without express or implied
8 // warranty, and with no claim as to its suitability for any purpose.
10 //----------------------------------------------------------------------------
11 // Contact: mcseem@antigrain.com
12 // mcseemagg@yahoo.com
13 // http://www.antigrain.com
14 //----------------------------------------------------------------------------
16 // classes: vertex_iterator
17 // vertex_source_adaptor
18 // vertex_source_adaptor_with_id
20 //----------------------------------------------------------------------------
21 #ifndef AGG_VERTEX_ITERATOR_INCLUDED
22 #define AGG_VERTEX_ITERATOR_INCLUDED
24 #include "agg_basics.h"
30 //---------------------------------------------------------vertex_iterator
31 template<class VertexSource
> class vertex_iterator
35 vertex_iterator(unsigned cmd
) { m_vertex
.cmd
= cmd
; }
36 vertex_iterator(const vertex_iterator
& i
) : m_vs(i
.m_vs
), m_vertex(i
.m_vertex
) {}
37 vertex_iterator(VertexSource
& vs
, unsigned id
) : m_vs(&vs
)
40 m_vertex
.cmd
= m_vs
->vertex(&m_vertex
.x
, &m_vertex
.y
);
42 vertex_iterator
& operator++()
44 m_vertex
.cmd
= m_vs
->vertex(&m_vertex
.x
, &m_vertex
.y
);
48 const vertex_type
& operator*() const { return m_vertex
; }
49 const vertex_type
* operator->() const { return &m_vertex
; }
51 bool operator != (const vertex_iterator
& i
)
53 return m_vertex
.cmd
!= i
.m_vertex
.cmd
;
62 //---------------------------------------------------vertex_source_adaptor
63 template<class VertexContainer
> class vertex_source_adaptor
66 vertex_source_adaptor(const VertexContainer
& container
) :
67 m_container(&container
) {}
71 m_iterator
= m_container
->begin();
72 m_end
= m_container
->end();
75 unsigned vertex(double* x
, double* y
)
77 unsigned cmd
= path_cmd_stop
;
78 if(m_iterator
!= m_end
)
82 cmd
= m_iterator
->cmd
;
89 const VertexContainer
* m_container
;
90 typename
VertexContainer::const_iterator m_iterator
;
91 typename
VertexContainer::const_iterator m_end
;
96 //-------------------------------------------vertex_source_adaptor_with_id
97 template<class VertexContainer
> class vertex_source_adaptor_with_id
100 vertex_source_adaptor_with_id(const VertexContainer
& container
) :
101 m_container(&container
) {}
103 void rewind(unsigned id
)
105 m_iterator
= m_container
->begin(id
);
106 m_end
= m_container
->end();
109 unsigned vertex(double* x
, double* y
)
111 unsigned cmd
= path_cmd_stop
;
112 if(m_iterator
!= m_end
)
116 cmd
= m_iterator
->cmd
;
123 const VertexContainer
* m_container
;
124 typename
VertexContainer::const_iterator m_iterator
;
125 typename
VertexContainer::const_iterator m_end
;