Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-17 09:21:24

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, const T& theEnd, double theT)
0030   {
0031     T                aResult;
0032     NCollection_Lerp aLerp(theStart, theEnd);
0033     aLerp.Interpolate(theT, aResult);
0034     return aResult;
0035   }
0036 
0037 public:
0038   //! Empty constructor
0039   NCollection_Lerp()
0040       : myStart(),
0041         myEnd()
0042   {
0043   }
0044 
0045   //! Main constructor.
0046   NCollection_Lerp(const T& theStart, const T& theEnd) { Init(theStart, theEnd); }
0047 
0048   //! Initialize values.
0049   void Init(const T& theStart, const T& theEnd)
0050   {
0051     myStart = theStart;
0052     myEnd   = theEnd;
0053   }
0054 
0055   //! Compute interpolated value between two values.
0056   //! @param theT normalized interpolation coefficient within [0, 1] range,
0057   //!             with 0 pointing to first value and 1 to the second value.
0058   //! @param[out] theResult  interpolated value
0059   void Interpolate(double theT, T& theResult) const
0060   {
0061     theResult = (1.0 - theT) * myStart + theT * myEnd;
0062   }
0063 
0064 private:
0065   T myStart;
0066   T myEnd;
0067 };
0068 
0069 #endif // _NCollection_Lerp_HeaderFile