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

Generated by: LCOV version 1.10