Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / inc / RegressionCalculationHelper.hxx
blob0b9600e99dc5045d8a4c8b6339033ecfd7b2fb48
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 #pragma once
21 #include <com/sun/star/uno/Sequence.hxx>
23 #include <cmath>
24 #include <utility>
25 #include <vector>
27 namespace chart::RegressionCalculationHelper
30 typedef std::pair< std::vector< double >, std::vector< double > > tDoubleVectorPair;
32 /** takes the given x- and y-values and copies them into the resulting pair,
33 which contains x-values in the first element and the y-values in the second
34 one. All tuples for which aPred is false are not copied.
36 <p>The function below provide a set of useful predicates that can be
37 used to pass as parameter aPred.</p>
39 template< class Pred >
40 tDoubleVectorPair
41 cleanup( const css::uno::Sequence< double > & rXValues,
42 const css::uno::Sequence< double > & rYValues,
43 Pred aPred )
45 tDoubleVectorPair aResult;
46 sal_Int32 nSize = std::min( rXValues.getLength(), rYValues.getLength());
47 for( sal_Int32 i=0; i<nSize; ++i )
49 if( aPred( rXValues[i], rYValues[i] ))
51 aResult.first.push_back( rXValues[i] );
52 aResult.second.push_back( rYValues[i] );
56 return aResult;
59 class isValid
61 public:
62 bool operator()( double x, double y )
63 { return ! ( std::isnan( x ) ||
64 std::isnan( y ) ||
65 std::isinf( x ) ||
66 std::isinf( y ) );
70 class isValidAndXPositive
72 public:
73 bool operator()( double x, double y )
74 { return ! ( std::isnan( x ) ||
75 std::isnan( y ) ||
76 std::isinf( x ) ||
77 std::isinf( y ) ||
78 x <= 0.0 );
82 class isValidAndYPositive
84 public:
85 bool operator()( double x, double y )
86 { return ! ( std::isnan( x ) ||
87 std::isnan( y ) ||
88 std::isinf( x ) ||
89 std::isinf( y ) ||
90 y <= 0.0 );
94 class isValidAndYNegative
96 public:
97 bool operator()( double x, double y )
98 { return ! ( std::isnan( x ) ||
99 std::isnan( y ) ||
100 std::isinf( x ) ||
101 std::isinf( y ) ||
102 y >= 0.0 );
106 class isValidAndBothPositive
108 public:
109 bool operator()( double x, double y )
110 { return ! ( std::isnan( x ) ||
111 std::isnan( y ) ||
112 std::isinf( x ) ||
113 std::isinf( y ) ||
114 x <= 0.0 ||
115 y <= 0.0 );
119 class isValidAndXPositiveAndYNegative
121 public:
122 bool operator()( double x, double y )
123 { return ! ( std::isnan( x ) ||
124 std::isnan( y ) ||
125 std::isinf( x ) ||
126 std::isinf( y ) ||
127 x <= 0.0 ||
128 y >= 0.0 );
132 } // namespace chart::RegressionCalculationHelper
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */