1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 #pragma once 20 21 #include <com/sun/star/uno/Sequence.hxx> 22 23 #include <cmath> 24 #include <utility> 25 #include <vector> 26 27 namespace chart::RegressionCalculationHelper 28 { 29 30 typedef std::pair< std::vector< double >, std::vector< double > > tDoubleVectorPair; 31 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. 35 36 <p>The function below provide a set of useful predicates that can be 37 used to pass as parameter aPred.</p> 38 */ 39 template< class Pred > 40 tDoubleVectorPair cleanup(const css::uno::Sequence<double> & rXValues,const css::uno::Sequence<double> & rYValues,Pred aPred)41 cleanup( const css::uno::Sequence< double > & rXValues, 42 const css::uno::Sequence< double > & rYValues, 43 Pred aPred ) 44 { 45 tDoubleVectorPair aResult; 46 sal_Int32 nSize = std::min( rXValues.getLength(), rYValues.getLength()); 47 for( sal_Int32 i=0; i<nSize; ++i ) 48 { 49 if( aPred( rXValues[i], rYValues[i] )) 50 { 51 aResult.first.push_back( rXValues[i] ); 52 aResult.second.push_back( rYValues[i] ); 53 } 54 } 55 56 return aResult; 57 } 58 59 class isValid 60 { 61 public: operator ()(double x,double y)62 bool operator()( double x, double y ) 63 { return ! ( std::isnan( x ) || 64 std::isnan( y ) || 65 std::isinf( x ) || 66 std::isinf( y ) ); 67 } 68 }; 69 70 class isValidAndXPositive 71 { 72 public: operator ()(double x,double y)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 ); 79 } 80 }; 81 82 class isValidAndYPositive 83 { 84 public: operator ()(double x,double y)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 ); 91 } 92 }; 93 94 class isValidAndYNegative 95 { 96 public: operator ()(double x,double y)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 ); 103 } 104 }; 105 106 class isValidAndBothPositive 107 { 108 public: operator ()(double x,double y)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 ); 116 } 117 }; 118 119 class isValidAndXPositiveAndYNegative 120 { 121 public: operator ()(double x,double y)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 ); 129 } 130 }; 131 132 } // namespace chart::RegressionCalculationHelper 133 134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 135