5#include "../2geom/orphan-code/nearestpoint.cpp"
13#include <2geom/zroots.c>
20 std::vector<double> &
roots,
21 double left,
double right);
27 for (
unsigned i = 0; i <
N; i++)
31 const double omt = (1-t);
34 double *prev_row = Vtemp;
35 double *row = Vtemp +
N;
36 for (
unsigned i = 1; i <
N; i++) {
37 for (
unsigned j = 0; j <
N - i; j++) {
38 row[j] = omt*prev_row[j] + t*prev_row[j+1];
56class RootFinderComparer:
public Toy {
60 void draw(
cairo_t *cr, std::ostringstream *notify,
int width,
int height,
bool save, std::ostringstream *timer_stream)
override {
61 std::vector<Geom::Point> trans;
62 trans.resize(psh.
size());
63 for(
unsigned i = 0; i <
handles.size(); i++) {
77 *notify <<
"original time = " << als_time << std::endl;
86 *notify <<
"sb bounds = "<<
bs.min()<<
", " <<
bs.max()<<std::endl;
93 vector<complex<double> > complex_solutions;
94 complex_solutions =
solve(ply);
97 std::copy(complex_solutions.begin(), complex_solutions.end(), std::ostream_iterator<std::complex<double> >(*notify,
",\t"));
103 fcomplex a[ply.size()];
104 for(
unsigned i = 0; i < ply.size(); i++) {
108 fcomplex rts[ply.size()];
110 zroots(a, ply.size(), rts,
true);
111 for(
unsigned i = 0; i < ply.size(); i++) {
123 *timer_stream <<
"gsl poly = " << als_time << std::endl;
129 zroots(a, ply.size(), rts,
false);
131 *timer_stream <<
"zroots poly = " << als_time << std::endl;
139 *timer_stream <<
"Laguerre poly = " << als_time << std::endl;
140 complex_solutions = Laguerre(ply);
144 #define SBASIS_SUBDIV_TEST 0
145 #if SBASIS_SUBDIV_TEST
151 *timer_stream <<
"sbasis subdivision = " << als_time << std::endl;
159 *timer_stream <<
"solver parametric = " << als_time << std::endl;
161 double ys[trans.size()];
162 for(
unsigned i = 0; i < trans.size(); i++) {
164 double x = double(i)/(trans.size()-1);
174 *notify <<
"found sub solutions at:\n";
175 std::copy(
solutions.begin(),
solutions.end(), std::ostream_iterator<double >(*notify,
","));
176 *notify <<
"solver 1d bernstein subdivision n_slns = " <<
solutions.size()
177 <<
", time = " << als_time << std::endl;
185 *notify <<
"solver 1d bernstein secant subdivision slns" <<
solutions.size()
186 <<
", time = " << als_time << std::endl;
187 *notify <<
"found secant solutions at:\n";
188 std::copy(
solutions.begin(),
solutions.end(), std::ostream_iterator<double >(*notify,
","));
189 *notify <<
"solver 1d bernstein subdivision accuracy:"
192 *notify << solution <<
":" <<
eval_bernstein(ys, solution, trans.size()) <<
",";
199 *notify <<
"sbasis roots: ";
200 std::copy(
solutions.begin(),
solutions.end(), std::ostream_iterator<double>(*notify,
",\t"));
201 *notify <<
"\n time = " << als_time << std::endl;
204 double x = test_sb[0](solution);
209 *notify <<
"found " <<
solutions.size() <<
"solutions at:\n";
210 std::copy(
solutions.begin(),
solutions.end(), std::ostream_iterator<double >(*notify,
","));
222 RootFinderComparer(
unsigned degree)
229int main(
int argc,
char **argv) {
230 unsigned bez_ord = 6;
232 sscanf(argv[1],
"%d", &bez_ord);
233 init(argc, argv,
new RootFinderComparer(bez_ord));
Path - a sequence of contiguous curves.
Conversion between Bezier control points and SBasis curves.
Adaptor that creates 2D functions from 1D ones.
Range of real numbers that is never empty.
Function that interpolates linearly between two values.
Sequence of contiguous curves, aka spline.
void close(bool closed=true)
Set whether the path is closed.
void append(Curve *curve)
Add a new curve to the end of the path.
Two-dimensional point that doubles as a vector.
Polynomial in canonical (monomial) basis.
Polynomial in symmetric power basis.
void push_back(double x, double y)
Geom::D2< Geom::SBasis > asBezier()
std::vector< Geom::Point > pts
void ask_for_timeslice()
Ask the OS nicely for a big time slice.
vector< Handle * > handles
virtual void save(FILE *f)
virtual void draw(cairo_t *cr, std::ostringstream *notify, int w, int h, bool save, std::ostringstream *timing_stream)
Various utility functions.
OptInterval bounds_exact(Bezier const &b)
void subdiv_sbasis(SBasis const &s, std::vector< double > &roots, double left, double right)
Poly sbasis_to_poly(SBasis const &s)
Changes the basis of p to be monomial.
void find_parametric_bezier_roots(Geom::Point const *w, unsigned degree, std::vector< double > &solutions, unsigned depth)
void find_bernstein_roots(double const *w, unsigned degree, std::vector< double > &solutions, unsigned depth, double left_t=0, double right_t=1, bool use_secant=true)
std::vector< double > roots(SBasis const &s)
std::vector< std::complex< double > > solve(const Poly &p)
static int FindRoots(Geom::Point *w, int degree, double *t, int depth)
void cairo_line_to(cairo_t *cr, Geom::Point p1)
void draw_cross(cairo_t *cr, Geom::Point h)
void cairo_path(cairo_t *cr, Geom::Path const &p)
void draw_handle(cairo_t *cr, Geom::Point h)
void cairo_move_to(cairo_t *cr, Geom::Point p1)
void cairo_d2_sb(cairo_t *cr, Geom::D2< Geom::SBasis > const &p)
double eval_bernstein(double *w, double t, unsigned N)
Conversion between SBasis and Poly.
Polynomial in symmetric power basis (S-basis)
std::vector< double > & solutions
Finding roots of Bernstein-Bezier polynomials.
void init(int argc, char **argv, Toy *t, int width=600, int height=600)