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 #include "agg_vpgen_clip_polygon.h"
17 #include "agg_clip_liang_barsky.h"
22 //------------------------------------------------------------------------
23 // Determine the clipping code of the vertex according to the
24 // Cyrus-Beck line clipping algorithm
29 // -------+--------+-------- clip_box.y2
33 // -------+--------+-------- clip_box.y1
37 // clip_box.x1 clip_box.x2
40 unsigned vpgen_clip_polygon::clipping_flags(double x
, double y
)
44 if(y
> m_clip_box
.y2
) return 6;
45 if(y
< m_clip_box
.y1
) return 12;
51 if(y
> m_clip_box
.y2
) return 3;
52 if(y
< m_clip_box
.y1
) return 9;
56 if(y
> m_clip_box
.y2
) return 2;
57 if(y
< m_clip_box
.y1
) return 8;
62 //----------------------------------------------------------------------------
63 void vpgen_clip_polygon::reset()
69 //----------------------------------------------------------------------------
70 void vpgen_clip_polygon::move_to(double x
, double y
)
74 m_clip_flags
= clipping_flags(x
, y
);
83 m_cmd
= path_cmd_move_to
;
87 //----------------------------------------------------------------------------
88 void vpgen_clip_polygon::line_to(double x
, double y
)
92 unsigned flags
= clipping_flags(x
, y
);
94 if(m_clip_flags
== flags
)
105 m_num_vertices
= clip_liang_barsky(m_x1
, m_y1
,
111 m_clip_flags
= flags
;
117 //----------------------------------------------------------------------------
118 unsigned vpgen_clip_polygon::vertex(double* x
, double* y
)
120 if(m_vertex
< m_num_vertices
)
125 unsigned cmd
= m_cmd
;
126 m_cmd
= path_cmd_line_to
;
129 return path_cmd_stop
;