lemon/bezier.h
changeset 1846 6b4e38acef1c
parent 1471 11a13908b510
child 1875 98698b69a902
equal deleted inserted replaced
1:beb28fbe71ca 2:5194780cda22
    56   
    56   
    57   Bezier1 after(double t) const
    57   Bezier1 after(double t) const
    58   {
    58   {
    59     return Bezier1(conv(p1,p2,t),p2);
    59     return Bezier1(conv(p1,p2,t),p2);
    60   }
    60   }
    61   Bezier1 revert() { return Bezier1(p2,p1);}
       
    62   Bezier1 operator()(double a,double b) { return before(b).after(a/b); }
       
    63   xy grad() { return p2-p1; }
       
    64   xy grad(double) { return grad(); }
       
    65 
    61 
       
    62   Bezier1 revert() const { return Bezier1(p2,p1);}
       
    63   Bezier1 operator()(double a,double b) const { return before(b).after(a/b); }
       
    64   xy grad() const { return p2-p1; }
       
    65   xy norm() const { return rot90(p2-p1); }
       
    66   xy grad(double) const { return grad(); }
       
    67   xy norm(double t) const { return rot90(grad(t)); }
    66 };
    68 };
    67 
    69 
    68 class Bezier2 : public BezierBase
    70 class Bezier2 : public BezierBase
    69 {
    71 {
    70 public:
    72 public:
    89   {
    91   {
    90     xy q(conv(p1,p2,t));
    92     xy q(conv(p1,p2,t));
    91     xy r(conv(p2,p3,t));
    93     xy r(conv(p2,p3,t));
    92     return Bezier2(conv(q,r,t),r,p3);
    94     return Bezier2(conv(q,r,t),r,p3);
    93   }
    95   }
    94   Bezier2 revert() { return Bezier2(p3,p2,p1);}
    96   Bezier2 revert() const { return Bezier2(p3,p2,p1);}
    95   Bezier2 operator()(double a,double b) { return before(b).after(a/b); }
    97   Bezier2 operator()(double a,double b) const { return before(b).after(a/b); }
    96   Bezier1 grad() { return Bezier1(2.0*(p2-p1),2.0*(p3-p2)); }
    98   Bezier1 grad() const { return Bezier1(2.0*(p2-p1),2.0*(p3-p2)); }
    97   xy grad(double t) { return grad()(t); }  
    99   Bezier1 norm() const { return Bezier1(2.0*rot90(p2-p1),2.0*rot90(p3-p2)); }
       
   100   xy grad(double t) const { return grad()(t); }
       
   101   xy norm(double t) const { return rot90(grad(t)); }
    98 };
   102 };
    99 
   103 
   100 class Bezier3 : public BezierBase
   104 class Bezier3 : public BezierBase
   101 {
   105 {
   102 public:
   106 public:
   134       xy a(conv(p,q,t));
   138       xy a(conv(p,q,t));
   135       xy b(conv(q,r,t));
   139       xy b(conv(q,r,t));
   136       xy c(conv(a,b,t));
   140       xy c(conv(a,b,t));
   137       return Bezier3(c,b,r,p4);
   141       return Bezier3(c,b,r,p4);
   138     }
   142     }
   139   Bezier3 revert() { return Bezier3(p4,p3,p2,p1);}
   143   Bezier3 revert() const { return Bezier3(p4,p3,p2,p1);}
   140   Bezier3 operator()(double a,double b) { return before(b).after(a/b); }
   144   Bezier3 operator()(double a,double b) const { return before(b).after(a/b); }
   141   Bezier2 grad() { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); }
   145   Bezier2 grad() const { return Bezier2(3.0*(p2-p1),3.0*(p3-p2),3.0*(p4-p3)); }
   142   xy grad(double t) { return grad()(t); }
   146   Bezier2 norm() const { return Bezier2(3.0*rot90(p2-p1),
       
   147 				  3.0*rot90(p3-p2),
       
   148 				  3.0*rot90(p4-p3)); }
       
   149   xy grad(double t) const { return grad()(t); }
       
   150   xy norm(double t) const { return rot90(grad(t)); }
       
   151 
       
   152   template<class R,class F,class S,class D>
       
   153   R recSplit(F &_f,const S &_s,D _d) const 
       
   154   {
       
   155     const xy a=(p1+p2)/2;
       
   156     const xy b=(p2+p3)/2;
       
   157     const xy c=(p3+p4)/2;
       
   158     const xy d=(a+b)/2;
       
   159     const xy e=(b+c)/2;
       
   160     const xy f=(d+e)/2;
       
   161     R f1=_f(Bezier3(p1,a,d,e),_d);
       
   162     R f2=_f(Bezier3(e,d,c,p4),_d);
       
   163     return _s(f1,f2);
       
   164   }
       
   165   
   143 };
   166 };
   144 
   167 
   145 } //END OF NAMESPACE LEMON
   168 } //END OF NAMESPACE LEMON
   146 
   169 
   147 #endif // LEMON_BEZIER_H
   170 #endif // LEMON_BEZIER_H