update dev300-m58
[ooovba.git] / agg / inc / agg_vpgen_clip_polyline.h
blob07e30e7bce20229f75e4142dba8466d70b5463f3
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 #ifndef AGG_VPGEN_CLIP_POLYLINE_INCLUDED
17 #define AGG_VPGEN_CLIP_POLYLINE_INCLUDED
19 #include "agg_basics.h"
21 namespace agg
24 //======================================================vpgen_clip_polyline
26 // See Implementation agg_vpgen_clip_polyline.cpp
28 class vpgen_clip_polyline
30 public:
31 vpgen_clip_polyline() :
32 m_clip_box(0, 0, 1, 1),
33 m_x1(0),
34 m_y1(0),
35 m_f1(0),
36 m_x2(0),
37 m_y2(0),
38 m_f2(0),
39 m_num_vertices(0),
40 m_vertex(0)
44 void clip_box(double _x1, double _y1, double _x2, double _y2)
46 m_clip_box.x1 = _x1;
47 m_clip_box.y1 = _y1;
48 m_clip_box.x2 = _x2;
49 m_clip_box.y2 = _y2;
50 m_clip_box.normalize();
54 double x1() const { return m_clip_box.x1; }
55 double y1() const { return m_clip_box.y1; }
56 double x2() const { return m_clip_box.x2; }
57 double y2() const { return m_clip_box.y2; }
59 static bool auto_close() { return false; }
60 static bool auto_unclose() { return true; }
62 void reset();
63 void move_to(double x, double y);
64 void line_to(double x, double y);
65 unsigned vertex(double* x, double* y);
67 private:
68 enum clipping_flags_def
70 clip_x1 = 1,
71 clip_x2 = 2,
72 clip_y1 = 4,
73 clip_y2 = 8
76 // Determine the clipping code of the vertex according to the
77 // Cyrus-Beck line clipping algorithm
78 //--------------------------------------------------------------------
79 unsigned clipping_flags_x(double x)
81 unsigned f = 0;
82 if(x < m_clip_box.x1) f |= clip_x1;
83 if(x > m_clip_box.x2) f |= clip_x2;
84 return f;
87 unsigned clipping_flags_y(double y)
89 unsigned f = 0;
90 if(y < m_clip_box.y1) f |= clip_y1;
91 if(y > m_clip_box.y2) f |= clip_y2;
92 return f;
95 unsigned clipping_flags(double x, double y)
97 return clipping_flags_x(x) | clipping_flags_y(y);
100 bool move_point(double& x, double& y, unsigned& flags);
101 void clip_line_segment();
103 private:
104 rect_d m_clip_box;
105 double m_x1;
106 double m_y1;
107 unsigned m_f1;
108 double m_x2;
109 double m_y2;
110 unsigned m_f2;
111 double m_x[2];
112 double m_y[2];
113 unsigned m_cmd[2];
114 unsigned m_num_vertices;
115 unsigned m_vertex;
121 #endif