~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/2geom/sbasis.h

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 
64
64
namespace Geom{
65
65
 
66
 
/*** An empty SBasis is identically 0. */
 
66
/**
 
67
* \brief S-power basis function class
 
68
*
 
69
* An empty SBasis is identically 0. */
67
70
class SBasis{
68
71
    std::vector<Linear> d;
69
72
    void push_back(Linear const&l) { d.push_back(l); }
125
128
    }
126
129
    inline bool isConstant() const {
127
130
        if (empty()) return true;
128
 
        for (unsigned i = 0; i < size(); i++) {
129
 
            if(!(*this)[i].isConstant()) return false;
 
131
        if(!(*this)[0].isConstant()) return false;
 
132
        for (unsigned i = 1; i < size(); i++) {
 
133
            if(!(*this)[i].isZero()) return false;
130
134
        }
131
135
        return true;
132
136
    }
188
192
 
189
193
/** Returns a function which reverses the domain of a.
190
194
 \param a sbasis function
 
195
 \relates SBasis
191
196
 
192
197
useful for reversing a parameteric curve.
193
198
*/
312
317
/** Returns the degree of the first non zero coefficient.
313
318
 \param a sbasis function
314
319
 \param tol largest abs val considered 0
315
 
 \returns first non zero coefficient
 
320
 \return first non zero coefficient
 
321
 \relates SBasis
316
322
*/
317
323
inline unsigned 
318
324
valuation(SBasis const &a, double tol=0){
333
339
SBasis compose_inverse(SBasis const &f, SBasis const &g, unsigned order=2, double tol=1e-3);
334
340
 
335
341
/** Returns the sbasis on domain [0,1] that was t on [from, to]
336
 
 \param a sbasis function
 
342
 \param t sbasis function
337
343
 \param from,to interval
338
 
 \returns sbasis
339
 
 
 
344
 \return sbasis
 
345
 \relates SBasis
340
346
*/
341
347
inline SBasis portion(const SBasis &t, double from, double to) { return compose(t, Linear(from, to)); }
342
 
inline SBasis portion(const SBasis &t, Interval ivl) { return compose(t, Linear(ivl[0], ivl[1])); }
 
348
inline SBasis portion(const SBasis &t, Interval ivl) { return compose(t, Linear(ivl.min(), ivl.max())); }
343
349
 
344
350
// compute f(g)
345
351
inline SBasis
364
370
SBasis cos(Linear bo, int k);
365
371
 
366
372
std::vector<double> roots(SBasis const & s);
 
373
std::vector<double> roots(SBasis const & s, Interval const inside);
367
374
std::vector<std::vector<double> > multi_roots(SBasis const &f,
368
375
                                 std::vector<double> const &levels,
369
376
                                 double htol=1e-7,
370
377
                                 double vtol=1e-7,
371
378
                                 double a=0,
372
379
                                 double b=1);
373
 
    
 
380
 
 
381
//--------- Levelset like functions -----------------------------------------------------
 
382
 
 
383
/** Solve f(t) = v +/- tolerance. The collection of intervals where
 
384
 *     v - vtol <= f(t) <= v+vtol
 
385
 *   is returned (with a precision tol on the boundaries).
 
386
    \param f sbasis function
 
387
    \param level the value of v.
 
388
    \param vtol: error tolerance on v.
 
389
    \param a, b limit search on domain [a,b]
 
390
    \param tol: tolerance on the result bounds.
 
391
    \returns a vector of intervals.
 
392
*/
 
393
std::vector<Interval> level_set (SBasis const &f,
 
394
                double level,
 
395
                double vtol = 1e-5,
 
396
                double a=0.,
 
397
                double b=1.,
 
398
                double tol = 1e-5);
 
399
 
 
400
/** Solve f(t)\in I=[u,v], which defines a collection of intervals (J_k). More precisely,
 
401
 *  a collection (J'_k) is returned with J'_k = J_k up to a given tolerance.
 
402
    \param f sbasis function
 
403
    \param level: the given interval of deisred values for f.
 
404
    \param a, b limit search on domain [a,b]
 
405
    \param tol: tolerance on the bounds of the result.
 
406
    \returns a vector of intervals.
 
407
*/
 
408
std::vector<Interval> level_set (SBasis const &f,
 
409
                Interval const &level,
 
410
                double a=0.,
 
411
                double b=1.,
 
412
                double tol = 1e-5);
 
413
 
 
414
/** 'Solve' f(t) = v +/- tolerance for several values of v at once.
 
415
    \param f sbasis function
 
416
    \param levels vector of values, that should be sorted.
 
417
    \param vtol: error tolerance on v.
 
418
    \param a, b limit search on domain [a,b]
 
419
    \param tol: the bounds of the returned intervals are exact up to that tolerance.
 
420
    \returns a vector of vectors of intervals.
 
421
*/
 
422
std::vector<std::vector<Interval> > level_sets (SBasis const &f,
 
423
                std::vector<double> const &levels,
 
424
                double a=0.,
 
425
                double b=1.,
 
426
                double vtol = 1e-5,
 
427
                double tol = 1e-5);
 
428
 
 
429
/** 'Solve' f(t)\in I=[u,v] for several intervals I at once.
 
430
    \param f sbasis function
 
431
    \param levels vector of 'y' intervals, that should be disjoints and sorted.
 
432
    \param a, b limit search on domain [a,b]
 
433
    \param tol: the bounds of the returned intervals are exact up to that tolerance.
 
434
    \returns a vector of vectors of intervals.
 
435
*/
 
436
std::vector<std::vector<Interval> > level_sets (SBasis const &f,
 
437
                std::vector<Interval> const &levels,
 
438
                double a=0.,
 
439
                double b=1.,
 
440
                double tol = 1e-5);
 
441
 
374
442
}
375
443
#endif
376
444
 
383
451
  fill-column:99
384
452
  End:
385
453
*/
386
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
 
454
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
387
455
#endif