LCOV - code coverage report
Current view: top level - chart2/source/tools - Scaling.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 89 0.0 %
Date: 2014-04-14 Functions: 0 50 0.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           0 : static const OUString lcl_aServiceName_Logarithmic( "com.sun.star.chart2.LogarithmicScaling" );
      28           0 : static const OUString lcl_aServiceName_Exponential( "com.sun.star.chart2.ExponentialScaling" );
      29           0 : static const OUString lcl_aServiceName_Linear( "com.sun.star.chart2.LinearScaling" );
      30           0 : 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           0 : LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      40             :         m_fBase( 10.0 ),
      41             :         m_fLogOfBase( log( 10.0 ) ),
      42           0 :         m_xContext( xContext )
      43             : {
      44           0 : }
      45             : 
      46           0 : LogarithmicScaling::LogarithmicScaling( double fBase ) :
      47             :         m_fBase( fBase ),
      48           0 :         m_fLogOfBase( log( fBase ) )
      49             : {
      50           0 : }
      51             : 
      52           0 : LogarithmicScaling::~LogarithmicScaling()
      53             : {
      54           0 : }
      55             : 
      56             :     double SAL_CALL
      57           0 : LogarithmicScaling::doScaling( double value )
      58             :     throw (uno::RuntimeException, std::exception)
      59             : {
      60             :     double fResult;
      61           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
      62           0 :         ::rtl::math::setNan( & fResult );
      63             :     else
      64           0 :         fResult = log( value ) / m_fLogOfBase;
      65           0 :     return fResult;
      66             : }
      67             : 
      68             :     uno::Reference< XScaling > SAL_CALL
      69           0 : LogarithmicScaling::getInverseScaling()
      70             :     throw (uno::RuntimeException, std::exception)
      71             : {
      72           0 :     return new ExponentialScaling( m_fBase );
      73             : }
      74             : 
      75             :     OUString SAL_CALL
      76           0 : LogarithmicScaling::getServiceName()
      77             :     throw (uno::RuntimeException, std::exception)
      78             : {
      79           0 :     return lcl_aServiceName_Logarithmic;
      80             : }
      81             : 
      82           0 : uno::Sequence< OUString > LogarithmicScaling::getSupportedServiceNames_Static()
      83             : {
      84           0 :     return uno::Sequence< OUString >( & lcl_aServiceName_Logarithmic, 1 );
      85             : }
      86             : 
      87             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
      88           0 : APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
      89             : 
      90           0 : ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      91             :         m_fBase( 10.0 ),
      92           0 :         m_xContext( xContext )
      93             : {
      94           0 : }
      95             : 
      96           0 : ExponentialScaling::ExponentialScaling( double fBase ) :
      97           0 :         m_fBase( fBase )
      98             : {
      99           0 : }
     100             : 
     101           0 : ExponentialScaling::~ExponentialScaling()
     102             : {
     103           0 : }
     104             : 
     105             :     double SAL_CALL
     106           0 : ExponentialScaling::doScaling( double value )
     107             :     throw (uno::RuntimeException, std::exception)
     108             : {
     109             :     double fResult;
     110           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     111           0 :         ::rtl::math::setNan( & fResult );
     112             :     else
     113           0 :         fResult = pow( m_fBase, value );
     114           0 :     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           0 : uno::Sequence< OUString > ExponentialScaling::getSupportedServiceNames_Static()
     132             : {
     133           0 :     return uno::Sequence< OUString >( & lcl_aServiceName_Exponential, 1 );
     134             : }
     135             : 
     136             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     137           0 : APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
     138             : 
     139           0 : LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     140             :         m_fSlope( 1.0 ),
     141             :         m_fOffset( 0.0 ),
     142           0 :         m_xContext( xContext )
     143           0 : {}
     144             : 
     145           0 : LinearScaling::LinearScaling( double fSlope, double fOffset ) :
     146             :         m_fSlope( fSlope ),
     147           0 :         m_fOffset( fOffset )
     148           0 : {}
     149             : 
     150           0 : LinearScaling::~LinearScaling()
     151           0 : {}
     152             : 
     153           0 : double SAL_CALL LinearScaling::doScaling( double value )
     154             :     throw (uno::RuntimeException, std::exception)
     155             : {
     156             :     double fResult;
     157           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     158           0 :         ::rtl::math::setNan( & fResult );
     159             :     else
     160           0 :         fResult = m_fOffset + m_fSlope * value;
     161           0 :     return fResult;
     162             : }
     163             : 
     164             : uno::Reference< XScaling > SAL_CALL
     165           0 :     LinearScaling::getInverseScaling()
     166             :     throw (uno::RuntimeException, std::exception)
     167             : {
     168             :     // ToDo: ApproxEqual ?
     169           0 :     if( m_fSlope == 0 )
     170           0 :         throw uno::RuntimeException();
     171             : 
     172           0 :     return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
     173             : }
     174             : 
     175             :     OUString SAL_CALL
     176           0 : LinearScaling::getServiceName()
     177             :     throw (uno::RuntimeException, std::exception)
     178             : {
     179           0 :     return lcl_aServiceName_Linear;
     180             : }
     181             : 
     182           0 : uno::Sequence< OUString > LinearScaling::getSupportedServiceNames_Static()
     183             : {
     184           0 :     return uno::Sequence< OUString >( & lcl_aServiceName_Linear, 1 );
     185             : }
     186             : 
     187             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     188           0 : APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
     189             : 
     190           0 : PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     191             :         m_fExponent( 10.0 ),
     192           0 :         m_xContext( xContext )
     193           0 : {}
     194             : 
     195           0 : PowerScaling::PowerScaling( double fExponent ) :
     196           0 :         m_fExponent( fExponent )
     197           0 : {}
     198             : 
     199           0 : PowerScaling::~PowerScaling()
     200           0 : {}
     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           0 : uno::Sequence< OUString > PowerScaling::getSupportedServiceNames_Static()
     232             : {
     233           0 :     return uno::Sequence< OUString >( & lcl_aServiceName_Power, 1 );
     234             : }
     235             : 
     236             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     237           0 : APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
     238             : 
     239           0 : } //namespace chart
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10