Code

Extensions. Fix for Bug #668895 (Extensions with <check> tags fail to load).
[inkscape.git] / src / 2geom / sbasis-poly.cpp
1 #include <2geom/sbasis-poly.h>
3 namespace Geom{
5 /** Changes the basis of p to be sbasis.
6  \param p the Monomial basis polynomial
7  \returns the Symmetric basis polynomial
9 This algorithm is horribly slow and numerically terrible.  Only for testing.
10 */
11 SBasis poly_to_sbasis(Poly const & p) {
12     SBasis x = Linear(0, 1);
13     SBasis r;
14     
15     for(int i = p.size()-1; i >= 0; i--) {
16         r = SBasis(Linear(p[i], p[i])) + multiply(x, r);
17     }
18     r.normalize();
19     return r;
20         
21 }
23 /** Changes the basis of p to be monomial.
24  \param p the Symmetric basis polynomial
25  \returns the Monomial basis polynomial
27 This algorithm is horribly slow and numerically terrible.  Only for testing.
28 */
29 Poly sbasis_to_poly(SBasis const & sb) {
30     if(sb.isZero())
31         return Poly();
32     Poly S; // (1-x)x = -1*x^2 + 1*x + 0
33     Poly A, B;
34     B.push_back(0);
35     B.push_back(1);
36     A.push_back(1);
37     A.push_back(-1);
38     S = A*B;
39     Poly r;
40     
41     for(int i = sb.size()-1; i >= 0; i--) {
42         r = S*r + sb[i][0]*A + sb[i][1]*B;
43     }
44     r.normalize();
45     return r;
46 }
48 };
50 /*
51   Local Variables:
52   mode:c++
53   c-file-style:"stroustrup"
54   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
55   indent-tabs-mode:nil
56   fill-column:99
57   End:
58 */
59 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :