nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / tools / Scaling.cxx
blob27a9c51a7a440653ff36469f3aed6bc71b534a52
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>
23 #include <cppuhelper/supportsservice.hxx>
25 namespace com::sun::star::uno { class XComponentContext; }
27 namespace
30 const char lcl_aServiceName_Logarithmic[] = "com.sun.star.chart2.LogarithmicScaling";
31 const char lcl_aServiceName_Exponential[] = "com.sun.star.chart2.ExponentialScaling";
32 const char lcl_aServiceName_Linear[] = "com.sun.star.chart2.LinearScaling";
33 const char lcl_aServiceName_Power[] = "com.sun.star.chart2.PowerScaling";
37 namespace chart
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::chart2;
42 LogarithmicScaling::LogarithmicScaling() :
43 m_fBase( 10.0 ),
44 m_fLogOfBase( log( 10.0 ) )
48 LogarithmicScaling::LogarithmicScaling( double fBase ) :
49 m_fBase( fBase ),
50 m_fLogOfBase( log( fBase ) )
54 LogarithmicScaling::~LogarithmicScaling()
58 double SAL_CALL LogarithmicScaling::doScaling( double value )
60 double fResult;
61 if( std::isnan( value ) || std::isinf( value ) )
62 ::rtl::math::setNan( & fResult );
63 else
64 fResult = log( value ) / m_fLogOfBase;
65 return fResult;
68 uno::Reference< XScaling > SAL_CALL LogarithmicScaling::getInverseScaling()
70 return new ExponentialScaling( m_fBase );
73 OUString SAL_CALL LogarithmicScaling::getServiceName()
75 return lcl_aServiceName_Logarithmic;
78 OUString SAL_CALL LogarithmicScaling::getImplementationName()
80 return lcl_aServiceName_Logarithmic;
83 sal_Bool SAL_CALL LogarithmicScaling::supportsService( const OUString& rServiceName )
85 return cppu::supportsService(this, rServiceName);
88 css::uno::Sequence< OUString > SAL_CALL LogarithmicScaling::getSupportedServiceNames()
90 return { lcl_aServiceName_Logarithmic };
93 ExponentialScaling::ExponentialScaling() :
94 m_fBase( 10.0 )
98 ExponentialScaling::ExponentialScaling( double fBase ) :
99 m_fBase( fBase )
103 ExponentialScaling::~ExponentialScaling()
107 double SAL_CALL ExponentialScaling::doScaling( double value )
109 double fResult;
110 if( std::isnan( value ) || std::isinf( value ) )
111 ::rtl::math::setNan( & fResult );
112 else
113 fResult = pow( m_fBase, value );
114 return fResult;
117 uno::Reference< XScaling > SAL_CALL ExponentialScaling::getInverseScaling()
119 return new LogarithmicScaling( m_fBase );
122 OUString SAL_CALL ExponentialScaling::getServiceName()
124 return lcl_aServiceName_Exponential;
127 OUString SAL_CALL ExponentialScaling::getImplementationName()
129 return lcl_aServiceName_Exponential;
132 sal_Bool SAL_CALL ExponentialScaling::supportsService( const OUString& rServiceName )
134 return cppu::supportsService(this, rServiceName);
137 css::uno::Sequence< OUString > SAL_CALL ExponentialScaling::getSupportedServiceNames()
139 return { lcl_aServiceName_Exponential };
142 LinearScaling::LinearScaling() :
143 m_fSlope( 1.0 ),
144 m_fOffset( 0.0 )
147 LinearScaling::LinearScaling( double fSlope, double fOffset ) :
148 m_fSlope( fSlope ),
149 m_fOffset( fOffset )
152 LinearScaling::~LinearScaling()
155 double SAL_CALL LinearScaling::doScaling( double value )
157 double fResult;
158 if( std::isnan( value ) || std::isinf( value ) )
159 ::rtl::math::setNan( & fResult );
160 else
161 fResult = m_fOffset + m_fSlope * value;
162 return fResult;
165 uno::Reference< XScaling > SAL_CALL
166 LinearScaling::getInverseScaling()
168 // ToDo: ApproxEqual ?
169 if( m_fSlope == 0 )
170 throw uno::RuntimeException();
172 return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
175 OUString SAL_CALL LinearScaling::getServiceName()
177 return lcl_aServiceName_Linear;
180 OUString SAL_CALL LinearScaling::getImplementationName()
182 return lcl_aServiceName_Linear ;
185 sal_Bool SAL_CALL LinearScaling::supportsService( const OUString& rServiceName )
187 return cppu::supportsService(this, rServiceName);
190 css::uno::Sequence< OUString > SAL_CALL LinearScaling::getSupportedServiceNames()
192 return { lcl_aServiceName_Linear };
195 PowerScaling::PowerScaling() :
196 m_fExponent( 10.0 )
199 PowerScaling::PowerScaling( double fExponent ) :
200 m_fExponent( fExponent )
203 PowerScaling::~PowerScaling()
206 double SAL_CALL PowerScaling::doScaling( double value )
208 double fResult;
209 if( std::isnan( value ) || std::isinf( value ) )
210 ::rtl::math::setNan( & fResult );
211 else
212 fResult = pow( value, m_fExponent );
213 return fResult;
216 uno::Reference< XScaling > SAL_CALL
217 PowerScaling::getInverseScaling()
219 // ToDo: ApproxEqual ?
220 if( m_fExponent == 0 )
221 throw uno::RuntimeException();
223 return new PowerScaling( 1.0 / m_fExponent );
226 OUString SAL_CALL
227 PowerScaling::getServiceName()
229 return lcl_aServiceName_Power;
232 OUString SAL_CALL PowerScaling::getImplementationName()
234 return lcl_aServiceName_Power;
237 sal_Bool SAL_CALL PowerScaling::supportsService( const OUString& rServiceName )
239 return cppu::supportsService(this, rServiceName);
242 css::uno::Sequence< OUString > SAL_CALL PowerScaling::getSupportedServiceNames()
244 return { lcl_aServiceName_Power };
247 } //namespace chart
249 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
250 com_sun_star_chart2_LinearScaling_get_implementation(css::uno::XComponentContext *,
251 css::uno::Sequence<css::uno::Any> const &)
253 return cppu::acquire(new chart::LinearScaling );
256 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
257 com_sun_star_chart2_ExponentialScaling_get_implementation(css::uno::XComponentContext *,
258 css::uno::Sequence<css::uno::Any> const &)
260 return cppu::acquire(new chart::ExponentialScaling );
263 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
264 com_sun_star_chart2_LogarithmicScaling_get_implementation(css::uno::XComponentContext *,
265 css::uno::Sequence<css::uno::Any> const &)
267 return cppu::acquire(new chart::LogarithmicScaling );
270 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
271 com_sun_star_chart2_PowerScaling_get_implementation(css::uno::XComponentContext *,
272 css::uno::Sequence<css::uno::Any> const &)
274 return cppu::acquire(new chart::PowerScaling );
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */