1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <basegfx/basegfxdllapi.h>
25 namespace com::sun::star::uno
{
26 template<typename T
> class Sequence
;
29 namespace basegfx::utils
31 /** Lerp in a vector of key stops
33 This class holds a key stop vector and provides the
34 functionality to lerp inside it. Useful e.g. for
35 multi-stop gradients, or the SMIL key time activity.
37 For those, given a global [0,1] lerp alpha, one need to
38 find the suitable bucket index from key stop vector, and
39 then calculate the relative alpha between the two buckets
42 class BASEGFX_DLLPUBLIC KeyStopLerp
45 typedef std::pair
<std::ptrdiff_t,double> ResultType
;
47 /** Create lerper with given vector of stops
51 Vector of stops, must contain at least two elements
52 (though preferably more, otherwise you probably don't
53 need key stop lerping in the first place). All
54 elements must be of monotonically increasing value.
56 explicit KeyStopLerp( std::vector
<double>&& rKeyStops
);
58 /** Create lerper with given sequence of stops
62 Sequence of stops, must contain at least two elements
63 (though preferably more, otherwise you probably don't
64 need key stop lerping in the first place). All
65 elements must be of monotonically increasing value.
67 explicit KeyStopLerp( const css::uno::Sequence
<double>& rKeyStops
);
69 /** Find two nearest bucket index & interpolate
72 Find bucket index i, with keyStops[i] < fAlpha <=
73 keyStops[i+1]. Return new alpha value in [0,1),
74 proportional to fAlpha's position between keyStops[i]
77 ResultType
lerp(double fAlpha
) const;
80 std::vector
<double> maKeyStops
;
81 mutable std::ptrdiff_t mnLastIndex
;
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */