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 //----------------------------------------------------------------------------
18 //----------------------------------------------------------------------------
20 #include "agg_vcgen_stroke.h"
21 #include "agg_shorten_path.h"
26 //------------------------------------------------------------------------
27 vcgen_stroke::vcgen_stroke() :
32 m_inner_miter_limit(1.0 + 1.0/64.0),
36 m_line_join(miter_join
),
37 m_inner_line_join(miter_join_revert
),
46 //------------------------------------------------------------------------
47 void vcgen_stroke::miter_limit_theta(double t
)
49 m_miter_limit
= 1.0 / sin(t
* 0.5) ;
53 //------------------------------------------------------------------------
54 void vcgen_stroke::remove_all()
56 m_src_vertices
.remove_all();
62 //------------------------------------------------------------------------
63 void vcgen_stroke::add_vertex(double x
, double y
, unsigned cmd
)
68 m_src_vertices
.modify_last(vertex_dist(x
, y
));
74 m_src_vertices
.add(vertex_dist(x
, y
));
78 m_closed
= get_close_flag(cmd
);
84 //------------------------------------------------------------------------
85 void vcgen_stroke::rewind(unsigned)
87 if(m_status
== initial
)
89 m_src_vertices
.close(m_closed
!= 0);
90 shorten_path(m_src_vertices
, m_shorten
, m_closed
);
91 if(m_src_vertices
.size() < 3) m_closed
= 0;
99 //------------------------------------------------------------------------
100 unsigned vcgen_stroke::vertex(double* x
, double* y
)
102 unsigned cmd
= path_cmd_line_to
;
111 if(m_src_vertices
.size() < 2 + unsigned(m_closed
!= 0))
116 m_status
= m_closed
? outline1
: cap1
;
117 cmd
= path_cmd_move_to
;
123 stroke_calc_cap(m_out_vertices
,
126 m_src_vertices
[0].dist
,
131 m_prev_status
= outline1
;
132 m_status
= out_vertices
;
137 stroke_calc_cap(m_out_vertices
,
138 m_src_vertices
[m_src_vertices
.size() - 1],
139 m_src_vertices
[m_src_vertices
.size() - 2],
140 m_src_vertices
[m_src_vertices
.size() - 2].dist
,
144 m_prev_status
= outline2
;
145 m_status
= out_vertices
;
152 if(m_src_vertex
>= m_src_vertices
.size())
154 m_prev_status
= close_first
;
155 m_status
= end_poly1
;
161 if(m_src_vertex
>= m_src_vertices
.size() - 1)
167 stroke_calc_join(m_out_vertices
,
168 m_src_vertices
.prev(m_src_vertex
),
169 m_src_vertices
.curr(m_src_vertex
),
170 m_src_vertices
.next(m_src_vertex
),
171 m_src_vertices
.prev(m_src_vertex
).dist
,
172 m_src_vertices
.curr(m_src_vertex
).dist
,
180 m_prev_status
= m_status
;
181 m_status
= out_vertices
;
187 cmd
= path_cmd_move_to
;
190 if(m_src_vertex
<= unsigned(m_closed
== 0))
192 m_status
= end_poly2
;
193 m_prev_status
= stop
;
198 stroke_calc_join(m_out_vertices
,
199 m_src_vertices
.next(m_src_vertex
),
200 m_src_vertices
.curr(m_src_vertex
),
201 m_src_vertices
.prev(m_src_vertex
),
202 m_src_vertices
.curr(m_src_vertex
).dist
,
203 m_src_vertices
.prev(m_src_vertex
).dist
,
211 m_prev_status
= m_status
;
212 m_status
= out_vertices
;
217 if(m_out_vertex
>= m_out_vertices
.size())
219 m_status
= m_prev_status
;
223 const point_type
& c
= m_out_vertices
[m_out_vertex
++];
231 m_status
= m_prev_status
;
232 return (unsigned)path_cmd_end_poly
| (unsigned)path_flags_close
| (unsigned)path_flags_ccw
;
235 m_status
= m_prev_status
;
236 return (unsigned)path_cmd_end_poly
| (unsigned)path_flags_close
| (unsigned)path_flags_cw
;