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"
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 //.............................................................................
37 //.............................................................................
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::chart2
;
41 LogarithmicScaling::LogarithmicScaling( const uno::Reference
< uno::XComponentContext
> & xContext
) :
43 m_fLogOfBase( log( 10.0 ) ),
44 m_xContext( xContext
)
48 LogarithmicScaling::LogarithmicScaling( double fBase
) :
50 m_fLogOfBase( log( fBase
) )
54 LogarithmicScaling::~LogarithmicScaling()
59 LogarithmicScaling::doScaling( double value
)
60 throw (uno::RuntimeException
)
63 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
64 ::rtl::math::setNan( & fResult
);
66 fResult
= log( value
) / m_fLogOfBase
;
70 uno::Reference
< XScaling
> SAL_CALL
71 LogarithmicScaling::getInverseScaling()
72 throw (uno::RuntimeException
)
74 return new ExponentialScaling( m_fBase
);
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
) :
96 m_xContext( xContext
)
100 ExponentialScaling::ExponentialScaling( double fBase
) :
105 ExponentialScaling::~ExponentialScaling()
110 ExponentialScaling::doScaling( double value
)
111 throw (uno::RuntimeException
)
114 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
115 ::rtl::math::setNan( & fResult
);
117 fResult
= pow( m_fBase
, value
);
121 uno::Reference
< XScaling
> SAL_CALL
122 ExponentialScaling::getInverseScaling()
123 throw (uno::RuntimeException
)
125 return new LogarithmicScaling( m_fBase
);
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
) :
148 m_xContext( xContext
)
151 LinearScaling::LinearScaling( double fSlope
, double fOffset
) :
156 LinearScaling::~LinearScaling()
159 double SAL_CALL
LinearScaling::doScaling( double value
)
160 throw (uno::RuntimeException
)
163 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
164 ::rtl::math::setNan( & fResult
);
166 fResult
= m_fOffset
+ m_fSlope
* value
;
170 uno::Reference
< XScaling
> SAL_CALL
171 LinearScaling::getInverseScaling()
172 throw (uno::RuntimeException
)
174 // ToDo: ApproxEqual ?
176 throw uno::RuntimeException();
178 return new LinearScaling( 1.0 / m_fSlope
, m_fOffset
/ m_fSlope
);
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
) :
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
)
214 if( ::rtl::math::isNan( value
) || ::rtl::math::isInf( value
) )
215 ::rtl::math::setNan( & fResult
);
217 fResult
= pow( value
, m_fExponent
);
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
);
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 //.............................................................................
249 //.............................................................................
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */