double goal_function(Piecewise<D2<SBasis> >const &A, Piecewise<D2<SBasis> >const&B) { if(goal_function_type) { OptInterval bnds = bounds_fast(dot(derivative(A), rot90(derivative(B)))); //double h_dist = bnds.dimensions().length(); //0 is in the rect!, TODO:gain factor ~2 for free. // njh: not really, the benefit is actually rather small. double h_dist = 0; if(bnds) h_dist = bnds->extent(); return h_dist ; } else { Rect bnds = *bounds_fast(A - B); return max(bnds.min().length(), bnds.max().length()); } }
static std::vector<double> solve_lambda0(double a0,double a1,double c0,double c1, int insist_on_speeds_signs){ SBasis p(3, Linear()); p[0] = Linear( a1*c0*c0+c1, a1*a0*(a0+ 2*c0) +a1*c0*c0 +c1 -1 ); p[1] = Linear( -a1*a0*(a0+2*c0), -a1*a0*(3*a0+2*c0) ); p[2] = Linear( a1*a0*a0 ); OptInterval domain = find_bounds_for_lambda0(a0,a1,c0,c1,insist_on_speeds_signs); if ( !domain ) return std::vector<double>(); p = compose(p,Linear(domain->min(),domain->max())); std::vector<double>rts = roots(p); for (unsigned i=0; i<rts.size(); i++){ rts[i] = domain->min() + rts[i] * domain->extent(); } return rts; }
Geom::Piecewise<Geom::D2<Geom::SBasis> > LPERecursiveSkeleton::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in) { using namespace Geom; Piecewise<D2<SBasis> > output; std::vector<Piecewise<D2<SBasis> > > pre_output; double prop_scale = 1.0; D2<Piecewise<SBasis> > patternd2 = make_cuts_independent(pwd2_in); Piecewise<SBasis> x0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]); Piecewise<SBasis> y0 = false /*vertical_pattern.get_value()*/ ? Piecewise<SBasis>(patternd2[0]) : Piecewise<SBasis>(patternd2[1]); OptInterval pattBndsX = bounds_exact(x0); OptInterval pattBndsY = bounds_exact(y0); if ( !pattBndsX || !pattBndsY) { return pwd2_in; } x0 -= pattBndsX->min(); y0 -= pattBndsY->middle(); double xspace = 0;//spacing; double noffset = 0;//normal_offset; double toffset = 0;//tang_offset; if (false /*prop_units.get_value()*/){ xspace *= pattBndsX->extent(); noffset *= pattBndsY->extent(); toffset *= pattBndsX->extent(); } y0+=noffset; output = pwd2_in; for (int i = 0; i < iterations; ++i) { std::vector<Piecewise<D2<SBasis> > > skeleton = split_at_discontinuities(output); output.clear(); for (unsigned idx = 0; idx < skeleton.size(); idx++){ Piecewise<D2<SBasis> > path_i = skeleton[idx]; Piecewise<SBasis> x = x0; Piecewise<SBasis> y = y0; Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1); uskeleton = remove_short_cuts(uskeleton,.01); Piecewise<D2<SBasis> > n = rot90(derivative(uskeleton)); n = force_continuity(remove_short_cuts(n,.1)); double scaling = 1; scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent(); // TODO investigate why pattWidth is not being used: double pattWidth = pattBndsX->extent() * scaling; if (scaling != 1.0) { x*=scaling; } if ( true /*scale_y_rel.get_value()*/ ) { y*=(scaling*prop_scale); } else { if (prop_scale != 1.0) y *= prop_scale; } x += toffset; output.concat(compose(uskeleton,x)+y*compose(n,x)); } } return output; }