Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_BASEGFX_TOOLS_KEYSTOPLERP_HXX
21 : #define INCLUDED_BASEGFX_TOOLS_KEYSTOPLERP_HXX
22 :
23 : #include <basegfx/numeric/ftools.hxx>
24 : #include <vector>
25 : #include <basegfx/basegfxdllapi.h>
26 :
27 : namespace com{ namespace sun{ namespace star{ namespace uno {
28 : template<typename T> class Sequence;
29 : }}}}
30 :
31 : namespace basegfx
32 : {
33 : namespace tools
34 : {
35 : /** Lerp in a vector of key stops
36 :
37 : This class holds a key stop vector and provides the
38 : functionality to lerp inside it. Useful e.g. for
39 : multi-stop gradients, or the SMIL key time activity.
40 :
41 : For those, given a global [0,1] lerp alpha, one need to
42 : find the suitable bucket index from key stop vector, and
43 : then calculate the relative alpha between the two buckets
44 : found.
45 : */
46 2 : class BASEGFX_DLLPUBLIC KeyStopLerp
47 : {
48 : public:
49 : typedef std::pair<std::ptrdiff_t,double> ResultType;
50 :
51 : /** Create lerper with given vector of stops
52 :
53 : @param rKeyStops
54 :
55 : Vector of stops, must contain at least two elements
56 : (though preferably more, otherwise you probably don't
57 : need key stop lerping in the first place). All
58 : elements must be of monotonically increasing value.
59 : */
60 : explicit KeyStopLerp( const std::vector<double>& rKeyStops );
61 :
62 : /** Create lerper with given sequence of stops
63 :
64 : @param rKeyStops
65 :
66 : Sequence of stops, must contain at least two elements
67 : (though preferably more, otherwise you probably don't
68 : need key stop lerping in the first place). All
69 : elements must be of monotonically increasing value.
70 : */
71 : explicit KeyStopLerp( const ::com::sun::star::uno::Sequence<double>& rKeyStops );
72 :
73 : /** Find two nearest bucket index & interpolate
74 :
75 : @param fAlpha
76 : Find bucket index i, with keyStops[i] < fAlpha <=
77 : keyStops[i+1]. Return new alpha value in [0,1),
78 : proportional to fAlpha's position between keyStops[i]
79 : and keyStops[i+1]
80 : */
81 : ResultType lerp(double fAlpha) const;
82 :
83 : private:
84 : std::vector<double> maKeyStops;
85 : mutable std::ptrdiff_t mnLastIndex;
86 : };
87 : }
88 : }
89 :
90 : #endif
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|