1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and / or modify it
6 // under the terms of the GNU Lesser General Public version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Message_ProgressScale.ixx>
16 static const Standard_Real ZERO = 1e-10;
17 static const Standard_Real INFINITE = 1e100;
19 //=======================================================================
20 //function : Message_ProgressScale
22 //=======================================================================
24 Message_ProgressScale::Message_ProgressScale () :
25 myMin(0.), myMax(100.), myStep(1.), myInfinite(Standard_False),
26 myFirst(0.), myLast(1.)
30 //=======================================================================
31 //function : LocalToBase
33 //=======================================================================
35 Standard_Real Message_ProgressScale::LocalToBase (const Standard_Real val) const
37 if ( val <= myMin ) return myFirst;
38 if ( myMax - myMin <= ZERO ) return myLast;
41 if ( val >= myMax ) return myLast;
42 return myFirst + ( myLast - myFirst ) * ( val - myMin ) / ( myMax - myMin );
44 Standard_Real x = ( val - myMin ) / ( myMax - myMin );
45 // return myFirst + ( myLast - myFirst ) * ( 1. - exp ( -x ) ); // exponent
46 return myFirst + ( myLast - myFirst ) * x / ( 1. + x ); // hyperbola
49 //=======================================================================
50 //function : BaseToLocal
52 //=======================================================================
54 Standard_Real Message_ProgressScale::BaseToLocal (const Standard_Real val) const
56 if ( myLast - val <= ZERO )
57 return myInfinite ? INFINITE : myMax;
59 return myMin + ( myMax - myMin ) * ( val - myFirst ) / ( myLast - myFirst );
60 // Standard_Real x = log ( ( val - myFirst ) / ( myLast - val ) ); // exponent
61 Standard_Real x = ( val - myFirst ) / ( myLast - val ); // hyperbola
62 return myMin + x * ( myMax - myMin );