LCOV - code coverage report
Current view: top level - chart2/source/tools - Scaling.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 68 89 76.4 %
Date: 2014-04-11 Functions: 32 50 64.0 %
Legend: Lines: hit not hit

          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 OUString lcl_aServiceName_Logarithmic( "com.sun.star.chart2.LogarithmicScaling" );
      28          16 : static const OUString lcl_aServiceName_Exponential( "com.sun.star.chart2.ExponentialScaling" );
      29          16 : static const OUString lcl_aServiceName_Linear( "com.sun.star.chart2.LinearScaling" );
      30          16 : static const OUString lcl_aServiceName_Power( "com.sun.star.chart2.PowerScaling" );
      31             : 
      32             : }
      33             : 
      34             : namespace chart
      35             : {
      36             : using namespace ::com::sun::star;
      37             : using namespace ::com::sun::star::chart2;
      38             : 
      39           3 : LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      40             :         m_fBase( 10.0 ),
      41             :         m_fLogOfBase( log( 10.0 ) ),
      42           3 :         m_xContext( xContext )
      43             : {
      44           3 : }
      45             : 
      46           4 : LogarithmicScaling::LogarithmicScaling( double fBase ) :
      47             :         m_fBase( fBase ),
      48           4 :         m_fLogOfBase( log( fBase ) )
      49             : {
      50           4 : }
      51             : 
      52          10 : LogarithmicScaling::~LogarithmicScaling()
      53             : {
      54          10 : }
      55             : 
      56             :     double SAL_CALL
      57       37219 : LogarithmicScaling::doScaling( double value )
      58             :     throw (uno::RuntimeException, std::exception)
      59             : {
      60             :     double fResult;
      61       37219 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
      62           0 :         ::rtl::math::setNan( & fResult );
      63             :     else
      64       37219 :         fResult = log( value ) / m_fLogOfBase;
      65       37219 :     return fResult;
      66             : }
      67             : 
      68             :     uno::Reference< XScaling > SAL_CALL
      69        1081 : LogarithmicScaling::getInverseScaling()
      70             :     throw (uno::RuntimeException, std::exception)
      71             : {
      72        1081 :     return new ExponentialScaling( m_fBase );
      73             : }
      74             : 
      75             :     OUString SAL_CALL
      76         470 : LogarithmicScaling::getServiceName()
      77             :     throw (uno::RuntimeException, std::exception)
      78             : {
      79         470 :     return lcl_aServiceName_Logarithmic;
      80             : }
      81             : 
      82           2 : uno::Sequence< OUString > LogarithmicScaling::getSupportedServiceNames_Static()
      83             : {
      84           2 :     return uno::Sequence< OUString >( & lcl_aServiceName_Logarithmic, 1 );
      85             : }
      86             : 
      87             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
      88          43 : APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
      89             : 
      90           1 : ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      91             :         m_fBase( 10.0 ),
      92           1 :         m_xContext( xContext )
      93             : {
      94           1 : }
      95             : 
      96        1081 : ExponentialScaling::ExponentialScaling( double fBase ) :
      97        1081 :         m_fBase( fBase )
      98             : {
      99        1081 : }
     100             : 
     101        2160 : ExponentialScaling::~ExponentialScaling()
     102             : {
     103        2160 : }
     104             : 
     105             :     double SAL_CALL
     106        5004 : ExponentialScaling::doScaling( double value )
     107             :     throw (uno::RuntimeException, std::exception)
     108             : {
     109             :     double fResult;
     110        5004 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     111           0 :         ::rtl::math::setNan( & fResult );
     112             :     else
     113        5004 :         fResult = pow( m_fBase, value );
     114        5004 :     return fResult;
     115             : }
     116             : 
     117             :     uno::Reference< XScaling > SAL_CALL
     118           0 : ExponentialScaling::getInverseScaling()
     119             :     throw (uno::RuntimeException, std::exception)
     120             : {
     121           0 :     return new LogarithmicScaling( m_fBase );
     122             : }
     123             : 
     124             :     OUString SAL_CALL
     125           0 : ExponentialScaling::getServiceName()
     126             :     throw (uno::RuntimeException, std::exception)
     127             : {
     128           0 :     return lcl_aServiceName_Exponential;
     129             : }
     130             : 
     131           1 : uno::Sequence< OUString > ExponentialScaling::getSupportedServiceNames_Static()
     132             : {
     133           1 :     return uno::Sequence< OUString >( & lcl_aServiceName_Exponential, 1 );
     134             : }
     135             : 
     136             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     137          43 : APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
     138             : 
     139         125 : LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     140             :         m_fSlope( 1.0 ),
     141             :         m_fOffset( 0.0 ),
     142         125 :         m_xContext( xContext )
     143         125 : {}
     144             : 
     145        6419 : LinearScaling::LinearScaling( double fSlope, double fOffset ) :
     146             :         m_fSlope( fSlope ),
     147        6419 :         m_fOffset( fOffset )
     148        6419 : {}
     149             : 
     150       12434 : LinearScaling::~LinearScaling()
     151       12434 : {}
     152             : 
     153      219365 : double SAL_CALL LinearScaling::doScaling( double value )
     154             :     throw (uno::RuntimeException, std::exception)
     155             : {
     156             :     double fResult;
     157      219365 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     158          42 :         ::rtl::math::setNan( & fResult );
     159             :     else
     160      219323 :         fResult = m_fOffset + m_fSlope * value;
     161      219365 :     return fResult;
     162             : }
     163             : 
     164             : uno::Reference< XScaling > SAL_CALL
     165        5859 :     LinearScaling::getInverseScaling()
     166             :     throw (uno::RuntimeException, std::exception)
     167             : {
     168             :     // ToDo: ApproxEqual ?
     169        5859 :     if( m_fSlope == 0 )
     170           0 :         throw uno::RuntimeException();
     171             : 
     172        5859 :     return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
     173             : }
     174             : 
     175             :     OUString SAL_CALL
     176        2999 : LinearScaling::getServiceName()
     177             :     throw (uno::RuntimeException, std::exception)
     178             : {
     179        2999 :     return lcl_aServiceName_Linear;
     180             : }
     181             : 
     182           7 : uno::Sequence< OUString > LinearScaling::getSupportedServiceNames_Static()
     183             : {
     184           7 :     return uno::Sequence< OUString >( & lcl_aServiceName_Linear, 1 );
     185             : }
     186             : 
     187             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     188          43 : APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
     189             : 
     190           1 : PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     191             :         m_fExponent( 10.0 ),
     192           1 :         m_xContext( xContext )
     193           1 : {}
     194             : 
     195           0 : PowerScaling::PowerScaling( double fExponent ) :
     196           0 :         m_fExponent( fExponent )
     197           0 : {}
     198             : 
     199           2 : PowerScaling::~PowerScaling()
     200           2 : {}
     201             : 
     202           0 : double SAL_CALL PowerScaling::doScaling( double value )
     203             :     throw (uno::RuntimeException, std::exception)
     204             : {
     205             :     double fResult;
     206           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     207           0 :         ::rtl::math::setNan( & fResult );
     208             :     else
     209           0 :         fResult = pow( value, m_fExponent );
     210           0 :     return fResult;
     211             : }
     212             : 
     213             : uno::Reference< XScaling > SAL_CALL
     214           0 :     PowerScaling::getInverseScaling()
     215             :     throw (uno::RuntimeException, std::exception)
     216             : {
     217             :     // ToDo: ApproxEqual ?
     218           0 :     if( m_fExponent == 0 )
     219           0 :         throw uno::RuntimeException();
     220             : 
     221           0 :     return new PowerScaling( 1.0 / m_fExponent );
     222             : }
     223             : 
     224             :     OUString SAL_CALL
     225           0 : PowerScaling::getServiceName()
     226             :     throw (uno::RuntimeException, std::exception)
     227             : {
     228           0 :     return lcl_aServiceName_Power;
     229             : }
     230             : 
     231           1 : uno::Sequence< OUString > PowerScaling::getSupportedServiceNames_Static()
     232             : {
     233           1 :     return uno::Sequence< OUString >( & lcl_aServiceName_Power, 1 );
     234             : }
     235             : 
     236             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     237          43 : APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
     238             : 
     239          48 : } //namespace chart
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10