1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 #ifndef CHART2_REGRESSIONCALCULATIONHELPER_HXX
28 #define CHART2_REGRESSIONCALCULATIONHELPER_HXX
29 
30 #include <rtl/math.hxx>
31 
32 #include <utility>
33 #include <functional>
34 #include <vector>
35 #include <rtl/math.hxx>
36 
37 #define NUMBER_TO_STR(number) (::rtl::OStringToOUString(::rtl::math::doubleToString( \
38           number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US ))
39 
40 #define UC_SPACE (sal_Unicode(' '))
41 #define UC_MINUS_SIGN (sal_Unicode('-'))
42 // #define UC_MINUS_SIGN (sal_Unicode(0x2212))
43 
44 namespace chart
45 {
46 namespace RegressionCalculationHelper
47 {
48 
49 typedef ::std::pair< ::std::vector< double >, ::std::vector< double > > tDoubleVectorPair;
50 
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.
54 
55     <p>The functors below provide a set of useful predicates that can be
56     used to pass as parameter aPred.</p>
57  */
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 )
63 {
64     tDoubleVectorPair aResult;
65     sal_Int32 nSize = ::std::min( rXValues.getLength(), rYValues.getLength());
66     for( sal_Int32 i=0; i<nSize; ++i )
67     {
68         if( aPred( rXValues[i], rYValues[i] ))
69         {
70             aResult.first.push_back( rXValues[i] );
71             aResult.second.push_back( rYValues[i] );
72         }
73     }
74 
75     return aResult;
76 }
77 
78 
79 class isValid : public ::std::binary_function< double, double, bool >
80 {
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 ) );
87     }
88 };
89 
90 class isValidAndXPositive : public ::std::binary_function< double, double, bool >
91 {
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 );
99     }
100 };
101 
102 class isValidAndYPositive : public ::std::binary_function< double, double, bool >
103 {
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 );
111     }
112 };
113 
114 class isValidAndBothPositive : public ::std::binary_function< double, double, bool >
115 {
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 );
124     }
125 };
126 
127 } //  namespace RegressionCalculationHelper
128 } //  namespace chart
129 
130 // CHART2_REGRESSIONCALCULATIONHELPER_HXX
131 #endif
132