Logo Search packages:      
Sourcecode: inkscape version File versions

template<typename T>
Piecewise<T> Geom::portion ( const Piecewise< T > &  pw,
double  from,
double  to 
) [inline]

Piecewise<T> portion(const Piecewise<T> &pw, double from, double to); Returns a Piecewise<T> with a defined domain of [min(from, to), max(from, to)].

Definition at line 344 of file piecewise.h.

                                                                     {
    if(pw.empty() || from == to) return Piecewise<T>();

    Piecewise<T> ret;

    double temp = from;
    from = std::min(from, to);
    to = std::max(temp, to);

    unsigned i = pw.segN(from);
    ret.push_cut(from);
    if(i == pw.size() - 1 || to < pw.cuts[i + 1]) {    //to/from inhabit the same segment
        ret.push(elem_portion(pw, i, from, to), to);
        return ret;
    }
    ret.push_seg(portion( pw[i], pw.segT(from, i), 1.0 ));
    i++;
    unsigned fi = pw.segN(to, i);

    ret.segs.insert(ret.segs.end(), pw.segs.begin() + i, pw.segs.begin() + fi);  //copy segs
    ret.cuts.insert(ret.cuts.end(), pw.cuts.begin() + i, pw.cuts.begin() + fi + 1);  //and their cuts

    ret.push_seg( portion(pw[fi], 0.0, pw.segT(to, fi)));
    if(to != ret.cuts.back()) ret.push_cut(to);
    ret.invariants();
    return ret;
}


Generated by  Doxygen 1.6.0   Back to index