#include <2geom/d2.h> #include <2geom/sbasis.h> #include <2geom/bezier-to-sbasis.h> #include #include using std::vector; using namespace std; using namespace Geom; static double exp_rescale(double x){ return std::pow(10, x);} std::string exp_formatter(double x){ return default_formatter(exp_rescale(x));} 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)); } static void plot_bar(cairo_t* cr, Interval height, double vscale=1,double a=0,double b=1){ Point A(150+300*a,-height.max()*vscale+300); Point B(150+300*b,-height.min()*vscale+300); cairo_rectangle(cr, Rect(A,B) ); } class BoundsTester: public Toy { 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.emplace_back(300-(hand.pts[2*size ][Y]-vtol), 300-(hand.pts[2*size ][Y]+vtol) ); levels.emplace_back(300-(hand.pts[2*size+1][Y]-vtol), 300-(hand.pts[2*size+1][Y]+vtol) ); levels.emplace_back(300-(hand.pts[2*size+2][Y]-vtol), 300-(hand.pts[2*size+2][Y]+vtol) ); for (auto & level : levels) plot_bar(cr,level.middle()); cairo_set_source_rgba( cr, 1., 0., 0., 1); cairo_stroke(cr); for (auto & level : levels) plot_bar(cr,level); cairo_set_source_rgba( cr, 1., 0., 0., .2); cairo_fill(cr); cairo_set_source_rgba (cr, 0., 0.5, 0., 1); *notify<<"Use hand.pts to set the coefficients of the s-basis."< > sols=level_sets(B,levels,0,1); for (unsigned i=0;i