LCOV - code coverage report
Current view: top level - chart2/source/tools - Scaling.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 89 57.3 %
Date: 2012-08-25 Functions: 24 50 48.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 100 21.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include "Scaling.hxx"
      21                 :            : #include <rtl/math.hxx>
      22                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      23                 :            : 
      24                 :            : namespace
      25                 :            : {
      26                 :            : 
      27                 :         16 : static const ::rtl::OUString lcl_aServiceName_Logarithmic(
      28                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LogarithmicScaling" ));
      29                 :         16 : static const ::rtl::OUString lcl_aServiceName_Exponential(
      30                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ExponentialScaling" ));
      31                 :         16 : static const ::rtl::OUString lcl_aServiceName_Linear(
      32                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LinearScaling" ));
      33                 :         16 : static const ::rtl::OUString lcl_aServiceName_Power(
      34                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PowerScaling" ));
      35                 :            : 
      36                 :            : }
      37                 :            : 
      38                 :            : //.............................................................................
      39                 :            : namespace chart
      40                 :            : {
      41                 :            : //.............................................................................
      42                 :            : using namespace ::com::sun::star;
      43                 :            : using namespace ::com::sun::star::chart2;
      44                 :            : 
      45                 :          0 : LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      46                 :            :         m_fBase( 10.0 ),
      47                 :            :         m_fLogOfBase( log( 10.0 ) ),
      48                 :          0 :         m_xContext( xContext )
      49                 :            : {
      50                 :          0 : }
      51                 :            : 
      52                 :          4 : LogarithmicScaling::LogarithmicScaling( double fBase ) :
      53                 :            :         m_fBase( fBase ),
      54                 :          4 :         m_fLogOfBase( log( fBase ) )
      55                 :            : {
      56                 :          4 : }
      57                 :            : 
      58                 :          4 : LogarithmicScaling::~LogarithmicScaling()
      59                 :            : {
      60         [ -  + ]:          8 : }
      61                 :            : 
      62                 :            :     double SAL_CALL
      63                 :      69216 : LogarithmicScaling::doScaling( double value )
      64                 :            :     throw (uno::RuntimeException)
      65                 :            : {
      66                 :            :     double fResult;
      67 [ +  - ][ -  + ]:      69216 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
                 [ -  + ]
      68                 :          0 :         ::rtl::math::setNan( & fResult );
      69                 :            :     else
      70                 :      69216 :         fResult = log( value ) / m_fLogOfBase;
      71                 :      69216 :     return fResult;
      72                 :            : }
      73                 :            : 
      74                 :            :     uno::Reference< XScaling > SAL_CALL
      75                 :       2030 : LogarithmicScaling::getInverseScaling()
      76                 :            :     throw (uno::RuntimeException)
      77                 :            : {
      78 [ +  - ][ +  - ]:       2030 :     return new ExponentialScaling( m_fBase );
      79                 :            : }
      80                 :            : 
      81                 :            :     ::rtl::OUString SAL_CALL
      82                 :        818 : LogarithmicScaling::getServiceName()
      83                 :            :     throw (uno::RuntimeException)
      84                 :            : {
      85                 :        818 :     return lcl_aServiceName_Logarithmic;
      86                 :            : }
      87                 :            : 
      88                 :          0 : uno::Sequence< ::rtl::OUString > LogarithmicScaling::getSupportedServiceNames_Static()
      89                 :            : {
      90                 :          0 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Logarithmic, 1 );
      91                 :            : }
      92                 :            : 
      93                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
      94 [ #  # ][ #  # ]:         30 : APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
         [ #  # ][ #  # ]
                 [ #  # ]
      95                 :            : 
      96                 :            : // ----------------------------------------
      97                 :            : 
      98                 :          0 : ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      99                 :            :         m_fBase( 10.0 ),
     100                 :          0 :         m_xContext( xContext )
     101                 :            : {
     102                 :          0 : }
     103                 :            : 
     104                 :       2030 : ExponentialScaling::ExponentialScaling( double fBase ) :
     105                 :       2030 :         m_fBase( fBase )
     106                 :            : {
     107                 :       2030 : }
     108                 :            : 
     109                 :       2030 : ExponentialScaling::~ExponentialScaling()
     110                 :            : {
     111         [ -  + ]:       4060 : }
     112                 :            : 
     113                 :            :     double SAL_CALL
     114                 :       9532 : ExponentialScaling::doScaling( double value )
     115                 :            :     throw (uno::RuntimeException)
     116                 :            : {
     117                 :            :     double fResult;
     118 [ +  - ][ -  + ]:       9532 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
                 [ -  + ]
     119                 :          0 :         ::rtl::math::setNan( & fResult );
     120                 :            :     else
     121                 :       9532 :         fResult = pow( m_fBase, value );
     122                 :       9532 :     return fResult;
     123                 :            : }
     124                 :            : 
     125                 :            :     uno::Reference< XScaling > SAL_CALL
     126                 :          0 : ExponentialScaling::getInverseScaling()
     127                 :            :     throw (uno::RuntimeException)
     128                 :            : {
     129 [ #  # ][ #  # ]:          0 :     return new LogarithmicScaling( m_fBase );
     130                 :            : }
     131                 :            : 
     132                 :            :     ::rtl::OUString SAL_CALL
     133                 :          0 : ExponentialScaling::getServiceName()
     134                 :            :     throw (uno::RuntimeException)
     135                 :            : {
     136                 :          0 :     return lcl_aServiceName_Exponential;
     137                 :            : }
     138                 :            : 
     139                 :          0 : uno::Sequence< ::rtl::OUString > ExponentialScaling::getSupportedServiceNames_Static()
     140                 :            : {
     141                 :          0 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Exponential, 1 );
     142                 :            : }
     143                 :            : 
     144                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     145 [ #  # ][ #  # ]:         30 : APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
         [ #  # ][ #  # ]
                 [ #  # ]
     146                 :            : 
     147                 :            : // ----------------------------------------
     148                 :            : 
     149                 :          6 : LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     150                 :            :         m_fSlope( 1.0 ),
     151                 :            :         m_fOffset( 0.0 ),
     152                 :          6 :         m_xContext( xContext )
     153                 :          6 : {}
     154                 :            : 
     155                 :       8524 : LinearScaling::LinearScaling( double fSlope, double fOffset ) :
     156                 :            :         m_fSlope( fSlope ),
     157                 :       8524 :         m_fOffset( fOffset )
     158                 :       8524 : {}
     159                 :            : 
     160                 :       8530 : LinearScaling::~LinearScaling()
     161         [ -  + ]:      17060 : {}
     162                 :            : 
     163                 :     320961 : double SAL_CALL LinearScaling::doScaling( double value )
     164                 :            :     throw (uno::RuntimeException)
     165                 :            : {
     166                 :            :     double fResult;
     167 [ +  + ][ -  + ]:     320961 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
                 [ +  + ]
     168                 :         84 :         ::rtl::math::setNan( & fResult );
     169                 :            :     else
     170                 :     320877 :         fResult = m_fOffset + m_fSlope * value;
     171                 :     320961 :     return fResult;
     172                 :            : }
     173                 :            : 
     174                 :            : uno::Reference< XScaling > SAL_CALL
     175                 :       8330 :     LinearScaling::getInverseScaling()
     176                 :            :     throw (uno::RuntimeException)
     177                 :            : {
     178                 :            :     // ToDo: ApproxEqual ?
     179         [ -  + ]:       8330 :     if( m_fSlope == 0 )
     180         [ #  # ]:          0 :         throw uno::RuntimeException();
     181                 :            : 
     182 [ +  - ][ +  - ]:       8330 :     return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
     183                 :            : }
     184                 :            : 
     185                 :            :     ::rtl::OUString SAL_CALL
     186                 :       2872 : LinearScaling::getServiceName()
     187                 :            :     throw (uno::RuntimeException)
     188                 :            : {
     189                 :       2872 :     return lcl_aServiceName_Linear;
     190                 :            : }
     191                 :            : 
     192                 :          3 : uno::Sequence< ::rtl::OUString > LinearScaling::getSupportedServiceNames_Static()
     193                 :            : {
     194                 :          3 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Linear, 1 );
     195                 :            : }
     196                 :            : 
     197                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     198 [ #  # ][ #  # ]:         30 : APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
         [ #  # ][ #  # ]
                 [ #  # ]
     199                 :            : 
     200                 :            : // ----------------------------------------
     201                 :            : 
     202                 :          0 : PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     203                 :            :         m_fExponent( 10.0 ),
     204                 :          0 :         m_xContext( xContext )
     205                 :          0 : {}
     206                 :            : 
     207                 :          0 : PowerScaling::PowerScaling( double fExponent ) :
     208                 :          0 :         m_fExponent( fExponent )
     209                 :          0 : {}
     210                 :            : 
     211                 :          0 : PowerScaling::~PowerScaling()
     212         [ #  # ]:          0 : {}
     213                 :            : 
     214                 :          0 : double SAL_CALL PowerScaling::doScaling( double value )
     215                 :            :     throw (uno::RuntimeException)
     216                 :            : {
     217                 :            :     double fResult;
     218 [ #  # ][ #  # ]:          0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
                 [ #  # ]
     219                 :          0 :         ::rtl::math::setNan( & fResult );
     220                 :            :     else
     221                 :          0 :         fResult = pow( value, m_fExponent );
     222                 :          0 :     return fResult;
     223                 :            : }
     224                 :            : 
     225                 :            : uno::Reference< XScaling > SAL_CALL
     226                 :          0 :     PowerScaling::getInverseScaling()
     227                 :            :     throw (uno::RuntimeException)
     228                 :            : {
     229                 :            :     // ToDo: ApproxEqual ?
     230         [ #  # ]:          0 :     if( m_fExponent == 0 )
     231         [ #  # ]:          0 :         throw uno::RuntimeException();
     232                 :            : 
     233 [ #  # ][ #  # ]:          0 :     return new PowerScaling( 1.0 / m_fExponent );
     234                 :            : }
     235                 :            : 
     236                 :            :     ::rtl::OUString SAL_CALL
     237                 :          0 : PowerScaling::getServiceName()
     238                 :            :     throw (uno::RuntimeException)
     239                 :            : {
     240                 :          0 :     return lcl_aServiceName_Power;
     241                 :            : }
     242                 :            : 
     243                 :          0 : uno::Sequence< ::rtl::OUString > PowerScaling::getSupportedServiceNames_Static()
     244                 :            : {
     245                 :          0 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Power, 1 );
     246                 :            : }
     247                 :            : 
     248                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     249 [ #  # ][ #  # ]:         30 : APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
         [ #  # ][ #  # ]
                 [ #  # ]
     250                 :            : 
     251                 :            : //.............................................................................
     252 [ +  - ][ +  - ]:         48 : } //namespace chart
     253                 :            : //.............................................................................
     254                 :            : 
     255                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10