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 .
19 #ifndef CHART2_REGRESSIONCALCULATIONHELPER_HXX
20 #define CHART2_REGRESSIONCALCULATIONHELPER_HXX
22 #include <rtl/math.hxx>
28 #define NUMBER_TO_STR(number) (OStringToOUString(::rtl::math::doubleToString( \
29 number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US ))
31 #define UC_SPACE (sal_Unicode(' '))
32 #define UC_MINUS_SIGN (sal_Unicode('-'))
33 // #define UC_MINUS_SIGN (sal_Unicode(0x2212))
37 namespace RegressionCalculationHelper
40 typedef ::std::pair
< ::std::vector
< double >, ::std::vector
< double > > tDoubleVectorPair
;
42 /** takes the given x- and y-values and copyies them into the resulting pair,
43 which contains x-values in the first element and the y-values in the second
44 one. All tuples for which aPred is false are not copied.
46 <p>The functors below provide a set of useful predicates that can be
47 used to pass as parameter aPred.</p>
49 template< class Pred
>
51 cleanup( const ::com::sun::star::uno::Sequence
< double > & rXValues
,
52 const ::com::sun::star::uno::Sequence
< double > & rYValues
,
55 tDoubleVectorPair aResult
;
56 sal_Int32 nSize
= ::std::min( rXValues
.getLength(), rYValues
.getLength());
57 for( sal_Int32 i
=0; i
<nSize
; ++i
)
59 if( aPred( rXValues
[i
], rYValues
[i
] ))
61 aResult
.first
.push_back( rXValues
[i
] );
62 aResult
.second
.push_back( rYValues
[i
] );
70 class isValid
: public ::std::binary_function
< double, double, bool >
73 inline bool operator()( double x
, double y
)
74 { return ! ( ::rtl::math::isNan( x
) ||
75 ::rtl::math::isNan( y
) ||
76 ::rtl::math::isInf( x
) ||
77 ::rtl::math::isInf( y
) );
81 class isValidAndXPositive
: public ::std::binary_function
< double, double, bool >
84 inline bool operator()( double x
, double y
)
85 { return ! ( ::rtl::math::isNan( x
) ||
86 ::rtl::math::isNan( y
) ||
87 ::rtl::math::isInf( x
) ||
88 ::rtl::math::isInf( y
) ||
93 class isValidAndYPositive
: public ::std::binary_function
< double, double, bool >
96 inline bool operator()( double x
, double y
)
97 { return ! ( ::rtl::math::isNan( x
) ||
98 ::rtl::math::isNan( y
) ||
99 ::rtl::math::isInf( x
) ||
100 ::rtl::math::isInf( y
) ||
105 class isValidAndBothPositive
: public ::std::binary_function
< double, double, bool >
108 inline bool operator()( double x
, double y
)
109 { return ! ( ::rtl::math::isNan( x
) ||
110 ::rtl::math::isNan( y
) ||
111 ::rtl::math::isInf( x
) ||
112 ::rtl::math::isInf( y
) ||
118 } // namespace RegressionCalculationHelper
121 // CHART2_REGRESSIONCALCULATIONHELPER_HXX
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */