Bump version to 6.4-15
[LibreOffice.git] / include / basegfx / utils / keystoplerp.hxx
blob551e31bcf65acdbe4ffd9901b28acc717322a9fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASEGFX_UTILS_KEYSTOPLERP_HXX
21 #define INCLUDED_BASEGFX_UTILS_KEYSTOPLERP_HXX
23 #include <vector>
24 #include <basegfx/basegfxdllapi.h>
26 namespace com{ namespace sun{ namespace star{ namespace uno {
27 template<typename T> class Sequence;
28 }}}}
30 namespace basegfx
32 namespace utils
34 /** Lerp in a vector of key stops
36 This class holds a key stop vector and provides the
37 functionality to lerp inside it. Useful e.g. for
38 multi-stop gradients, or the SMIL key time activity.
40 For those, given a global [0,1] lerp alpha, one need to
41 find the suitable bucket index from key stop vector, and
42 then calculate the relative alpha between the two buckets
43 found.
45 class BASEGFX_DLLPUBLIC KeyStopLerp
47 public:
48 typedef std::pair<std::ptrdiff_t,double> ResultType;
50 /** Create lerper with given vector of stops
52 @param rKeyStops
54 Vector of stops, must contain at least two elements
55 (though preferably more, otherwise you probably don't
56 need key stop lerping in the first place). All
57 elements must be of monotonically increasing value.
59 explicit KeyStopLerp( const std::vector<double>& rKeyStops );
61 /** Create lerper with given sequence of stops
63 @param rKeyStops
65 Sequence of stops, must contain at least two elements
66 (though preferably more, otherwise you probably don't
67 need key stop lerping in the first place). All
68 elements must be of monotonically increasing value.
70 explicit KeyStopLerp( const css::uno::Sequence<double>& rKeyStops );
72 /** Find two nearest bucket index & interpolate
74 @param fAlpha
75 Find bucket index i, with keyStops[i] < fAlpha <=
76 keyStops[i+1]. Return new alpha value in [0,1),
77 proportional to fAlpha's position between keyStops[i]
78 and keyStops[i+1]
80 ResultType lerp(double fAlpha) const;
82 private:
83 std::vector<double> maKeyStops;
84 mutable std::ptrdiff_t mnLastIndex;
89 #endif
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */