1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionCalculationHelper.hxx,v $
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>
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))
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
>
63 cleanup( const ::com::sun::star::uno::Sequence
< double > & rXValues
,
64 const ::com::sun::star::uno::Sequence
< double > & rYValues
,
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
] );
82 class isValid
: public ::std::binary_function
< double, double, bool >
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 >
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 isValidAndYPositive
: 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
) ||
117 class isValidAndBothPositive
: public ::std::binary_function
< double, double, bool >
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
) ||
130 } // namespace RegressionCalculationHelper
133 // CHART2_REGRESSIONCALCULATIONHELPER_HXX