11#include <2geom/zroots.c>
26void shift(T &a, T &b, T &
c, T
const &d) {
34class MatchCurve:
public Toy {
36 double timer_precision;
40 void draw(
cairo_t *cr, std::ostringstream *notify,
int width,
int height,
bool save, std::ostringstream *timer_stream)
override {
41 cairo_set_line_width (cr, 1);
42 cairo_set_source_rgb(cr, 0,0,0);
43 std::vector<Geom::Point> trans;
44 trans.resize(psh.
size());
45 for(
unsigned i = 0; i < psh.
size(); i++) {
70 for(
int dim = 0; dim < 2; dim++) {
71 m[dim] =
Linear(pt[dim],pt[dim]+tang[dim]);
76 double lo = 0, hi = 1;
78 while(hi - lo > 0.0001) {
79 double mid = (hi + lo)/2;
84 double best_f = 0, best_x = 1;
85 for(
int n = 2; n < 4; n++) {
87 double x0 = 0, x3 = 1.;
88 const double R = 0.61803399;
89 const double C = 1 -
R;
90 double x1 = C*x0 +
R*x3;
91 double x2 = C*x1 +
R*x3;
94 while(fabs(x3 - x0) > 1e-3*(fabs(x1) + fabs(x2))) {
96 shift(x0, x1, x2,
R*x1 + C*x3);
99 shift(x3, x2, x1,
R*x2 + C*x0);
102 std::cout << x0 <<
","
117 std::cout << mid <<
":" << best_x <<
"->" << best_f << std::endl;
126 std::cout << std::endl;
139 MatchCurve() : timer_precision(0.1), units(1e6)
142 for(
int i = 0; i < 6; i++)
147int main(
int argc,
char **argv) {
148 init(argc, argv,
new MatchCurve());
Path - a sequence of contiguous curves.
Conversion between Bezier control points and SBasis curves.
Adaptor that creates 2D functions from 1D ones.
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.
void push_back(double x, double y)
Geom::D2< Geom::SBasis > asBezier()
std::vector< Geom::Point > pts
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)
Lifts one dimensional objects into 2D.
Various utility functions.
Angle distance(Angle const &a, Angle const &b)
SBasisOf< T > shift(SBasisOf< T > const &a, int sh)
D2< T > compose(D2< T > const &a, T const &b)
Bezier derivative(Bezier const &a)
D2< SBasis > truncate(D2< SBasis > const &a, unsigned terms)
void cairo_path(cairo_t *cr, Geom::Path const &p)
void draw_circ(cairo_t *cr, Geom::Point h)
Polynomial in symmetric power basis (S-basis)
std::vector< double > & solutions
void init(int argc, char **argv, Toy *t, int width=600, int height=600)