1 #include "sbasis-poly.h"
3 namespace Geom{
5 SBasis poly_to_sbasis(Poly const & p) {
6 SBasis x = Linear(0, 1);
7 SBasis r;
9 for(int i = p.size()-1; i >= 0; i--) {
10 r = SBasis(Linear(p[i], p[i])) + multiply(x, r);
11 }
12 r.normalize();
13 return r;
15 }
17 Poly sbasis_to_poly(SBasis const & sb) {
18 if(sb.isZero())
19 return Poly();
20 Poly S; // (1-x)x = -1*x^2 + 1*x + 0
21 Poly A, B;
22 B.push_back(0);
23 B.push_back(1);
24 A.push_back(1);
25 A.push_back(-1);
26 S = A*B;
27 Poly r;
29 for(int i = sb.size()-1; i >= 0; i--) {
30 r = S*r + sb[i][0]*A + sb[i][1]*B;
31 }
32 r.normalize();
33 return r;
34 }
36 };
38 /*
39 Local Variables:
40 mode:c++
41 c-file-style:"stroustrup"
42 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
43 indent-tabs-mode:nil
44 fill-column:99
45 End:
46 */
47 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :