merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / RegressionCalculationHelper.hxx
blobdf407482b34da43250c4fc4c24512110cf967720
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifndef CHART2_REGRESSIONCALCULATIONHELPER_HXX
28 #define CHART2_REGRESSIONCALCULATIONHELPER_HXX
30 #include <rtl/math.hxx>
32 #include <utility>
33 #include <functional>
34 #include <vector>
35 #include <rtl/math.hxx>
37 #define NUMBER_TO_STR(number) (::rtl::OStringToOUString(::rtl::math::doubleToString( \
38 number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US ))
40 #define UC_SPACE (sal_Unicode(' '))
41 #define UC_MINUS_SIGN (sal_Unicode('-'))
42 // #define UC_MINUS_SIGN (sal_Unicode(0x2212))
44 namespace chart
46 namespace RegressionCalculationHelper
49 typedef ::std::pair< ::std::vector< double >, ::std::vector< double > > tDoubleVectorPair;
51 /** takes the given x- and y-values and copyies them into the resulting pair,
52 which contains x-values in the first element and the y-values in the second
53 one. All tuples for which aPred is false are not copied.
55 <p>The functors below provide a set of useful predicates that can be
56 used to pass as parameter aPred.</p>
58 template< class Pred >
59 tDoubleVectorPair
60 cleanup( const ::com::sun::star::uno::Sequence< double > & rXValues,
61 const ::com::sun::star::uno::Sequence< double > & rYValues,
62 Pred aPred )
64 tDoubleVectorPair aResult;
65 sal_Int32 nSize = ::std::min( rXValues.getLength(), rYValues.getLength());
66 for( sal_Int32 i=0; i<nSize; ++i )
68 if( aPred( rXValues[i], rYValues[i] ))
70 aResult.first.push_back( rXValues[i] );
71 aResult.second.push_back( rYValues[i] );
75 return aResult;
79 class isValid : public ::std::binary_function< double, double, bool >
81 public:
82 inline bool operator()( double x, double y )
83 { return ! ( ::rtl::math::isNan( x ) ||
84 ::rtl::math::isNan( y ) ||
85 ::rtl::math::isInf( x ) ||
86 ::rtl::math::isInf( y ) );
90 class isValidAndXPositive : public ::std::binary_function< double, double, bool >
92 public:
93 inline bool operator()( double x, double y )
94 { return ! ( ::rtl::math::isNan( x ) ||
95 ::rtl::math::isNan( y ) ||
96 ::rtl::math::isInf( x ) ||
97 ::rtl::math::isInf( y ) ||
98 x <= 0.0 );
102 class isValidAndYPositive : public ::std::binary_function< double, double, bool >
104 public:
105 inline bool operator()( double x, double y )
106 { return ! ( ::rtl::math::isNan( x ) ||
107 ::rtl::math::isNan( y ) ||
108 ::rtl::math::isInf( x ) ||
109 ::rtl::math::isInf( y ) ||
110 y <= 0.0 );
114 class isValidAndBothPositive : public ::std::binary_function< double, double, bool >
116 public:
117 inline bool operator()( double x, double y )
118 { return ! ( ::rtl::math::isNan( x ) ||
119 ::rtl::math::isNan( y ) ||
120 ::rtl::math::isInf( x ) ||
121 ::rtl::math::isInf( y ) ||
122 x <= 0.0 ||
123 y <= 0.0 );
127 } // namespace RegressionCalculationHelper
128 } // namespace chart
130 // CHART2_REGRESSIONCALCULATIONHELPER_HXX
131 #endif