merge the formfield patch from ooo-build
[ooovba.git] / agg / source / agg_vpgen_clip_polygon.cpp
blob70f6e218c1e086a71afc2ba5a71f76a9ad743d5c
1 //----------------------------------------------------------------------------
2 // Anti-Grain Geometry - Version 2.3
3 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4 //
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.
9 //
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"
19 namespace agg
22 //------------------------------------------------------------------------
23 // Determine the clipping code of the vertex according to the
24 // Cyrus-Beck line clipping algorithm
26 // | |
27 // 0110 | 0010 | 0011
28 // | |
29 // -------+--------+-------- clip_box.y2
30 // | |
31 // 0100 | 0000 | 0001
32 // | |
33 // -------+--------+-------- clip_box.y1
34 // | |
35 // 1100 | 1000 | 1001
36 // | |
37 // clip_box.x1 clip_box.x2
39 //
40 unsigned vpgen_clip_polygon::clipping_flags(double x, double y)
42 if(x < m_clip_box.x1)
44 if(y > m_clip_box.y2) return 6;
45 if(y < m_clip_box.y1) return 12;
46 return 4;
49 if(x > m_clip_box.x2)
51 if(y > m_clip_box.y2) return 3;
52 if(y < m_clip_box.y1) return 9;
53 return 1;
56 if(y > m_clip_box.y2) return 2;
57 if(y < m_clip_box.y1) return 8;
59 return 0;
62 //----------------------------------------------------------------------------
63 void vpgen_clip_polygon::reset()
65 m_vertex = 0;
66 m_num_vertices = 0;
69 //----------------------------------------------------------------------------
70 void vpgen_clip_polygon::move_to(double x, double y)
72 m_vertex = 0;
73 m_num_vertices = 0;
74 m_clip_flags = clipping_flags(x, y);
75 if(m_clip_flags == 0)
77 m_x[0] = x;
78 m_y[0] = y;
79 m_num_vertices = 1;
81 m_x1 = x;
82 m_y1 = y;
83 m_cmd = path_cmd_move_to;
87 //----------------------------------------------------------------------------
88 void vpgen_clip_polygon::line_to(double x, double y)
90 m_vertex = 0;
91 m_num_vertices = 0;
92 unsigned flags = clipping_flags(x, y);
94 if(m_clip_flags == flags)
96 if(flags == 0)
98 m_x[0] = x;
99 m_y[0] = y;
100 m_num_vertices = 1;
103 else
105 m_num_vertices = clip_liang_barsky(m_x1, m_y1,
106 x, y,
107 m_clip_box,
108 m_x, m_y);
111 m_clip_flags = flags;
112 m_x1 = x;
113 m_y1 = y;
117 //----------------------------------------------------------------------------
118 unsigned vpgen_clip_polygon::vertex(double* x, double* y)
120 if(m_vertex < m_num_vertices)
122 *x = m_x[m_vertex];
123 *y = m_y[m_vertex];
124 ++m_vertex;
125 unsigned cmd = m_cmd;
126 m_cmd = path_cmd_line_to;
127 return cmd;
129 return path_cmd_stop;