qwt_transform.cpp 3.15 KB
Newer Older
Bryant's avatar
Bryant committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#include "qwt_transform.h"
#include "qwt_math.h"

#if QT_VERSION < 0x040601
#define qExp(x) ::exp(x)
#endif

//! Smallest allowed value for logarithmic scales: 1.0e-150
18
const double QwtLogTransform::LogMin = 1.0e-150;
Bryant's avatar
Bryant committed
19 20

//! Largest allowed value for logarithmic scales: 1.0e150
21
const  double QwtLogTransform::LogMax = 1.0e150;
Bryant's avatar
Bryant committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

//! Constructor
QwtTransform::QwtTransform()
{
}

//! Destructor
QwtTransform::~QwtTransform()
{
}

/*! 
  \param value Value to be bounded
  \return value unmodified
 */
double QwtTransform::bounded( double value ) const
{
    return value;
}

//! Constructor
QwtNullTransform::QwtNullTransform():
    QwtTransform()
{
}

//! Destructor
QwtNullTransform::~QwtNullTransform()
{
}

/*! 
  \param value Value to be transformed
  \return value unmodified
 */
double QwtNullTransform::transform( double value ) const
{
    return value;
}

/*! 
  \param value Value to be transformed
  \return value unmodified
 */
double QwtNullTransform::invTransform( double value ) const
{
    return value;
}

//! \return Clone of the transformation
QwtTransform *QwtNullTransform::copy() const
{
    return new QwtNullTransform();
}

//! Constructor
QwtLogTransform::QwtLogTransform():
    QwtTransform()
{
}

//! Destructor
QwtLogTransform::~QwtLogTransform()
{
}

/*! 
  \param value Value to be transformed
  \return log( value )
 */
double QwtLogTransform::transform( double value ) const
{
    return ::log( value );
}

/*! 
  \param value Value to be transformed
  \return exp( value )
 */
double QwtLogTransform::invTransform( double value ) const
{
    return qExp( value );
}

/*! 
  \param value Value to be bounded
  \return qBound( LogMin, value, LogMax )
 */
double QwtLogTransform::bounded( double value ) const
{
    return qBound( LogMin, value, LogMax );
}

//! \return Clone of the transformation
QwtTransform *QwtLogTransform::copy() const
{
    return new QwtLogTransform();
}

/*!
  Constructor
  \param exponent Exponent
*/
QwtPowerTransform::QwtPowerTransform( double exponent ):
    QwtTransform(),
    d_exponent( exponent )
{
}

//! Destructor
QwtPowerTransform::~QwtPowerTransform()
{
}

/*! 
  \param value Value to be transformed
  \return Exponentiation preserving the sign
 */
double QwtPowerTransform::transform( double value ) const
{
    if ( value < 0.0 )
        return -qPow( -value, 1.0 / d_exponent );
    else
        return qPow( value, 1.0 / d_exponent );
    
}

/*! 
  \param value Value to be transformed
  \return Inverse exponentiation preserving the sign
 */
double QwtPowerTransform::invTransform( double value ) const
{
    if ( value < 0.0 )
        return -qPow( -value, d_exponent );
    else
        return qPow( value, d_exponent );
}

//! \return Clone of the transformation
QwtTransform *QwtPowerTransform::copy() const
{
    return new QwtPowerTransform( d_exponent );
}