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 INCLUDED_CHART2_SOURCE_INC_REGRESSIONCALCULATIONHELPER_HXX
20 #define INCLUDED_CHART2_SOURCE_INC_REGRESSIONCALCULATIONHELPER_HXX
22 #include <rtl/math.hxx>
29 namespace RegressionCalculationHelper
32 typedef std::pair
< std::vector
< double >, std::vector
< double > > tDoubleVectorPair
;
34 /** takes the given x- and y-values and copies them into the resulting pair,
35 which contains x-values in the first element and the y-values in the second
36 one. All tuples for which aPred is false are not copied.
38 <p>The function below provide a set of useful predicates that can be
39 used to pass as parameter aPred.</p>
41 template< class Pred
>
43 cleanup( const css::uno::Sequence
< double > & rXValues
,
44 const css::uno::Sequence
< double > & rYValues
,
47 tDoubleVectorPair aResult
;
48 sal_Int32 nSize
= std::min( rXValues
.getLength(), rYValues
.getLength());
49 for( sal_Int32 i
=0; i
<nSize
; ++i
)
51 if( aPred( rXValues
[i
], rYValues
[i
] ))
53 aResult
.first
.push_back( rXValues
[i
] );
54 aResult
.second
.push_back( rYValues
[i
] );
64 bool operator()( double x
, double y
)
65 { return ! ( ::rtl::math::isNan( x
) ||
66 ::rtl::math::isNan( y
) ||
67 ::rtl::math::isInf( x
) ||
68 ::rtl::math::isInf( y
) );
72 class isValidAndXPositive
75 bool operator()( double x
, double y
)
76 { return ! ( ::rtl::math::isNan( x
) ||
77 ::rtl::math::isNan( y
) ||
78 ::rtl::math::isInf( x
) ||
79 ::rtl::math::isInf( y
) ||
84 class isValidAndYPositive
87 bool operator()( double x
, double y
)
88 { return ! ( ::rtl::math::isNan( x
) ||
89 ::rtl::math::isNan( y
) ||
90 ::rtl::math::isInf( x
) ||
91 ::rtl::math::isInf( y
) ||
96 class isValidAndYNegative
99 bool operator()( double x
, double y
)
100 { return ! ( ::rtl::math::isNan( x
) ||
101 ::rtl::math::isNan( y
) ||
102 ::rtl::math::isInf( x
) ||
103 ::rtl::math::isInf( y
) ||
108 class isValidAndBothPositive
111 bool operator()( double x
, double y
)
112 { return ! ( ::rtl::math::isNan( x
) ||
113 ::rtl::math::isNan( y
) ||
114 ::rtl::math::isInf( x
) ||
115 ::rtl::math::isInf( y
) ||
121 class isValidAndXPositiveAndYNegative
124 bool operator()( double x
, double y
)
125 { return ! ( ::rtl::math::isNan( x
) ||
126 ::rtl::math::isNan( y
) ||
127 ::rtl::math::isInf( x
) ||
128 ::rtl::math::isInf( y
) ||
134 } // namespace RegressionCalculationHelper
137 // INCLUDED_CHART2_SOURCE_INC_REGRESSIONCALCULATIONHELPER_HXX
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */