|
||||
File indexing completed on 2025-01-18 10:04:19
0001 // Created by: Kirill GAVRILOV 0002 // Copyright (c) 2016 OPEN CASCADE SAS 0003 // 0004 // This file is part of Open CASCADE Technology software library. 0005 // 0006 // This library is free software; you can redistribute it and/or modify it under 0007 // the terms of the GNU Lesser General Public License version 2.1 as published 0008 // by the Free Software Foundation, with special exception defined in the file 0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0010 // distribution for complete text of the license and disclaimer of any warranty. 0011 // 0012 // Alternatively, this file may be used under the terms of Open CASCADE 0013 // commercial license or contractual agreement. 0014 0015 #ifndef _NCollection_Lerp_HeaderFile 0016 #define _NCollection_Lerp_HeaderFile 0017 0018 //! Simple linear interpolation tool (also known as mix() in GLSL). 0019 //! The main purpose of this template class is making interpolation routines more readable. 0020 template<class T> 0021 class NCollection_Lerp 0022 { 0023 public: 0024 //! Compute interpolated value between two values. 0025 //! @param theStart first value 0026 //! @param theEnd second value 0027 //! @param theT normalized interpolation coefficient within [0, 1] range, 0028 //! with 0 pointing to theStart and 1 to theEnd. 0029 static T Interpolate (const T& theStart, 0030 const T& theEnd, 0031 double theT) 0032 { 0033 T aResult; 0034 NCollection_Lerp aLerp (theStart, theEnd); 0035 aLerp.Interpolate (theT, aResult); 0036 return aResult; 0037 } 0038 0039 public: 0040 0041 //! Empty constructor 0042 NCollection_Lerp() : myStart(), myEnd() {} 0043 0044 //! Main constructor. 0045 NCollection_Lerp (const T& theStart, const T& theEnd) 0046 { 0047 Init (theStart, theEnd); 0048 } 0049 0050 //! Initialize values. 0051 void Init (const T& theStart, const T& theEnd) 0052 { 0053 myStart = theStart; 0054 myEnd = theEnd; 0055 } 0056 0057 //! Compute interpolated value between two values. 0058 //! @param theT normalized interpolation coefficient within [0, 1] range, 0059 //! with 0 pointing to first value and 1 to the second value. 0060 //! @param theResult [out] interpolated value 0061 void Interpolate (double theT, T& theResult) const 0062 { 0063 theResult = (1.0 - theT) * myStart + theT * myEnd; 0064 } 0065 0066 private: 0067 T myStart; 0068 T myEnd; 0069 }; 0070 0071 #endif // _NCollection_Lerp_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |