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 //----------------------------------------------------------------------------
17 #include "agg_vpgen_clip_polyline.h"
21 static double clip_epsilon
= 1e-10;
24 //----------------------------------------------------------------------------
25 void vpgen_clip_polyline::reset()
31 //----------------------------------------------------------------------------
32 void vpgen_clip_polyline::move_to(double x
, double y
)
36 m_f1
= clipping_flags(x
, y
);
41 m_cmd
[0] = path_cmd_move_to
;
49 //----------------------------------------------------------------------------
50 bool vpgen_clip_polyline::move_point(double& x
, double& y
, unsigned& flags
)
54 if(flags
& (clip_x1
| clip_x2
))
56 bound
= (flags
& clip_x1
) ? m_clip_box
.x1
: m_clip_box
.x2
;
57 y
= (bound
- m_x1
) * (m_y2
- m_y1
) / (m_x2
- m_x1
) + m_y1
;
59 flags
= clipping_flags_y(y
);
61 if(fabs(m_y2
- m_y1
) < clip_epsilon
&& fabs(m_x2
- m_x1
) < clip_epsilon
)
65 if(flags
& (clip_y1
| clip_y2
))
67 bound
= (flags
& clip_y1
) ? m_clip_box
.y1
: m_clip_box
.y2
;
68 x
= (bound
- m_y1
) * (m_x2
- m_x1
) / (m_y2
- m_y1
) + m_x1
;
75 //----------------------------------------------------------------------------
76 void vpgen_clip_polyline::clip_line_segment()
78 if((m_f1
& m_f2
) == 0)
82 if(!move_point(m_x1
, m_y1
, m_f1
)) return;
86 m_cmd
[0] = path_cmd_move_to
;
91 if(!move_point(m_x2
, m_y2
, m_f2
)) return;
93 m_x
[m_num_vertices
] = m_x2
;
94 m_y
[m_num_vertices
] = m_y2
;
95 m_cmd
[m_num_vertices
++] = path_cmd_line_to
;
101 //----------------------------------------------------------------------------
102 void vpgen_clip_polyline::line_to(double x
, double y
)
106 unsigned f
= m_f2
= clipping_flags(m_x2
= x
, m_y2
= y
);
114 m_cmd
[0] = path_cmd_line_to
;
129 //----------------------------------------------------------------------------
130 unsigned vpgen_clip_polyline::vertex(double* x
, double* y
)
132 if(m_vertex
< m_num_vertices
)
136 return m_cmd
[m_vertex
++];
138 return path_cmd_stop
;