Code

Fix path transformation (LP bug #515237)
[inkscape.git] / src / 2geom / bezier-to-sbasis.h
1 /**
2  * \file bezier-to-sbasis.h
3  * \brief  \todo brief description
4  *
5  * Copyright 2006 Nathan Hurst <njh@mail.csse.monash.edu.au>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it either under the terms of the GNU Lesser General Public
9  * License version 2.1 as published by the Free Software Foundation
10  * (the "LGPL") or, at your option, under the terms of the Mozilla
11  * Public License Version 1.1 (the "MPL"). If you do not alter this
12  * notice, a recipient may use your version of this file under either
13  * the MPL or the LGPL.
14  *
15  * You should have received a copy of the LGPL along with this library
16  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  * You should have received a copy of the MPL along with this library
19  * in the file COPYING-MPL-1.1
20  *
21  * The contents of this file are subject to the Mozilla Public License
22  * Version 1.1 (the "License"); you may not use this file except in
23  * compliance with the License. You may obtain a copy of the License at
24  * http://www.mozilla.org/MPL/
25  *
26  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
27  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
28  * the specific language governing rights and limitations.
29  *
30  */
32 #ifndef _BEZIER_TO_SBASIS
33 #define _BEZIER_TO_SBASIS
35 #include <2geom/coord.h>
36 #include <2geom/point.h>
37 #include <2geom/d2.h>
38 #include <2geom/sbasis-to-bezier.h>
40 namespace Geom
41 {
43 #if 0
44 inline SBasis bezier_to_sbasis(Coord const *handles, unsigned order) {
45     if(order == 0)
46         return Linear(handles[0]);
47     else if(order == 1)
48         return Linear(handles[0], handles[1]);
49     else
50         return multiply(Linear(1, 0), bezier_to_sbasis(handles, order-1)) +
51             multiply(Linear(0, 1), bezier_to_sbasis(handles+1, order-1));
52 }
55 template <typename T>
56 inline D2<SBasis> handles_to_sbasis(T const &handles, unsigned order)
57 {
58     double v[2][order+1];
59     for(unsigned i = 0; i <= order; i++)
60         for(unsigned j = 0; j < 2; j++)
61              v[j][i] = handles[i][j];
62     return D2<SBasis>(bezier_to_sbasis(v[0], order),
63                       bezier_to_sbasis(v[1], order));
64 }
65 #endif
68 template <typename T>
69 inline
70 D2<SBasis> handles_to_sbasis(T const& handles, unsigned order)
71 {
72     D2<SBasis> sbc;
73     size_t sz = order + 1;
74     std::vector<Point> v;
75     v.reserve(sz);
76     for (size_t i = 0; i < sz; ++i)
77         v.push_back(handles[i]);
78     bezier_to_sbasis(sbc, v);
79     return sbc;
80 }
83 } // end namespace Geom
88 #endif
89 /*
90   Local Variables:
91   mode:c++
92   c-file-style:"stroustrup"
93   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
94   indent-tabs-mode:nil
95   fill-column:99
96   End:
97 */
98 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :