/src/libreoffice/chart2/source/tools/Scaling.cxx
Line | Count | Source |
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 <com/sun/star/uno/RuntimeException.hpp> |
22 | | #include <cppuhelper/supportsservice.hxx> |
23 | | |
24 | | #include <cmath> |
25 | | #include <limits> |
26 | | |
27 | | namespace com::sun::star::uno { class XComponentContext; } |
28 | | |
29 | | namespace |
30 | | { |
31 | | |
32 | | constexpr OUString lcl_aServiceName_Logarithmic = u"com.sun.star.chart2.LogarithmicScaling"_ustr; |
33 | | constexpr OUString lcl_aServiceName_Exponential = u"com.sun.star.chart2.ExponentialScaling"_ustr; |
34 | | constexpr OUString lcl_aServiceName_Linear = u"com.sun.star.chart2.LinearScaling"_ustr; |
35 | | constexpr OUString lcl_aServiceName_Power = u"com.sun.star.chart2.PowerScaling"_ustr; |
36 | | |
37 | | } |
38 | | |
39 | | namespace chart |
40 | | { |
41 | | using namespace ::com::sun::star; |
42 | | using namespace ::com::sun::star::chart2; |
43 | | |
44 | | LogarithmicScaling::LogarithmicScaling() : |
45 | 0 | m_fBase( 10.0 ), |
46 | 0 | m_fLogOfBase( log( 10.0 ) ) |
47 | 0 | { |
48 | 0 | } |
49 | | |
50 | | LogarithmicScaling::LogarithmicScaling( double fBase ) : |
51 | 0 | m_fBase( fBase ), |
52 | 0 | m_fLogOfBase( log( fBase ) ) |
53 | 0 | { |
54 | 0 | } |
55 | | |
56 | | LogarithmicScaling::~LogarithmicScaling() |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | double SAL_CALL LogarithmicScaling::doScaling( double value ) |
61 | 0 | { |
62 | 0 | if( std::isnan( value ) || std::isinf( value ) ) |
63 | 0 | return std::numeric_limits<double>::quiet_NaN(); |
64 | 0 | return std::log( value ) / m_fLogOfBase; |
65 | 0 | } |
66 | | |
67 | | uno::Reference< XScaling > SAL_CALL LogarithmicScaling::getInverseScaling() |
68 | 0 | { |
69 | 0 | return new ExponentialScaling( m_fBase ); |
70 | 0 | } |
71 | | |
72 | | OUString SAL_CALL LogarithmicScaling::getServiceName() |
73 | 0 | { |
74 | 0 | return lcl_aServiceName_Logarithmic; |
75 | 0 | } |
76 | | |
77 | | OUString SAL_CALL LogarithmicScaling::getImplementationName() |
78 | 0 | { |
79 | 0 | return lcl_aServiceName_Logarithmic; |
80 | 0 | } |
81 | | |
82 | | sal_Bool SAL_CALL LogarithmicScaling::supportsService( const OUString& rServiceName ) |
83 | 0 | { |
84 | 0 | return cppu::supportsService(this, rServiceName); |
85 | 0 | } |
86 | | |
87 | | css::uno::Sequence< OUString > SAL_CALL LogarithmicScaling::getSupportedServiceNames() |
88 | 0 | { |
89 | 0 | return { lcl_aServiceName_Logarithmic }; |
90 | 0 | } |
91 | | |
92 | | ExponentialScaling::ExponentialScaling() : |
93 | 0 | m_fBase( 10.0 ) |
94 | 0 | { |
95 | 0 | } |
96 | | |
97 | | ExponentialScaling::ExponentialScaling( double fBase ) : |
98 | 0 | m_fBase( fBase ) |
99 | 0 | { |
100 | 0 | } |
101 | | |
102 | | ExponentialScaling::~ExponentialScaling() |
103 | 0 | { |
104 | 0 | } |
105 | | |
106 | | double SAL_CALL ExponentialScaling::doScaling( double value ) |
107 | 0 | { |
108 | 0 | if( std::isnan( value ) || std::isinf( value ) ) |
109 | 0 | return std::numeric_limits<double>::quiet_NaN(); |
110 | 0 | return std::pow( m_fBase, value ); |
111 | 0 | } |
112 | | |
113 | | uno::Reference< XScaling > SAL_CALL ExponentialScaling::getInverseScaling() |
114 | 0 | { |
115 | 0 | return new LogarithmicScaling( m_fBase ); |
116 | 0 | } |
117 | | |
118 | | OUString SAL_CALL ExponentialScaling::getServiceName() |
119 | 0 | { |
120 | 0 | return lcl_aServiceName_Exponential; |
121 | 0 | } |
122 | | |
123 | | OUString SAL_CALL ExponentialScaling::getImplementationName() |
124 | 0 | { |
125 | 0 | return lcl_aServiceName_Exponential; |
126 | 0 | } |
127 | | |
128 | | sal_Bool SAL_CALL ExponentialScaling::supportsService( const OUString& rServiceName ) |
129 | 0 | { |
130 | 0 | return cppu::supportsService(this, rServiceName); |
131 | 0 | } |
132 | | |
133 | | css::uno::Sequence< OUString > SAL_CALL ExponentialScaling::getSupportedServiceNames() |
134 | 0 | { |
135 | 0 | return { lcl_aServiceName_Exponential }; |
136 | 0 | } |
137 | | |
138 | | LinearScaling::LinearScaling() : |
139 | 0 | m_fSlope( 1.0 ), |
140 | 0 | m_fOffset( 0.0 ) |
141 | 0 | {} |
142 | | |
143 | | LinearScaling::LinearScaling( double fSlope, double fOffset ) : |
144 | 0 | m_fSlope( fSlope ), |
145 | 0 | m_fOffset( fOffset ) |
146 | 0 | {} |
147 | | |
148 | | LinearScaling::~LinearScaling() |
149 | 0 | {} |
150 | | |
151 | | double SAL_CALL LinearScaling::doScaling( double value ) |
152 | 0 | { |
153 | 0 | if( std::isnan( value ) || std::isinf( value ) ) |
154 | 0 | return std::numeric_limits<double>::quiet_NaN(); |
155 | 0 | return m_fOffset + m_fSlope * value; |
156 | 0 | } |
157 | | |
158 | | uno::Reference< XScaling > SAL_CALL |
159 | | LinearScaling::getInverseScaling() |
160 | 0 | { |
161 | | // ToDo: ApproxEqual ? |
162 | 0 | if( m_fSlope == 0 ) |
163 | 0 | throw uno::RuntimeException(u"Divide by zero exception"_ustr); |
164 | | |
165 | 0 | return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope ); |
166 | 0 | } |
167 | | |
168 | | OUString SAL_CALL LinearScaling::getServiceName() |
169 | 0 | { |
170 | 0 | return lcl_aServiceName_Linear; |
171 | 0 | } |
172 | | |
173 | | OUString SAL_CALL LinearScaling::getImplementationName() |
174 | 0 | { |
175 | 0 | return lcl_aServiceName_Linear ; |
176 | 0 | } |
177 | | |
178 | | sal_Bool SAL_CALL LinearScaling::supportsService( const OUString& rServiceName ) |
179 | 0 | { |
180 | 0 | return cppu::supportsService(this, rServiceName); |
181 | 0 | } |
182 | | |
183 | | css::uno::Sequence< OUString > SAL_CALL LinearScaling::getSupportedServiceNames() |
184 | 0 | { |
185 | 0 | return { lcl_aServiceName_Linear }; |
186 | 0 | } |
187 | | |
188 | | PowerScaling::PowerScaling() : |
189 | 0 | m_fExponent( 10.0 ) |
190 | 0 | {} |
191 | | |
192 | | PowerScaling::PowerScaling( double fExponent ) : |
193 | 0 | m_fExponent( fExponent ) |
194 | 0 | {} |
195 | | |
196 | | PowerScaling::~PowerScaling() |
197 | 0 | {} |
198 | | |
199 | | double SAL_CALL PowerScaling::doScaling( double value ) |
200 | 0 | { |
201 | 0 | if( std::isnan( value ) || std::isinf( value ) ) |
202 | 0 | return std::numeric_limits<double>::quiet_NaN(); |
203 | 0 | return std::pow( value, m_fExponent ); |
204 | 0 | } |
205 | | |
206 | | uno::Reference< XScaling > SAL_CALL |
207 | | PowerScaling::getInverseScaling() |
208 | 0 | { |
209 | | // ToDo: ApproxEqual ? |
210 | 0 | if( m_fExponent == 0 ) |
211 | 0 | throw uno::RuntimeException(u"Divide by zero exception"_ustr); |
212 | | |
213 | 0 | return new PowerScaling( 1.0 / m_fExponent ); |
214 | 0 | } |
215 | | |
216 | | OUString SAL_CALL |
217 | | PowerScaling::getServiceName() |
218 | 0 | { |
219 | 0 | return lcl_aServiceName_Power; |
220 | 0 | } |
221 | | |
222 | | OUString SAL_CALL PowerScaling::getImplementationName() |
223 | 0 | { |
224 | 0 | return lcl_aServiceName_Power; |
225 | 0 | } |
226 | | |
227 | | sal_Bool SAL_CALL PowerScaling::supportsService( const OUString& rServiceName ) |
228 | 0 | { |
229 | 0 | return cppu::supportsService(this, rServiceName); |
230 | 0 | } |
231 | | |
232 | | css::uno::Sequence< OUString > SAL_CALL PowerScaling::getSupportedServiceNames() |
233 | 0 | { |
234 | 0 | return { lcl_aServiceName_Power }; |
235 | 0 | } |
236 | | |
237 | | } //namespace chart |
238 | | |
239 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
240 | | com_sun_star_chart2_LinearScaling_get_implementation(css::uno::XComponentContext *, |
241 | | css::uno::Sequence<css::uno::Any> const &) |
242 | 0 | { |
243 | 0 | return cppu::acquire(new chart::LinearScaling ); |
244 | 0 | } |
245 | | |
246 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
247 | | com_sun_star_chart2_ExponentialScaling_get_implementation(css::uno::XComponentContext *, |
248 | | css::uno::Sequence<css::uno::Any> const &) |
249 | 0 | { |
250 | 0 | return cppu::acquire(new chart::ExponentialScaling ); |
251 | 0 | } |
252 | | |
253 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
254 | | com_sun_star_chart2_LogarithmicScaling_get_implementation(css::uno::XComponentContext *, |
255 | | css::uno::Sequence<css::uno::Any> const &) |
256 | 0 | { |
257 | 0 | return cppu::acquire(new chart::LogarithmicScaling ); |
258 | 0 | } |
259 | | |
260 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
261 | | com_sun_star_chart2_PowerScaling_get_implementation(css::uno::XComponentContext *, |
262 | | css::uno::Sequence<css::uno::Any> const &) |
263 | 0 | { |
264 | 0 | return cppu::acquire(new chart::PowerScaling ); |
265 | 0 | } |
266 | | |
267 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |