blob: 488db4a1ffaba5d0264dcf604349cd92b1919f32 [file] [log] [blame]
John Abd-El-Malek5110c472014-05-17 22:33:34 -07001
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"
20namespace agg
21{
Tom Sepez6fc8cbb2015-04-14 13:50:34 -070022struct curve4_points {
Dan Sinclair05df0752017-03-14 14:43:42 -040023 float cp[8];
John Abd-El-Malek5110c472014-05-17 22:33:34 -070024 curve4_points() {}
Dan Sinclair05df0752017-03-14 14:43:42 -040025 curve4_points(float x1, float y1,
26 float x2, float y2,
27 float x3, float y3,
28 float x4, float y4)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070029 {
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 }
Dan Sinclair05df0752017-03-14 14:43:42 -040039 void init(float x1, float y1,
40 float x2, float y2,
41 float x3, float y3,
42 float x4, float y4)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070043 {
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 }
Dan Sinclair05df0752017-03-14 14:43:42 -040053 float operator [] (unsigned i) const
John Abd-El-Malek5110c472014-05-17 22:33:34 -070054 {
55 return cp[i];
56 }
Dan Sinclair05df0752017-03-14 14:43:42 -040057 float& operator [] (unsigned i)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070058 {
59 return cp[i];
60 }
61};
Tom Sepez6fc8cbb2015-04-14 13:50:34 -070062class curve4_div
John Abd-El-Malek5110c472014-05-17 22:33:34 -070063{
64public:
65 curve4_div() :
John Abd-El-Malek5110c472014-05-17 22:33:34 -070066 m_count(0)
67 {}
Dan Sinclair05df0752017-03-14 14:43:42 -040068 curve4_div(float x1, float y1,
69 float x2, float y2,
70 float x3, float y3,
71 float x4, float y4) :
John Abd-El-Malek5110c472014-05-17 22:33:34 -070072 m_count(0)
73 {
74 init(x1, y1, x2, y2, x3, y3, x4, y4);
75 }
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 }
81 void reset()
82 {
83 m_points.remove_all();
84 m_count = 0;
85 }
Dan Sinclair05df0752017-03-14 14:43:42 -040086 void init(float x1, float y1,
87 float x2, float y2,
88 float x3, float y3,
89 float x4, float y4);
John Abd-El-Malek5110c472014-05-17 22:33:34 -070090 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 }
94 void rewind(unsigned)
95 {
96 m_count = 0;
97 }
Dan Sinclair05df0752017-03-14 14:43:42 -040098 unsigned vertex(float* x, float* y)
John Abd-El-Malek5110c472014-05-17 22:33:34 -070099 {
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 }
Dan Sinclair05df0752017-03-14 14:43:42 -0400108 unsigned vertex_flag(float* x, float* y, int& flag)
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700109 {
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 }
119 int count()
120 {
121 return m_points.size();
122 }
123private:
Dan Sinclair05df0752017-03-14 14:43:42 -0400124 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,
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700132 unsigned level);
Dan Sinclair05df0752017-03-14 14:43:42 -0400133 float m_distance_tolerance_square;
134 float m_distance_tolerance_manhattan;
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700135 unsigned m_count;
136 pod_deque<point_type> m_points;
137};
Tom Sepez6fc8cbb2015-04-14 13:50:34 -0700138class curve4
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700139{
140public:
141 curve4() {}
Dan Sinclair05df0752017-03-14 14:43:42 -0400142 curve4(float x1, float y1,
143 float x2, float y2,
144 float x3, float y3,
145 float x4, float y4)
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700146 {
147 init(x1, y1, x2, y2, x3, y3, x4, y4);
148 }
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 }
153 void reset()
154 {
155 m_curve_div.reset();
156 }
Dan Sinclair05df0752017-03-14 14:43:42 -0400157 void init(float x1, float y1,
158 float x2, float y2,
159 float x3, float y3,
160 float x4, float y4)
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700161 {
162 m_curve_div.init(x1, y1, x2, y2, x3, y3, x4, y4);
163 }
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 }
168 void rewind(unsigned path_id)
169 {
170 m_curve_div.rewind(path_id);
171 }
Dan Sinclair05df0752017-03-14 14:43:42 -0400172 unsigned vertex(float* x, float* y)
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700173 {
174 return m_curve_div.vertex(x, y);
175 }
Dan Sinclair05df0752017-03-14 14:43:42 -0400176 unsigned vertex_curve_flag(float* x, float* y, int& flag)
John Abd-El-Malek5110c472014-05-17 22:33:34 -0700177 {
178 return m_curve_div.vertex_flag(x, y, flag);
179 }
180 int count()
181 {
182 return m_curve_div.count();
183 }
184private:
185 curve4_div m_curve_div;
186};
187}
188#endif