The BIG graph update
[rrdtool.git] / libraries / libart_lgpl-2.3.7 / art_bpath.c
1 /* Libart_LGPL - library of basic graphic primitives
2  * Copyright (C) 1998 Raph Levien
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /* Basic constructors and operations for bezier paths */
21
22 #include <math.h>
23
24 #include "art_misc.h"
25
26 #include "art_bpath.h"
27
28 /**
29  * art_bpath_affine_transform: Affine transform an #ArtBpath.
30  * @src: The source #ArtBpath.
31  * @matrix: The affine transform.
32  *
33  * Affine transform the bezpath, returning a newly allocated #ArtBpath
34  * (allocated using art_alloc()).
35  *
36  * Result (x', y') = (matrix[0] * x + matrix[2] * y + matrix[4],
37  *                    matrix[1] * x + matrix[3] * y + matrix[5])
38  *
39  * Return value: the transformed #ArtBpath.
40  **/
41 ArtBpath *
42 art_bpath_affine_transform (const ArtBpath *src, const double matrix[6])
43 {
44   int i;
45   int size;
46   ArtBpath *new;
47   ArtPathcode code;
48   double x, y;
49
50   for (i = 0; src[i].code != ART_END; i++);
51   size = i;
52
53   new = art_new (ArtBpath, size + 1);
54
55   for (i = 0; i < size; i++)
56     {
57       code = src[i].code;
58       new[i].code = code;
59       if (code == ART_CURVETO)
60         {
61           x = src[i].x1;
62           y = src[i].y1;
63           new[i].x1 = matrix[0] * x + matrix[2] * y + matrix[4];
64           new[i].y1 = matrix[1] * x + matrix[3] * y + matrix[5];
65           x = src[i].x2;
66           y = src[i].y2;
67           new[i].x2 = matrix[0] * x + matrix[2] * y + matrix[4];
68           new[i].y2 = matrix[1] * x + matrix[3] * y + matrix[5];
69         }
70       else
71         {
72           new[i].x1 = 0;
73           new[i].y1 = 0;
74           new[i].x2 = 0;
75           new[i].y2 = 0;
76         }
77       x = src[i].x3;
78       y = src[i].y3;
79       new[i].x3 = matrix[0] * x + matrix[2] * y + matrix[4];
80       new[i].y3 = matrix[1] * x + matrix[3] * y + matrix[5];
81     }
82   new[i].code = ART_END;
83   new[i].x1 = 0;
84   new[i].y1 = 0;
85   new[i].x2 = 0;
86   new[i].y2 = 0;
87   new[i].x3 = 0;
88   new[i].y3 = 0;
89
90   return new;
91 }
92