• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 //----------------------------------------------------------------------------
3 // Anti-Grain Geometry - Version 2.3
4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 // Copyright (C) 2005 Tony Juricic (tonygeek@yahoo.com)
6 //
7 // Permission to copy, use, modify, sell and distribute this software
8 // is granted provided this copyright notice appears in all copies.
9 // This software is provided "as is" without express or implied
10 // warranty, and with no claim as to its suitability for any purpose.
11 //
12 //----------------------------------------------------------------------------
13 // Contact: mcseem@antigrain.com
14 //          mcseemagg@yahoo.com
15 //          http://www.antigrain.com
16 //----------------------------------------------------------------------------
17 #ifndef AGG_CURVES_INCLUDED
18 #define AGG_CURVES_INCLUDED
19 #include "agg_array.h"
20 namespace agg
21 {
22 struct curve4_points  {
23     float cp[8];
curve4_pointscurve4_points24     curve4_points() {}
curve4_pointscurve4_points25     curve4_points(float x1, float y1,
26                   float x2, float y2,
27                   float x3, float y3,
28                   float x4, float y4)
29     {
30         cp[0] = x1;
31         cp[1] = y1;
32         cp[2] = x2;
33         cp[3] = y2;
34         cp[4] = x3;
35         cp[5] = y3;
36         cp[6] = x4;
37         cp[7] = y4;
38     }
initcurve4_points39     void init(float x1, float y1,
40               float x2, float y2,
41               float x3, float y3,
42               float x4, float y4)
43     {
44         cp[0] = x1;
45         cp[1] = y1;
46         cp[2] = x2;
47         cp[3] = y2;
48         cp[4] = x3;
49         cp[5] = y3;
50         cp[6] = x4;
51         cp[7] = y4;
52     }
53     float  operator [] (unsigned i) const
54     {
55         return cp[i];
56     }
57     float& operator [] (unsigned i)
58     {
59         return cp[i];
60     }
61 };
62 class curve4_div
63 {
64 public:
curve4_div()65     curve4_div() :
66         m_count(0)
67     {}
curve4_div(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)68     curve4_div(float x1, float y1,
69                float x2, float y2,
70                float x3, float y3,
71                float x4, float y4) :
72         m_count(0)
73     {
74         init(x1, y1, x2, y2, x3, y3, x4, y4);
75     }
curve4_div(const curve4_points & cp)76     curve4_div(const curve4_points& cp) :
77         m_count(0)
78     {
79         init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
80     }
reset()81     void reset()
82     {
83         m_points.remove_all();
84         m_count = 0;
85     }
86     void init(float x1, float y1,
87               float x2, float y2,
88               float x3, float y3,
89               float x4, float y4);
init(const curve4_points & cp)90     void init(const curve4_points& cp)
91     {
92         init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
93     }
rewind(unsigned)94     void rewind(unsigned)
95     {
96         m_count = 0;
97     }
vertex(float * x,float * y)98     unsigned vertex(float* x, float* y)
99     {
100         if(m_count >= m_points.size()) {
101             return path_cmd_stop;
102         }
103         const point_type& p = m_points[m_count++];
104         *x = p.x;
105         *y = p.y;
106         return (m_count == 1) ? path_cmd_move_to : path_cmd_line_to;
107     }
vertex_flag(float * x,float * y,int & flag)108     unsigned vertex_flag(float* x, float* y, int& flag)
109     {
110         if(m_count >= m_points.size()) {
111             return path_cmd_stop;
112         }
113         const point_type& p = m_points[m_count++];
114         *x = p.x;
115         *y = p.y;
116         flag = p.flag;
117         return (m_count == 1) ? path_cmd_move_to : path_cmd_line_to;
118     }
count()119     int count()
120     {
121         return m_points.size();
122     }
123 private:
124     void bezier(float x1, float y1,
125                 float x2, float y2,
126                 float x3, float y3,
127                 float x4, float y4);
128     void recursive_bezier(float x1, float y1,
129                           float x2, float y2,
130                           float x3, float y3,
131                           float x4, float y4,
132                           unsigned level);
133     float    m_distance_tolerance_square;
134     float    m_distance_tolerance_manhattan;
135     unsigned              m_count;
136     pod_deque<point_type> m_points;
137 };
138 class curve4
139 {
140 public:
curve4()141     curve4() {}
curve4(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)142     curve4(float x1, float y1,
143            float x2, float y2,
144            float x3, float y3,
145            float x4, float y4)
146     {
147         init(x1, y1, x2, y2, x3, y3, x4, y4);
148     }
curve4(const curve4_points & cp)149     curve4(const curve4_points& cp)
150     {
151         init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
152     }
reset()153     void reset()
154     {
155         m_curve_div.reset();
156     }
init(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)157     void init(float x1, float y1,
158               float x2, float y2,
159               float x3, float y3,
160               float x4, float y4)
161     {
162         m_curve_div.init(x1, y1, x2, y2, x3, y3, x4, y4);
163     }
init(const curve4_points & cp)164     void init(const curve4_points& cp)
165     {
166         init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
167     }
rewind(unsigned path_id)168     void rewind(unsigned path_id)
169     {
170         m_curve_div.rewind(path_id);
171     }
vertex(float * x,float * y)172     unsigned vertex(float* x, float* y)
173     {
174         return m_curve_div.vertex(x, y);
175     }
vertex_curve_flag(float * x,float * y,int & flag)176     unsigned vertex_curve_flag(float* x, float* y, int& flag)
177     {
178         return m_curve_div.vertex_flag(x, y, flag);
179     }
count()180     int count()
181     {
182         return m_curve_div.count();
183     }
184 private:
185     curve4_div m_curve_div;
186 };
187 }
188 #endif
189