~lib2geom-hackers/lib2geom/trunk

« back to all changes in this revision

Viewing changes to bez-test.cpp

  • Committer: njh
  • Date: 2006-05-22 11:50:24 UTC
  • Revision ID: svn-v4:4601daaa-0314-0410-9a8b-c964a3c23b6b:trunk/lib2geom:1
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "point.h"
 
2
#include "point-ops.h"
 
3
 
 
4
template <unsigned order> 
 
5
inline Geom::Point Bez(double t, Geom::Point* b) {
 
6
    Geom::Point child[order];
 
7
    for(unsigned i = 0; i < order; i++)
 
8
        child[i] = (1-t)*b[i] + t*b[i+1];
 
9
    return Bez<order-1>(t, child);
 
10
}
 
11
 
 
12
template <> 
 
13
inline Geom::Point Bez<0>(double t, Geom::Point* b) { return *b;}
 
14
 
 
15
 
 
16
 
 
17
#include <stdio.h>
 
18
int main(int argc, char** argv) {
 
19
        Geom::Point a[] = {Geom::Point(1,0),Geom::Point(2,3),Geom::Point(2,5)};
 
20
        Geom::Point p = Bez<1>(0.5, a);
 
21
        
 
22
        printf("%g %g\n", p[0], p[1]);
 
23
}