3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
4
// Copyright (C) 2005 Tony Juricic (tonygeek@yahoo.com)
6
// Permission to copy, use, modify, sell and distribute this software
7
// is granted provided this copyright notice appears in all copies.
6
// Permission to copy, use, modify, sell and distribute this software
7
// is granted provided this copyright notice appears in all copies.
8
8
// This software is provided "as is" without express or implied
9
9
// warranty, and with no claim as to its suitability for any purpose.
39
39
m_num_steps(0), m_step(0), m_scale(1.0) { }
41
curve3_inc(double x1, double y1,
41
curve3_inc(double x1, double y1,
43
43
double x3, double y3) :
44
m_num_steps(0), m_step(0), m_scale(1.0)
44
m_num_steps(0), m_step(0), m_scale(1.0)
46
46
init(x1, y1, x2, y2, x3, y3);
49
49
void reset() { m_num_steps = 0; m_step = -1; }
50
void init(double x1, double y1,
50
void init(double x1, double y1,
52
52
double x3, double y3);
54
54
void approximation_method(curve_approximation_method_e) {}
98
98
m_approximation_scale(1.0),
99
99
m_angle_tolerance(0.0),
103
curve3_div(double x1, double y1,
104
double x2, double y2,
103
curve3_div(double x1, double y1,
104
double x2, double y2,
105
105
double x3, double y3) :
106
106
m_approximation_scale(1.0),
107
107
m_angle_tolerance(0.0),
110
110
init(x1, y1, x2, y2, x3, y3);
113
113
void reset() { m_points.remove_all(); m_count = 0; }
114
void init(double x1, double y1,
115
double x2, double y2,
114
void init(double x1, double y1,
115
double x2, double y2,
116
116
double x3, double y3);
118
118
void approximation_method(curve_approximation_method_e) {}
145
void bezier(double x1, double y1,
146
double x2, double y2,
145
void bezier(double x1, double y1,
146
double x2, double y2,
147
147
double x3, double y3);
148
void recursive_bezier(double x1, double y1,
149
double x2, double y2,
148
void recursive_bezier(double x1, double y1,
149
double x2, double y2,
150
150
double x3, double y3,
198
198
m_num_steps(0), m_step(0), m_scale(1.0) { }
200
curve4_inc(double x1, double y1,
201
double x2, double y2,
200
curve4_inc(double x1, double y1,
201
double x2, double y2,
202
202
double x3, double y3,
203
203
double x4, double y4) :
204
m_num_steps(0), m_step(0), m_scale(1.0)
204
m_num_steps(0), m_step(0), m_scale(1.0)
206
206
init(x1, y1, x2, y2, x3, y3, x4, y4);
209
209
curve4_inc(const curve4_points& cp) :
210
m_num_steps(0), m_step(0), m_scale(1.0)
210
m_num_steps(0), m_step(0), m_scale(1.0)
212
212
init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
215
215
void reset() { m_num_steps = 0; m_step = -1; }
216
void init(double x1, double y1,
217
double x2, double y2,
216
void init(double x1, double y1,
217
double x2, double y2,
218
218
double x3, double y3,
219
219
double x4, double y4);
246
246
double m_start_y;
258
258
double m_saved_fy;
260
260
double m_saved_dfy;
262
262
double m_saved_ddfy;
267
267
//-------------------------------------------------------catrom_to_bezier
268
inline curve4_points catrom_to_bezier(double x1, double y1,
269
double x2, double y2,
268
inline curve4_points catrom_to_bezier(double x1, double y1,
269
double x2, double y2,
270
270
double x3, double y3,
271
271
double x4, double y4)
293
293
inline curve4_points
294
294
catrom_to_bezier(const curve4_points& cp)
296
return catrom_to_bezier(cp[0], cp[1], cp[2], cp[3],
296
return catrom_to_bezier(cp[0], cp[1], cp[2], cp[3],
297
297
cp[4], cp[5], cp[6], cp[7]);
302
302
//-----------------------------------------------------ubspline_to_bezier
303
inline curve4_points ubspline_to_bezier(double x1, double y1,
304
double x2, double y2,
303
inline curve4_points ubspline_to_bezier(double x1, double y1,
304
double x2, double y2,
305
305
double x3, double y3,
306
306
double x4, double y4)
327
327
//-----------------------------------------------------------------------
329
329
ubspline_to_bezier(const curve4_points& cp)
331
return ubspline_to_bezier(cp[0], cp[1], cp[2], cp[3],
331
return ubspline_to_bezier(cp[0], cp[1], cp[2], cp[3],
332
332
cp[4], cp[5], cp[6], cp[7]);
338
338
//------------------------------------------------------hermite_to_bezier
339
inline curve4_points hermite_to_bezier(double x1, double y1,
340
double x2, double y2,
339
inline curve4_points hermite_to_bezier(double x1, double y1,
340
double x2, double y2,
341
341
double x3, double y3,
342
342
double x4, double y4)
364
364
//-----------------------------------------------------------------------
366
366
hermite_to_bezier(const curve4_points& cp)
368
return hermite_to_bezier(cp[0], cp[1], cp[2], cp[3],
368
return hermite_to_bezier(cp[0], cp[1], cp[2], cp[3],
369
369
cp[4], cp[5], cp[6], cp[7]);
378
378
m_approximation_scale(1.0),
379
379
m_angle_tolerance(0.0),
380
380
m_cusp_limit(0.0),
384
curve4_div(double x1, double y1,
385
double x2, double y2,
384
curve4_div(double x1, double y1,
385
double x2, double y2,
386
386
double x3, double y3,
387
387
double x4, double y4) :
388
388
m_approximation_scale(1.0),
389
389
m_angle_tolerance(0.0),
390
390
m_cusp_limit(0.0),
393
393
init(x1, y1, x2, y2, x3, y3, x4, y4);
397
397
m_approximation_scale(1.0),
398
398
m_angle_tolerance(0.0),
401
401
init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
404
404
void reset() { m_points.remove_all(); m_count = 0; }
405
void init(double x1, double y1,
406
double x2, double y2,
405
void init(double x1, double y1,
406
double x2, double y2,
407
407
double x3, double y3,
408
408
double x4, double y4);
415
415
void approximation_method(curve_approximation_method_e) {}
417
curve_approximation_method_e approximation_method() const
417
curve_approximation_method_e approximation_method() const
422
422
void approximation_scale(double s) { m_approximation_scale = s; }
425
425
void angle_tolerance(double a) { m_angle_tolerance = a; }
426
426
double angle_tolerance() const { return m_angle_tolerance; }
428
void cusp_limit(double v)
430
m_cusp_limit = (v == 0.0) ? 0.0 : pi - v;
428
void cusp_limit(double v)
430
m_cusp_limit = (v == 0.0) ? 0.0 : pi - v;
433
double cusp_limit() const
435
return (m_cusp_limit == 0.0) ? 0.0 : pi - m_cusp_limit;
433
double cusp_limit() const
435
return (m_cusp_limit == 0.0) ? 0.0 : pi - m_cusp_limit;
438
438
void rewind(unsigned)
453
void bezier(double x1, double y1,
454
double x2, double y2,
455
double x3, double y3,
453
void bezier(double x1, double y1,
454
double x2, double y2,
455
double x3, double y3,
456
456
double x4, double y4);
458
void recursive_bezier(double x1, double y1,
459
double x2, double y2,
460
double x3, double y3,
458
void recursive_bezier(double x1, double y1,
459
double x2, double y2,
460
double x3, double y3,
461
461
double x4, double y4,
477
477
curve3() : m_approximation_method(curve_div) {}
478
curve3(double x1, double y1,
479
double x2, double y2,
478
curve3(double x1, double y1,
479
double x2, double y2,
480
480
double x3, double y3) :
481
481
m_approximation_method(curve_div)
483
483
init(x1, y1, x2, y2, x3, y3);
488
488
m_curve_inc.reset();
489
489
m_curve_div.reset();
492
void init(double x1, double y1,
493
double x2, double y2,
492
void init(double x1, double y1,
493
double x2, double y2,
494
494
double x3, double y3)
496
if(m_approximation_method == curve_inc)
496
if(m_approximation_method == curve_inc)
498
498
m_curve_inc.init(x1, y1, x2, y2, x3, y3);
506
void approximation_method(curve_approximation_method_e v)
508
m_approximation_method = v;
511
curve_approximation_method_e approximation_method() const
513
return m_approximation_method;
516
void approximation_scale(double s)
506
void approximation_method(curve_approximation_method_e v)
508
m_approximation_method = v;
511
curve_approximation_method_e approximation_method() const
513
return m_approximation_method;
516
void approximation_scale(double s)
518
518
m_curve_inc.approximation_scale(s);
519
519
m_curve_div.approximation_scale(s);
522
double approximation_scale() const
524
return m_curve_inc.approximation_scale();
527
void angle_tolerance(double a)
529
m_curve_div.angle_tolerance(a);
532
double angle_tolerance() const
534
return m_curve_div.angle_tolerance();
537
void cusp_limit(double v)
539
m_curve_div.cusp_limit(v);
542
double cusp_limit() const
544
return m_curve_div.cusp_limit();
522
double approximation_scale() const
524
return m_curve_inc.approximation_scale();
527
void angle_tolerance(double a)
529
m_curve_div.angle_tolerance(a);
532
double angle_tolerance() const
534
return m_curve_div.angle_tolerance();
537
void cusp_limit(double v)
539
m_curve_div.cusp_limit(v);
542
double cusp_limit() const
544
return m_curve_div.cusp_limit();
547
547
void rewind(unsigned path_id)
549
if(m_approximation_method == curve_inc)
549
if(m_approximation_method == curve_inc)
551
551
m_curve_inc.rewind(path_id);
559
559
unsigned vertex(double* x, double* y)
561
if(m_approximation_method == curve_inc)
561
if(m_approximation_method == curve_inc)
563
563
return m_curve_inc.vertex(x, y);
582
582
curve4() : m_approximation_method(curve_div) {}
583
curve4(double x1, double y1,
584
double x2, double y2,
583
curve4(double x1, double y1,
584
double x2, double y2,
585
585
double x3, double y3,
586
double x4, double y4) :
586
double x4, double y4) :
587
587
m_approximation_method(curve_div)
589
589
init(x1, y1, x2, y2, x3, y3, x4, y4);
592
592
curve4(const curve4_points& cp) :
593
593
m_approximation_method(curve_div)
595
595
init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
600
600
m_curve_inc.reset();
601
601
m_curve_div.reset();
604
void init(double x1, double y1,
605
double x2, double y2,
604
void init(double x1, double y1,
605
double x2, double y2,
606
606
double x3, double y3,
607
607
double x4, double y4)
609
if(m_approximation_method == curve_inc)
609
if(m_approximation_method == curve_inc)
611
611
m_curve_inc.init(x1, y1, x2, y2, x3, y3, x4, y4);
621
621
init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
624
void approximation_method(curve_approximation_method_e v)
626
m_approximation_method = v;
629
curve_approximation_method_e approximation_method() const
631
return m_approximation_method;
634
void approximation_scale(double s)
624
void approximation_method(curve_approximation_method_e v)
626
m_approximation_method = v;
629
curve_approximation_method_e approximation_method() const
631
return m_approximation_method;
634
void approximation_scale(double s)
636
636
m_curve_inc.approximation_scale(s);
637
637
m_curve_div.approximation_scale(s);
639
639
double approximation_scale() const { return m_curve_inc.approximation_scale(); }
641
void angle_tolerance(double v)
643
m_curve_div.angle_tolerance(v);
646
double angle_tolerance() const
648
return m_curve_div.angle_tolerance();
651
void cusp_limit(double v)
653
m_curve_div.cusp_limit(v);
656
double cusp_limit() const
658
return m_curve_div.cusp_limit();
641
void angle_tolerance(double v)
643
m_curve_div.angle_tolerance(v);
646
double angle_tolerance() const
648
return m_curve_div.angle_tolerance();
651
void cusp_limit(double v)
653
m_curve_div.cusp_limit(v);
656
double cusp_limit() const
658
return m_curve_div.cusp_limit();
661
661
void rewind(unsigned path_id)
663
if(m_approximation_method == curve_inc)
663
if(m_approximation_method == curve_inc)
665
665
m_curve_inc.rewind(path_id);
673
673
unsigned vertex(double* x, double* y)
675
if(m_approximation_method == curve_inc)
675
if(m_approximation_method == curve_inc)
677
677
return m_curve_inc.vertex(x, y);