#include <2geom/d2.h> #include <2geom/sbasis.h> #include <2geom/bezier-to-sbasis.h> #include #include #include #include using std::vector; using namespace Geom; using namespace std; static void plot(cairo_t* cr, SBasis const &B,double vscale=1,double a=0,double b=1){ D2 plot; plot[0]=SBasis(Linear(150+a*300,150+b*300)); plot[1]=B*(-vscale); plot[1]+=300; cairo_d2_sb(cr, plot); cairo_stroke(cr); } static void plot_bar(cairo_t* cr, double height, double vscale=1,double a=0,double b=1){ cairo_move_to(cr, Geom::Point(150+300*a,-height*vscale+300)); cairo_line_to(cr, Geom::Point(150+300*b,-height*vscale+300)); cairo_stroke(cr); } class BoundsTester: public Toy { unsigned size; PointSetHandle hand; void draw(cairo_t *cr, std::ostringstream *notify, int width, int height, bool save, std::ostringstream *timer_stream) override { for (unsigned i=0;i levels; levels.push_back((300-hand.pts[2*size ][1])); levels.push_back((300-hand.pts[2*size+1][1])); levels.push_back((300-hand.pts[2*size+2][1])); for (double level : levels) plot_bar(cr,level); cairo_set_source_rgba (cr, 0., 0.5, 0., 1); *notify<<"Use hand.pts to set the coefficients of the s-basis."<my_roots; // cairo_set_source_rgba (cr, 0.9, 0., 0.8, 1); // for (unsigned i=0;i > sols=multi_roots(B,levels,.001,.001); //map sols=multi_roots(B,levels); //for(map::iterator sol=sols.begin();sol!=sols.end();sol++){ // draw_handle(cr,Point(150+300*(*sol).first,300-levels[(*sol).second])); //} for (unsigned i=0;i clock()) { my_roots.clear(); for (unsigned i=0;i clock()) { sols.clear(); sols=multi_roots(B,levels); iterations++; } *notify << 1000*0.1/iterations <<" ms = multi roots time"<< std::endl; */ Toy::draw(cr, notify, width, height, save,timer_stream); } public: BoundsTester(){ size=5; if(hand.pts.empty()) { for(unsigned i = 0; i < 2*size; i++) hand.pts.emplace_back(0,150+150+uniform()*300*0); } hand.pts.emplace_back(150,300+ 50+uniform()*100); hand.pts.emplace_back(150,300- 50+uniform()*100); hand.pts.emplace_back(150,300-150+uniform()*100); handles.push_back(&hand); } }; int main(int argc, char **argv) { init(argc, argv, new BoundsTester); return 0; } /* Local Variables: mode:c++ c-file-style:"stroustrup" c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) indent-tabs-mode:nil fill-column:99 End: */ // vim: filetype = cpp:expandtab:shiftwidth = 4:tabstop = 8:softtabstop = 4:encoding = utf-8:textwidth = 99 :