update dev300-m58
[ooovba.git] / chart2 / source / tools / RegressionCalculationHelper.hxx
blob049baa5321b5b76ca15ffe3ceb50dfd0992036b2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionCalculationHelper.hxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CHART2_REGRESSIONCALCULATIONHELPER_HXX
31 #define CHART2_REGRESSIONCALCULATIONHELPER_HXX
33 #include <rtl/math.hxx>
35 #include <utility>
36 #include <functional>
37 #include <vector>
38 #include <rtl/math.hxx>
40 #define NUMBER_TO_STR(number) (::rtl::OStringToOUString(::rtl::math::doubleToString( \
41 number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US ))
43 #define UC_SPACE (sal_Unicode(' '))
44 #define UC_MINUS_SIGN (sal_Unicode('-'))
45 // #define UC_MINUS_SIGN (sal_Unicode(0x2212))
47 namespace chart
49 namespace RegressionCalculationHelper
52 typedef ::std::pair< ::std::vector< double >, ::std::vector< double > > tDoubleVectorPair;
54 /** takes the given x- and y-values and copyies them into the resulting pair,
55 which contains x-values in the first element and the y-values in the second
56 one. All tuples for which aPred is false are not copied.
58 <p>The functors below provide a set of useful predicates that can be
59 used to pass as parameter aPred.</p>
61 template< class Pred >
62 tDoubleVectorPair
63 cleanup( const ::com::sun::star::uno::Sequence< double > & rXValues,
64 const ::com::sun::star::uno::Sequence< double > & rYValues,
65 Pred aPred )
67 tDoubleVectorPair aResult;
68 sal_Int32 nSize = ::std::min( rXValues.getLength(), rYValues.getLength());
69 for( sal_Int32 i=0; i<nSize; ++i )
71 if( aPred( rXValues[i], rYValues[i] ))
73 aResult.first.push_back( rXValues[i] );
74 aResult.second.push_back( rYValues[i] );
78 return aResult;
82 class isValid : public ::std::binary_function< double, double, bool >
84 public:
85 inline bool operator()( double x, double y )
86 { return ! ( ::rtl::math::isNan( x ) ||
87 ::rtl::math::isNan( y ) ||
88 ::rtl::math::isInf( x ) ||
89 ::rtl::math::isInf( y ) );
93 class isValidAndXPositive : public ::std::binary_function< double, double, bool >
95 public:
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 ) ||
101 x <= 0.0 );
105 class isValidAndYPositive : public ::std::binary_function< double, double, bool >
107 public:
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 ) ||
113 y <= 0.0 );
117 class isValidAndBothPositive : public ::std::binary_function< double, double, bool >
119 public:
120 inline bool operator()( double x, double y )
121 { return ! ( ::rtl::math::isNan( x ) ||
122 ::rtl::math::isNan( y ) ||
123 ::rtl::math::isInf( x ) ||
124 ::rtl::math::isInf( y ) ||
125 x <= 0.0 ||
126 y <= 0.0 );
130 } // namespace RegressionCalculationHelper
131 } // namespace chart
133 // CHART2_REGRESSIONCALCULATIONHELPER_HXX
134 #endif