Line data Source code
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 <rtl/math.hxx>
22 : #include "com/sun/star/uno/RuntimeException.hpp"
23 :
24 : namespace
25 : {
26 :
27 36 : static const OUString lcl_aServiceName_Logarithmic( "com.sun.star.chart2.LogarithmicScaling" );
28 36 : static const OUString lcl_aServiceName_Exponential( "com.sun.star.chart2.ExponentialScaling" );
29 36 : static const OUString lcl_aServiceName_Linear( "com.sun.star.chart2.LinearScaling" );
30 36 : static const OUString lcl_aServiceName_Power( "com.sun.star.chart2.PowerScaling" );
31 :
32 : }
33 :
34 : namespace chart
35 : {
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::chart2;
38 :
39 6 : LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
40 : m_fBase( 10.0 ),
41 : m_fLogOfBase( log( 10.0 ) ),
42 6 : m_xContext( xContext )
43 : {
44 6 : }
45 :
46 8 : LogarithmicScaling::LogarithmicScaling( double fBase ) :
47 : m_fBase( fBase ),
48 8 : m_fLogOfBase( log( fBase ) )
49 : {
50 8 : }
51 :
52 24 : LogarithmicScaling::~LogarithmicScaling()
53 : {
54 24 : }
55 :
56 : double SAL_CALL
57 27194 : LogarithmicScaling::doScaling( double value )
58 : throw (uno::RuntimeException, std::exception)
59 : {
60 : double fResult;
61 27194 : if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
62 0 : ::rtl::math::setNan( & fResult );
63 : else
64 27194 : fResult = log( value ) / m_fLogOfBase;
65 27194 : return fResult;
66 : }
67 :
68 : uno::Reference< XScaling > SAL_CALL
69 826 : LogarithmicScaling::getInverseScaling()
70 : throw (uno::RuntimeException, std::exception)
71 : {
72 826 : return new ExponentialScaling( m_fBase );
73 : }
74 :
75 : OUString SAL_CALL
76 372 : LogarithmicScaling::getServiceName()
77 : throw (uno::RuntimeException, std::exception)
78 : {
79 372 : return lcl_aServiceName_Logarithmic;
80 : }
81 :
82 4 : uno::Sequence< OUString > LogarithmicScaling::getSupportedServiceNames_Static()
83 : {
84 4 : return uno::Sequence< OUString >( & lcl_aServiceName_Logarithmic, 1 );
85 : }
86 :
87 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
88 94 : APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
89 :
90 2 : ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
91 : m_fBase( 10.0 ),
92 2 : m_xContext( xContext )
93 : {
94 2 : }
95 :
96 826 : ExponentialScaling::ExponentialScaling( double fBase ) :
97 826 : m_fBase( fBase )
98 : {
99 826 : }
100 :
101 1656 : ExponentialScaling::~ExponentialScaling()
102 : {
103 1656 : }
104 :
105 : double SAL_CALL
106 3985 : ExponentialScaling::doScaling( double value )
107 : throw (uno::RuntimeException, std::exception)
108 : {
109 : double fResult;
110 3985 : if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
111 0 : ::rtl::math::setNan( & fResult );
112 : else
113 3985 : fResult = pow( m_fBase, value );
114 3985 : return fResult;
115 : }
116 :
117 : uno::Reference< XScaling > SAL_CALL
118 0 : ExponentialScaling::getInverseScaling()
119 : throw (uno::RuntimeException, std::exception)
120 : {
121 0 : return new LogarithmicScaling( m_fBase );
122 : }
123 :
124 : OUString SAL_CALL
125 0 : ExponentialScaling::getServiceName()
126 : throw (uno::RuntimeException, std::exception)
127 : {
128 0 : return lcl_aServiceName_Exponential;
129 : }
130 :
131 2 : uno::Sequence< OUString > ExponentialScaling::getSupportedServiceNames_Static()
132 : {
133 2 : return uno::Sequence< OUString >( & lcl_aServiceName_Exponential, 1 );
134 : }
135 :
136 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
137 94 : APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
138 :
139 362 : LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
140 : m_fSlope( 1.0 ),
141 : m_fOffset( 0.0 ),
142 362 : m_xContext( xContext )
143 362 : {}
144 :
145 5694 : LinearScaling::LinearScaling( double fSlope, double fOffset ) :
146 : m_fSlope( fSlope ),
147 5694 : m_fOffset( fOffset )
148 5694 : {}
149 :
150 11972 : LinearScaling::~LinearScaling()
151 11972 : {}
152 :
153 222669 : double SAL_CALL LinearScaling::doScaling( double value )
154 : throw (uno::RuntimeException, std::exception)
155 : {
156 : double fResult;
157 222669 : if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
158 63 : ::rtl::math::setNan( & fResult );
159 : else
160 222606 : fResult = m_fOffset + m_fSlope * value;
161 222669 : return fResult;
162 : }
163 :
164 : uno::Reference< XScaling > SAL_CALL
165 4844 : LinearScaling::getInverseScaling()
166 : throw (uno::RuntimeException, std::exception)
167 : {
168 : // ToDo: ApproxEqual ?
169 4844 : if( m_fSlope == 0 )
170 0 : throw uno::RuntimeException();
171 :
172 4844 : return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
173 : }
174 :
175 : OUString SAL_CALL
176 5336 : LinearScaling::getServiceName()
177 : throw (uno::RuntimeException, std::exception)
178 : {
179 5336 : return lcl_aServiceName_Linear;
180 : }
181 :
182 18 : uno::Sequence< OUString > LinearScaling::getSupportedServiceNames_Static()
183 : {
184 18 : return uno::Sequence< OUString >( & lcl_aServiceName_Linear, 1 );
185 : }
186 :
187 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
188 94 : APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
189 :
190 2 : PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
191 : m_fExponent( 10.0 ),
192 2 : m_xContext( xContext )
193 2 : {}
194 :
195 0 : PowerScaling::PowerScaling( double fExponent ) :
196 0 : m_fExponent( fExponent )
197 0 : {}
198 :
199 4 : PowerScaling::~PowerScaling()
200 4 : {}
201 :
202 0 : double SAL_CALL PowerScaling::doScaling( double value )
203 : throw (uno::RuntimeException, std::exception)
204 : {
205 : double fResult;
206 0 : if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
207 0 : ::rtl::math::setNan( & fResult );
208 : else
209 0 : fResult = pow( value, m_fExponent );
210 0 : return fResult;
211 : }
212 :
213 : uno::Reference< XScaling > SAL_CALL
214 0 : PowerScaling::getInverseScaling()
215 : throw (uno::RuntimeException, std::exception)
216 : {
217 : // ToDo: ApproxEqual ?
218 0 : if( m_fExponent == 0 )
219 0 : throw uno::RuntimeException();
220 :
221 0 : return new PowerScaling( 1.0 / m_fExponent );
222 : }
223 :
224 : OUString SAL_CALL
225 0 : PowerScaling::getServiceName()
226 : throw (uno::RuntimeException, std::exception)
227 : {
228 0 : return lcl_aServiceName_Power;
229 : }
230 :
231 2 : uno::Sequence< OUString > PowerScaling::getSupportedServiceNames_Static()
232 : {
233 2 : return uno::Sequence< OUString >( & lcl_aServiceName_Power, 1 );
234 : }
235 :
236 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
237 94 : APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
238 :
239 108 : } //namespace chart
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|