Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / inc / RegressionCalculationHelper.hxx
blobeb1e46703e39d080bb3c0f6034a7b550b3b4f474
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 #include <utility>
25 #include <vector>
27 namespace chart
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 >
42 tDoubleVectorPair
43 cleanup( const css::uno::Sequence< double > & rXValues,
44 const css::uno::Sequence< double > & rYValues,
45 Pred aPred )
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] );
58 return aResult;
61 class isValid
63 public:
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
74 public:
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 ) ||
80 x <= 0.0 );
84 class isValidAndYPositive
86 public:
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 ) ||
92 y <= 0.0 );
96 class isValidAndYNegative
98 public:
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 ) ||
104 y >= 0.0 );
108 class isValidAndBothPositive
110 public:
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 ) ||
116 x <= 0.0 ||
117 y <= 0.0 );
121 class isValidAndXPositiveAndYNegative
123 public:
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 ) ||
129 x <= 0.0 ||
130 y >= 0.0 );
134 } // namespace RegressionCalculationHelper
135 } // namespace chart
137 // INCLUDED_CHART2_SOURCE_INC_REGRESSIONCALCULATIONHELPER_HXX
138 #endif
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */