1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
; }
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";
39 using namespace ::com::sun::star
;
40 using namespace ::com::sun::star::chart2
;
42 LogarithmicScaling::LogarithmicScaling() :
44 m_fLogOfBase( log( 10.0 ) )
48 LogarithmicScaling::LogarithmicScaling( double fBase
) :
50 m_fLogOfBase( log( fBase
) )
54 LogarithmicScaling::~LogarithmicScaling()
58 double SAL_CALL
LogarithmicScaling::doScaling( double value
)
61 if( std::isnan( value
) || std::isinf( value
) )
62 ::rtl::math::setNan( & fResult
);
64 fResult
= log( value
) / m_fLogOfBase
;
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() :
98 ExponentialScaling::ExponentialScaling( double fBase
) :
103 ExponentialScaling::~ExponentialScaling()
107 double SAL_CALL
ExponentialScaling::doScaling( double value
)
110 if( std::isnan( value
) || std::isinf( value
) )
111 ::rtl::math::setNan( & fResult
);
113 fResult
= pow( m_fBase
, value
);
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() :
147 LinearScaling::LinearScaling( double fSlope
, double fOffset
) :
152 LinearScaling::~LinearScaling()
155 double SAL_CALL
LinearScaling::doScaling( double value
)
158 if( std::isnan( value
) || std::isinf( value
) )
159 ::rtl::math::setNan( & fResult
);
161 fResult
= m_fOffset
+ m_fSlope
* value
;
165 uno::Reference
< XScaling
> SAL_CALL
166 LinearScaling::getInverseScaling()
168 // ToDo: ApproxEqual ?
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() :
199 PowerScaling::PowerScaling( double fExponent
) :
200 m_fExponent( fExponent
)
203 PowerScaling::~PowerScaling()
206 double SAL_CALL
PowerScaling::doScaling( double value
)
209 if( std::isnan( value
) || std::isinf( value
) )
210 ::rtl::math::setNan( & fResult
);
212 fResult
= pow( value
, m_fExponent
);
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
);
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
};
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: */