~kalon33/corsix-th/master

« back to all changes in this revision

Viewing changes to agg/include/agg_curves.h

  • Committer: corsixth.bot at gmail
  • Date: 2014-03-31 23:30:23 UTC
  • Revision ID: svn-v4:c39591fa-788f-11de-a72b-d90af8dea425:trunk:2687
Remove trailing whitespaces in .h, .cpp, .c and .lua files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
4
4
// Copyright (C) 2005 Tony Juricic (tonygeek@yahoo.com)
5
5
//
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.
10
10
//
30
30
        curve_inc,
31
31
        curve_div
32
32
    };
33
 
    
 
33
 
34
34
    //--------------------------------------------------------------curve3_inc
35
35
    class curve3_inc
36
36
    {
38
38
        curve3_inc() :
39
39
          m_num_steps(0), m_step(0), m_scale(1.0) { }
40
40
 
41
 
        curve3_inc(double x1, double y1, 
42
 
                   double x2, double y2, 
 
41
        curve3_inc(double x1, double y1,
 
42
                   double x2, double y2,
43
43
                   double x3, double y3) :
44
 
            m_num_steps(0), m_step(0), m_scale(1.0) 
45
 
        { 
 
44
            m_num_steps(0), m_step(0), m_scale(1.0)
 
45
        {
46
46
            init(x1, y1, x2, y2, x3, y3);
47
47
        }
48
48
 
49
49
        void reset() { m_num_steps = 0; m_step = -1; }
50
 
        void init(double x1, double y1, 
51
 
                  double x2, double y2, 
 
50
        void init(double x1, double y1,
 
51
                  double x2, double y2,
52
52
                  double x3, double y3);
53
53
 
54
54
        void approximation_method(curve_approximation_method_e) {}
70
70
        int      m_num_steps;
71
71
        int      m_step;
72
72
        double   m_scale;
73
 
        double   m_start_x; 
 
73
        double   m_start_x;
74
74
        double   m_start_y;
75
 
        double   m_end_x; 
 
75
        double   m_end_x;
76
76
        double   m_end_y;
77
 
        double   m_fx; 
 
77
        double   m_fx;
78
78
        double   m_fy;
79
 
        double   m_dfx; 
 
79
        double   m_dfx;
80
80
        double   m_dfy;
81
 
        double   m_ddfx; 
 
81
        double   m_ddfx;
82
82
        double   m_ddfy;
83
 
        double   m_saved_fx; 
 
83
        double   m_saved_fx;
84
84
        double   m_saved_fy;
85
 
        double   m_saved_dfx; 
 
85
        double   m_saved_dfx;
86
86
        double   m_saved_dfy;
87
87
    };
88
88
 
94
94
    class curve3_div
95
95
    {
96
96
    public:
97
 
        curve3_div() : 
 
97
        curve3_div() :
98
98
            m_approximation_scale(1.0),
99
99
            m_angle_tolerance(0.0),
100
100
            m_count(0)
101
101
        {}
102
102
 
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),
108
108
            m_count(0)
109
 
        { 
 
109
        {
110
110
            init(x1, y1, x2, y2, x3, y3);
111
111
        }
112
112
 
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);
117
117
 
118
118
        void approximation_method(curve_approximation_method_e) {}
142
142
        }
143
143
 
144
144
    private:
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,
151
151
                              unsigned level);
152
152
 
197
197
        curve4_inc() :
198
198
            m_num_steps(0), m_step(0), m_scale(1.0) { }
199
199
 
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) 
205
 
        { 
 
204
            m_num_steps(0), m_step(0), m_scale(1.0)
 
205
        {
206
206
            init(x1, y1, x2, y2, x3, y3, x4, y4);
207
207
        }
208
208
 
209
209
        curve4_inc(const curve4_points& cp) :
210
 
            m_num_steps(0), m_step(0), m_scale(1.0) 
211
 
        { 
 
210
            m_num_steps(0), m_step(0), m_scale(1.0)
 
211
        {
212
212
            init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
213
213
        }
214
214
 
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);
220
220
 
242
242
        int      m_num_steps;
243
243
        int      m_step;
244
244
        double   m_scale;
245
 
        double   m_start_x; 
 
245
        double   m_start_x;
246
246
        double   m_start_y;
247
 
        double   m_end_x; 
 
247
        double   m_end_x;
248
248
        double   m_end_y;
249
 
        double   m_fx; 
 
249
        double   m_fx;
250
250
        double   m_fy;
251
 
        double   m_dfx; 
 
251
        double   m_dfx;
252
252
        double   m_dfy;
253
 
        double   m_ddfx; 
 
253
        double   m_ddfx;
254
254
        double   m_ddfy;
255
 
        double   m_dddfx; 
 
255
        double   m_dddfx;
256
256
        double   m_dddfy;
257
 
        double   m_saved_fx; 
 
257
        double   m_saved_fx;
258
258
        double   m_saved_fy;
259
 
        double   m_saved_dfx; 
 
259
        double   m_saved_dfx;
260
260
        double   m_saved_dfy;
261
 
        double   m_saved_ddfx; 
 
261
        double   m_saved_ddfx;
262
262
        double   m_saved_ddfy;
263
263
    };
264
264
 
265
265
 
266
266
 
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)
272
272
    {
293
293
    inline curve4_points
294
294
    catrom_to_bezier(const curve4_points& cp)
295
295
    {
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]);
298
298
    }
299
299
 
300
300
 
301
301
 
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)
307
307
    {
325
325
 
326
326
 
327
327
    //-----------------------------------------------------------------------
328
 
    inline curve4_points 
 
328
    inline curve4_points
329
329
    ubspline_to_bezier(const curve4_points& cp)
330
330
    {
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]);
333
333
    }
334
334
 
336
336
 
337
337
 
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)
343
343
    {
362
362
 
363
363
 
364
364
    //-----------------------------------------------------------------------
365
 
    inline curve4_points 
 
365
    inline curve4_points
366
366
    hermite_to_bezier(const curve4_points& cp)
367
367
    {
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]);
370
370
    }
371
371
 
374
374
    class curve4_div
375
375
    {
376
376
    public:
377
 
        curve4_div() : 
 
377
        curve4_div() :
378
378
            m_approximation_scale(1.0),
379
379
            m_angle_tolerance(0.0),
380
380
            m_cusp_limit(0.0),
381
381
            m_count(0)
382
382
        {}
383
383
 
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),
391
391
            m_count(0)
392
 
        { 
 
392
        {
393
393
            init(x1, y1, x2, y2, x3, y3, x4, y4);
394
394
        }
395
395
 
397
397
            m_approximation_scale(1.0),
398
398
            m_angle_tolerance(0.0),
399
399
            m_count(0)
400
 
        { 
 
400
        {
401
401
            init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
402
402
        }
403
403
 
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);
409
409
 
414
414
 
415
415
        void approximation_method(curve_approximation_method_e) {}
416
416
 
417
 
        curve_approximation_method_e approximation_method() const 
418
 
        { 
419
 
            return curve_div; 
 
417
        curve_approximation_method_e approximation_method() const
 
418
        {
 
419
            return curve_div;
420
420
        }
421
421
 
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;  }
427
427
 
428
 
        void cusp_limit(double v) 
429
 
        { 
430
 
            m_cusp_limit = (v == 0.0) ? 0.0 : pi - v; 
 
428
        void cusp_limit(double v)
 
429
        {
 
430
            m_cusp_limit = (v == 0.0) ? 0.0 : pi - v;
431
431
        }
432
432
 
433
 
        double cusp_limit() const 
434
 
        { 
435
 
            return (m_cusp_limit == 0.0) ? 0.0 : pi - m_cusp_limit; 
 
433
        double cusp_limit() const
 
434
        {
 
435
            return (m_cusp_limit == 0.0) ? 0.0 : pi - m_cusp_limit;
436
436
        }
437
437
 
438
438
        void rewind(unsigned)
450
450
        }
451
451
 
452
452
    private:
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);
457
457
 
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,
462
462
                              unsigned level);
