bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / tools / Scaling.cxx
blob5dc4083597496a4a67a04b6cd4b4827a75f186a7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "Scaling.hxx"
21 #include <rtl/math.hxx>
22 #include "com/sun/star/uno/RuntimeException.hpp"
24 namespace
27 static const OUString lcl_aServiceName_Logarithmic( "com.sun.star.chart2.LogarithmicScaling" );
28 static const OUString lcl_aServiceName_Exponential( "com.sun.star.chart2.ExponentialScaling" );
29 static const OUString lcl_aServiceName_Linear( "com.sun.star.chart2.LinearScaling" );
30 static const OUString lcl_aServiceName_Power( "com.sun.star.chart2.PowerScaling" );
34 //.............................................................................
35 namespace chart
37 //.............................................................................
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::chart2;
41 LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
42 m_fBase( 10.0 ),
43 m_fLogOfBase( log( 10.0 ) ),
44 m_xContext( xContext )
48 LogarithmicScaling::LogarithmicScaling( double fBase ) :
49 m_fBase( fBase ),
50 m_fLogOfBase( log( fBase ) )
54 LogarithmicScaling::~LogarithmicScaling()
58 double SAL_CALL
59 LogarithmicScaling::doScaling( double value )
60 throw (uno::RuntimeException)
62 double fResult;
63 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
64 ::rtl::math::setNan( & fResult );
65 else
66 fResult = log( value ) / m_fLogOfBase;
67 return fResult;
70 uno::Reference< XScaling > SAL_CALL
71 LogarithmicScaling::getInverseScaling()
72 throw (uno::RuntimeException)
74 return new ExponentialScaling( m_fBase );
77 OUString SAL_CALL
78 LogarithmicScaling::getServiceName()
79 throw (uno::RuntimeException)
81 return lcl_aServiceName_Logarithmic;
84 uno::Sequence< OUString > LogarithmicScaling::getSupportedServiceNames_Static()
86 return uno::Sequence< OUString >( & lcl_aServiceName_Logarithmic, 1 );
89 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
90 APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
92 // ----------------------------------------
94 ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
95 m_fBase( 10.0 ),
96 m_xContext( xContext )
100 ExponentialScaling::ExponentialScaling( double fBase ) :
101 m_fBase( fBase )
105 ExponentialScaling::~ExponentialScaling()
109 double SAL_CALL
110 ExponentialScaling::doScaling( double value )
111 throw (uno::RuntimeException)
113 double fResult;
114 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
115 ::rtl::math::setNan( & fResult );
116 else
117 fResult = pow( m_fBase, value );
118 return fResult;
121 uno::Reference< XScaling > SAL_CALL
122 ExponentialScaling::getInverseScaling()
123 throw (uno::RuntimeException)
125 return new LogarithmicScaling( m_fBase );
128 OUString SAL_CALL
129 ExponentialScaling::getServiceName()
130 throw (uno::RuntimeException)
132 return lcl_aServiceName_Exponential;
135 uno::Sequence< OUString > ExponentialScaling::getSupportedServiceNames_Static()
137 return uno::Sequence< OUString >( & lcl_aServiceName_Exponential, 1 );
140 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
141 APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
143 // ----------------------------------------
145 LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
146 m_fSlope( 1.0 ),
147 m_fOffset( 0.0 ),
148 m_xContext( xContext )
151 LinearScaling::LinearScaling( double fSlope, double fOffset ) :
152 m_fSlope( fSlope ),
153 m_fOffset( fOffset )
156 LinearScaling::~LinearScaling()
159 double SAL_CALL LinearScaling::doScaling( double value )
160 throw (uno::RuntimeException)
162 double fResult;
163 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
164 ::rtl::math::setNan( & fResult );
165 else
166 fResult = m_fOffset + m_fSlope * value;
167 return fResult;
170 uno::Reference< XScaling > SAL_CALL
171 LinearScaling::getInverseScaling()
172 throw (uno::RuntimeException)
174 // ToDo: ApproxEqual ?
175 if( m_fSlope == 0 )
176 throw uno::RuntimeException();
178 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
181 OUString SAL_CALL
182 LinearScaling::getServiceName()
183 throw (uno::RuntimeException)
185 return lcl_aServiceName_Linear;
188 uno::Sequence< OUString > LinearScaling::getSupportedServiceNames_Static()
190 return uno::Sequence< OUString >( & lcl_aServiceName_Linear, 1 );
193 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
194 APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
196 // ----------------------------------------
198 PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
199 m_fExponent( 10.0 ),
200 m_xContext( xContext )
203 PowerScaling::PowerScaling( double fExponent ) :
204 m_fExponent( fExponent )
207 PowerScaling::~PowerScaling()
210 double SAL_CALL PowerScaling::doScaling( double value )
211 throw (uno::RuntimeException)
213 double fResult;
214 if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
215 ::rtl::math::setNan( & fResult );
216 else
217 fResult = pow( value, m_fExponent );
218 return fResult;
221 uno::Reference< XScaling > SAL_CALL
222 PowerScaling::getInverseScaling()
223 throw (uno::RuntimeException)
225 // ToDo: ApproxEqual ?
226 if( m_fExponent == 0 )
227 throw uno::RuntimeException();
229 return new PowerScaling( 1.0 / m_fExponent );
232 OUString SAL_CALL
233 PowerScaling::getServiceName()
234 throw (uno::RuntimeException)
236 return lcl_aServiceName_Power;
239 uno::Sequence< OUString > PowerScaling::getSupportedServiceNames_Static()
241 return uno::Sequence< OUString >( & lcl_aServiceName_Power, 1 );
244 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
245 APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
247 //.............................................................................
248 } //namespace chart
249 //.............................................................................
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */