25#ifndef AGG_CURVES_INCLUDED
26#define AGG_CURVES_INCLUDED
31AGG_INLINE
double calc_sq_distance(
double x1,
double y1,
double x2,
double y2) {
34 return dx * dx + dy * dy;
40enum curve_approximation_method_e {
51 curve4_points(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4) {
62 void init(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4) {
73 double operator[](
unsigned i)
const {
77 double& operator[](
unsigned i) {
108 curve4_inc(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
112 init(x1, y1, x2, y2,
x3,
y3,
x4,
y4);
119 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
127 void init(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4);
130 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
133 void approximation_method(curve_approximation_method_e) {}
135 curve_approximation_method_e approximation_method()
const {
139 void approximation_scale(
double s);
141 double approximation_scale()
const;
143 void angle_tolerance(
double) {}
145 double angle_tolerance()
const {
149 void cusp_limit(
double) {}
151 double cusp_limit()
const {
157 unsigned vertex(
double* x,
double* y);
184inline curve4_points catrom_to_bezier(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
193 return curve4_points(x2, y2, (-x1 + 6 * x2 +
x3) / 6, (-y1 + 6 * y2 +
y3) / 6, (x2 + 6 *
x3 -
x4) / 6,
198inline curve4_points catrom_to_bezier(
const curve4_points& cp) {
199 return catrom_to_bezier(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
203inline curve4_points ubspline_to_bezier(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
212 return curve4_points((x1 + 4 * x2 + x3) / 6, (y1 + 4 * y2 + y3) / 6, (4 * x2 + 2 * x3) / 6, (4 * y2 + 2 * y3) / 6,
213 (2 * x2 + 4 * x3) / 6, (2 * y2 + 4 * y3) / 6, (x2 + 4 * x3 + x4) / 6, (y2 + 4 * y3 + y4) / 6);
217inline curve4_points ubspline_to_bezier(
const curve4_points& cp) {
218 return ubspline_to_bezier(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
222inline curve4_points hermite_to_bezier(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
231 return curve4_points(x1, y1, (3 * x1 + x3) / 3, (3 * y1 + y3) / 3, (3 * x2 - x4) / 3, (3 * y2 - y4) / 3, x2, y2);
235inline curve4_points hermite_to_bezier(
const curve4_points& cp) {
236 return hermite_to_bezier(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
243 : m_approximation_scale(1.0),
244 m_distance_tolerance_square(0.0),
245 m_angle_tolerance(0.0),
249 curve4_div(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
250 : m_approximation_scale(1.0),
251 m_distance_tolerance_square(0.0),
252 m_angle_tolerance(0.0),
255 init(x1, y1, x2, y2,
x3,
y3,
x4,
y4);
259 : m_approximation_scale(1.0),
260 m_distance_tolerance_square(0.0),
261 m_angle_tolerance(0.0),
263 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
267 m_points.remove_all();
271 void init(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4);
274 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
277 void approximation_method(curve_approximation_method_e) {}
279 curve_approximation_method_e approximation_method()
const {
283 void approximation_scale(
double s) {
284 m_approximation_scale =
s;
287 double approximation_scale()
const {
288 return m_approximation_scale;
291 void angle_tolerance(
double a) {
292 m_angle_tolerance = a;
295 double angle_tolerance()
const {
296 return m_angle_tolerance;
299 void cusp_limit(
double v) {
300 m_cusp_limit = (
v == 0.0) ? 0.0 : pi -
v;
303 double cusp_limit()
const {
304 return (m_cusp_limit == 0.0) ? 0.0 : pi - m_cusp_limit;
307 void rewind(
unsigned) {
311 unsigned vertex(
double* x,
double* y) {
312 if (m_count >= m_points.size())
return path_cmd_stop;
313 const point_d&
p = m_points[m_count++];
316 return (m_count == 1) ? path_cmd_move_to : path_cmd_line_to;
320 void bezier(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4);
322 void recursive_bezier(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4,
325 double m_approximation_scale;
326 double m_distance_tolerance_square;
327 double m_angle_tolerance;
337 : m_approximation_method(curve_div) {}
339 curve4(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4)
340 : m_approximation_method(curve_div) {
341 init(x1, y1, x2, y2,
x3,
y3,
x4,
y4);
345 : m_approximation_method(curve_div) {
346 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
354 void init(
double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
double x4,
double y4) {
355 if (m_approximation_method == curve_inc) {
356 m_curve_inc.init(x1, y1, x2, y2,
x3,
y3,
x4,
y4);
358 m_curve_div.init(x1, y1, x2, y2,
x3,
y3,
x4,
y4);
363 init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
366 void approximation_method(curve_approximation_method_e
v) {
367 m_approximation_method =
v;
370 curve_approximation_method_e approximation_method()
const {
371 return m_approximation_method;
374 void approximation_scale(
double s) {
375 m_curve_inc.approximation_scale(
s);
376 m_curve_div.approximation_scale(
s);
379 double approximation_scale()
const {
380 return m_curve_inc.approximation_scale();
383 void angle_tolerance(
double v) {
384 m_curve_div.angle_tolerance(
v);
387 double angle_tolerance()
const {
388 return m_curve_div.angle_tolerance();
391 void cusp_limit(
double v) {
392 m_curve_div.cusp_limit(
v);
395 double cusp_limit()
const {
396 return m_curve_div.cusp_limit();
399 void rewind(
unsigned path_id) {
400 if (m_approximation_method == curve_inc) {
407 unsigned vertex(
double* x,
double* y) {
408 if (m_approximation_method == curve_inc) {
409 return m_curve_inc.vertex(x, y);
411 return m_curve_div.vertex(x, y);
417 curve_approximation_method_e m_approximation_method;
Definition agg_curves.h:240
Definition agg_curves.h:83
Definition agg_curves.h:334
Definition agg_array.h:259
Definition agg_curves.h:46