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 #ifndef AGG_CONV_ADAPTOR_VPGEN_INCLUDED
17 #define AGG_CONV_ADAPTOR_VPGEN_INCLUDED
19 #include "agg_basics.h"
20 #include "agg_vertex_iterator.h"
25 //======================================================conv_adaptor_vpgen
26 template<class VertexSource
, class VPGen
> class conv_adaptor_vpgen
29 conv_adaptor_vpgen(VertexSource
& source
) : m_source(&source
) {}
31 void set_source(VertexSource
& source
) { m_source
= &source
; }
33 VPGen
& vpgen() { return m_vpgen
; }
34 const VPGen
& vpgen() const { return m_vpgen
; }
36 void rewind(unsigned path_id
);
37 unsigned vertex(double* x
, double* y
);
39 typedef conv_adaptor_vpgen
<VertexSource
, VPGen
> source_type
;
40 typedef vertex_iterator
<source_type
> iterator
;
41 iterator
begin(unsigned id
) { return iterator(*this, id
); }
42 iterator
end() { return iterator(path_cmd_stop
); }
45 conv_adaptor_vpgen(const conv_adaptor_vpgen
<VertexSource
, VPGen
>&);
46 const conv_adaptor_vpgen
<VertexSource
, VPGen
>&
47 operator = (const conv_adaptor_vpgen
<VertexSource
, VPGen
>&);
49 VertexSource
* m_source
;
53 unsigned m_poly_flags
;
59 //------------------------------------------------------------------------
60 template<class VertexSource
, class VPGen
>
61 void conv_adaptor_vpgen
<VertexSource
, VPGen
>::rewind(unsigned path_id
)
63 m_source
->rewind(path_id
);
72 //------------------------------------------------------------------------
73 template<class VertexSource
, class VPGen
>
74 unsigned conv_adaptor_vpgen
<VertexSource
, VPGen
>::vertex(double* x
, double* y
)
76 unsigned cmd
= path_cmd_stop
;
79 cmd
= m_vpgen
.vertex(x
, y
);
80 if(!is_stop(cmd
)) break;
82 if(m_poly_flags
&& !m_vpgen
.auto_unclose())
98 m_vpgen
.move_to(m_start_x
, m_start_y
);
104 cmd
= m_source
->vertex(&tx
, &ty
);
109 if(m_vpgen
.auto_close() && m_vertices
> 2)
111 m_vpgen
.line_to(m_start_x
, m_start_y
);
112 m_poly_flags
= path_cmd_end_poly
| path_flags_close
;
118 m_vpgen
.move_to(tx
, ty
);
125 m_vpgen
.line_to(tx
, ty
);
134 if(is_closed(cmd
) || m_vpgen
.auto_close())
136 if(m_vpgen
.auto_close()) m_poly_flags
|= path_flags_close
;
139 m_vpgen
.line_to(m_start_x
, m_start_y
);
147 if(m_vpgen
.auto_close() && m_vertices
> 2)
149 m_vpgen
.line_to(m_start_x
, m_start_y
);
150 m_poly_flags
= path_cmd_end_poly
| path_flags_close
;