463
463
 
475
475
    {
476
476
    public:
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)
482
 
        { 
 
482
        {
483
483
            init(x1, y1, x2, y2, x3, y3);
484
484
        }
485
485
 
486
 
        void reset() 
487
 
        { 
 
486
        void reset()
 
487
        {
488
488
            m_curve_inc.reset();
489
489
            m_curve_div.reset();
490
490
        }
491
491
 
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)
495
495
        {
496
 
            if(m_approximation_method == curve_inc) 
 
496
            if(m_approximation_method == curve_inc)
497
497
            {
498
498
                m_curve_inc.init(x1, y1, x2, y2, x3, y3);
499
499
            }
503
503
            }
504
504
        }
505
505
 
506
 
        void approximation_method(curve_approximation_method_e v) 
507
 
        { 
508
 
            m_approximation_method = v; 
509
 
        }
510
 
 
511
 
        curve_approximation_method_e approximation_method() const 
512
 
        { 
513
 
            return m_approximation_method; 
514
 
        }
515
 
 
516
 
        void approximation_scale(double s) 
517
 
        { 
 
506
        void approximation_method(curve_approximation_method_e v)
 
507
        {
 
508
            m_approximation_method = v;
 
509
        }
 
510
 
 
511
        curve_approximation_method_e approximation_method() const
 
512
        {
 
513
            return m_approximation_method;
 
514
        }
 
515
 
 
516
        void approximation_scale(double s)
 
517
        {
518
518
            m_curve_inc.approximation_scale(s);
519
519
            m_curve_div.approximation_scale(s);
520
520
        }
521
521
 
522
 
        double approximation_scale() const 
523
 
        { 
524
 
            return m_curve_inc.approximation_scale(); 
525
 
        }
526
 
 
527
 
        void angle_tolerance(double a) 
528
 
        { 
529
 
            m_curve_div.angle_tolerance(a); 
530
 
        }
531
 
 
532
 
        double angle_tolerance() const 
533
 
        { 
534
 
            return m_curve_div.angle_tolerance(); 
535
 
        }
536
 
 
537
 
        void cusp_limit(double v) 
538
 
        { 
539
 
            m_curve_div.cusp_limit(v); 
540
 
        }
541
 
 
542
 
        double cusp_limit() const 
543
 
        { 
544
 
            return m_curve_div.cusp_limit();  
 
522
        double approximation_scale() const
 
523
        {
 
524
            return m_curve_inc.approximation_scale();
 
525
        }
 
526
 
 
527
        void angle_tolerance(double a)
 
528
        {
 
529
            m_curve_div.angle_tolerance(a);
 
530
        }
 
531
 
 
532
        double angle_tolerance() const
 
533
        {
 
534
            return m_curve_div.angle_tolerance();
 
535
        }
 
536
 
 
537
        void cusp_limit(double v)
 
538
        {
 
539
            m_curve_div.cusp_limit(v);
 
540
        }
 
541
 
 
542
        double cusp_limit() const
 
543
        {
 
544
            return m_curve_div.cusp_limit();
545
545
        }
546
546
 
547
547
        void rewind(unsigned path_id)
548
548
        {
549
 
            if(m_approximation_method == curve_inc) 
 
549
            if(m_approximation_method == curve_inc)
550
550
            {
551
551
                m_curve_inc.rewind(path_id);
552
552
            }
558
558
 
559
559
        unsigned vertex(double* x, double* y)
560
560
        {
561
 
            if(m_approximation_method == curve_inc) 
 
561
            if(m_approximation_method == curve_inc)
562
562
            {
563
563
                return m_curve_inc.vertex(x, y);
564
564
            }
580
580
    {
581
581
    public:
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)
588
 
        { 
 
588
        {
589
589
            init(x1, y1, x2, y2, x3, y3, x4, y4);
590
590
        }
591
591
 
592
592
        curve4(const curve4_points& cp) :
593
593
            m_approximation_method(curve_div)
594
 
        { 
 
594
        {
595
595
            init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
596
596
        }
597
597
 
598
 
        void reset() 
599
 
        { 
 
598
        void reset()
 
599
        {
600
600
            m_curve_inc.reset();
601
601
            m_curve_div.reset();
602
602
        }
603
603
 
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)
608
608
        {
609
 
            if(m_approximation_method == curve_inc) 
 
609
            if(m_approximation_method == curve_inc)
610
610
            {
611
611
                m_curve_inc.init(x1, y1, x2, y2, x3, y3, x4, y4);
612
612
            }
621
621
            init(cp[0], cp[1], cp[2], cp[3], cp[4], cp[5], cp[6], cp[7]);
622
622
        }
623
623
 
624
 
        void approximation_method(curve_approximation_method_e v) 
625
 
        { 
626
 
            m_approximation_method = v; 
627
 
        }
628
 
 
629
 
        curve_approximation_method_e approximation_method() const 
630
 
        { 
631
 
            return m_approximation_method; 
632
 
        }
633
 
 
634
 
        void approximation_scale(double s) 
635
 
        { 
 
624
        void approximation_method(curve_approximation_method_e v)
 
625
        {
 
626
            m_approximation_method = v;
 
627
        }
 
628
 
 
629
        curve_approximation_method_e approximation_method() const
 
630
        {
 
631
            return m_approximation_method;
 
632
        }
 
633
 
 
634
        void approximation_scale(double s)
 
635
        {
636
636
            m_curve_inc.approximation_scale(s);
637
637
            m_curve_div.approximation_scale(s);
638
638
        }
639
639
        double approximation_scale() const { return m_curve_inc.approximation_scale(); }
640
640
 
641
 
        void angle_tolerance(double v) 
642
 
        { 
643
 
            m_curve_div.angle_tolerance(v); 
644
 
        }
645
 
 
646
 
        double angle_tolerance() const 
647
 
        { 
648
 
            return m_curve_div.angle_tolerance();  
649
 
        }
650
 
 
651
 
        void cusp_limit(double v) 
652
 
        { 
653
 
            m_curve_div.cusp_limit(v); 
654
 
        }
655
 
 
656
 
        double cusp_limit() const 
657
 
        { 
658
 
            return m_curve_div.cusp_limit();  
 
641
        void angle_tolerance(double v)
 
642
        {
 
643
            m_curve_div.angle_tolerance(v);
 
644
        }
 
645
 
 
646
        double angle_tolerance() const
 
647
        {
 
648
            return m_curve_div.angle_tolerance();
 
649
        }
 
650
 
 
651
        void cusp_limit(double v)
 
652
        {
 
653
            m_curve_div.cusp_limit(v);
 
654
        }
 
655
 
 
656
        double cusp_limit() const
 
657
        {
 
658
            return m_curve_div.cusp_limit();
659
659
        }
660
660
 
661
661
        void rewind(unsigned path_id)
662
662
        {
663
 
            if(m_approximation_method == curve_inc) 
 
663
            if(m_approximation_method == curve_inc)
664
664
            {
665
665
                m_curve_inc.rewind(path_id);
666
666
            }
672
672
 
673
673
        unsigned vertex(double* x, double* y)
674
674
        {
675
 
            if(m_approximation_method == curve_inc) 
 
675
            if(m_approximation_method == curve_inc)
676
676
            {
677
677
                return m_curve_inc.vertex(x, y);
678
678
            }