1beb58d7 |
1 | // Created by: Kirill GAVRILOV |
2 | // Copyright (c) 2016 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #ifndef _NCollection_Lerp_HeaderFile |
16 | #define _NCollection_Lerp_HeaderFile |
17 | |
18 | //! Simple linear interpolation tool (also known as mix() in GLSL). |
19 | //! The main purpose of this template class is making interpolation routines more readable. |
20 | template<class T> |
21 | class NCollection_Lerp |
22 | { |
23 | public: |
24 | //! Compute interpolated value between two values. |
25 | //! @param theStart first value |
26 | //! @param theEnd second value |
27 | //! @param theT normalized interpolation coefficient within [0, 1] range, |
28 | //! with 0 pointing to theStart and 1 to theEnd. |
29 | static T Interpolate (const T& theStart, |
30 | const T& theEnd, |
31 | double theT) |
32 | { |
33 | T aResult; |
34 | NCollection_Lerp aLerp (theStart, theEnd); |
35 | aLerp.Interpolate (theT, aResult); |
36 | return aResult; |
37 | } |
38 | |
39 | public: |
40 | |
41 | //! Empty constructor |
42 | NCollection_Lerp() : myStart(), myEnd() {} |
43 | |
44 | //! Main constructor. |
45 | NCollection_Lerp (const T& theStart, const T& theEnd) |
46 | { |
47 | Init (theStart, theEnd); |
48 | } |
49 | |
50 | //! Initialize values. |
51 | void Init (const T& theStart, const T& theEnd) |
52 | { |
53 | myStart = theStart; |
54 | myEnd = theEnd; |
55 | } |
56 | |
57 | //! Compute interpolated value between two values. |
58 | //! @param theT normalized interpolation coefficient within [0, 1] range, |
59 | //! with 0 pointing to first value and 1 to the second value. |
60 | //! @param theResult [out] interpolated value |
61 | void Interpolate (double theT, T& theResult) const |
62 | { |
63 | theResult = (1.0 - theT) * myStart + theT * myEnd; |
64 | } |
65 | |
66 | private: |
67 | T myStart; |
68 | T myEnd; |
69 | }; |
70 | |
71 | #endif // _NCollection_Lerp_HeaderFile |