1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef CHART2_REGRESSIONCALCULATIONHELPER_HXX 24 #define CHART2_REGRESSIONCALCULATIONHELPER_HXX 25 26 #include <rtl/math.hxx> 27 28 #include <utility> 29 #include <functional> 30 #include <vector> 31 #include <rtl/math.hxx> 32 33 #define NUMBER_TO_STR(number) (::rtl::OStringToOUString(::rtl::math::doubleToString( \ 34 number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US )) 35 36 #define UC_SPACE (sal_Unicode(' ')) 37 #define UC_MINUS_SIGN (sal_Unicode('-')) 38 // #define UC_MINUS_SIGN (sal_Unicode(0x2212)) 39 40 namespace chart 41 { 42 namespace RegressionCalculationHelper 43 { 44 45 typedef ::std::pair< ::std::vector< double >, ::std::vector< double > > tDoubleVectorPair; 46 47 /** takes the given x- and y-values and copyies them into the resulting pair, 48 which contains x-values in the first element and the y-values in the second 49 one. All tuples for which aPred is false are not copied. 50 51 <p>The functors below provide a set of useful predicates that can be 52 used to pass as parameter aPred.</p> 53 */ 54 template< class Pred > 55 tDoubleVectorPair cleanup(const::com::sun::star::uno::Sequence<double> & rXValues,const::com::sun::star::uno::Sequence<double> & rYValues,Pred aPred)56 cleanup( const ::com::sun::star::uno::Sequence< double > & rXValues, 57 const ::com::sun::star::uno::Sequence< double > & rYValues, 58 Pred aPred ) 59 { 60 tDoubleVectorPair aResult; 61 sal_Int32 nSize = ::std::min( rXValues.getLength(), rYValues.getLength()); 62 for( sal_Int32 i=0; i<nSize; ++i ) 63 { 64 if( aPred( rXValues[i], rYValues[i] )) 65 { 66 aResult.first.push_back( rXValues[i] ); 67 aResult.second.push_back( rYValues[i] ); 68 } 69 } 70 71 return aResult; 72 } 73 74 75 class isValid : public ::std::binary_function< double, double, bool > 76 { 77 public: operator ()(double x,double y)78 inline bool operator()( double x, double y ) 79 { return ! ( ::rtl::math::isNan( x ) || 80 ::rtl::math::isNan( y ) || 81 ::rtl::math::isInf( x ) || 82 ::rtl::math::isInf( y ) ); 83 } 84 }; 85 86 class isValidAndXPositive : public ::std::binary_function< double, double, bool > 87 { 88 public: operator ()(double x,double y)89 inline bool operator()( double x, double y ) 90 { return ! ( ::rtl::math::isNan( x ) || 91 ::rtl::math::isNan( y ) || 92 ::rtl::math::isInf( x ) || 93 ::rtl::math::isInf( y ) || 94 x <= 0.0 ); 95 } 96 }; 97 98 class isValidAndYPositive : public ::std::binary_function< double, double, bool > 99 { 100 public: operator ()(double x,double y)101 inline bool operator()( double x, double y ) 102 { return ! ( ::rtl::math::isNan( x ) || 103 ::rtl::math::isNan( y ) || 104 ::rtl::math::isInf( x ) || 105 ::rtl::math::isInf( y ) || 106 y <= 0.0 ); 107 } 108 }; 109 110 class isValidAndBothPositive : public ::std::binary_function< double, double, bool > 111 { 112 public: operator ()(double x,double y)113 inline bool operator()( double x, double y ) 114 { return ! ( ::rtl::math::isNan( x ) || 115 ::rtl::math::isNan( y ) || 116 ::rtl::math::isInf( x ) || 117 ::rtl::math::isInf( y ) || 118 x <= 0.0 || 119 y <= 0.0 ); 120 } 121 }; 122 123 } // namespace RegressionCalculationHelper 124 } // namespace chart 125 126 // CHART2_REGRESSIONCALCULATIONHELPER_HXX 127 #endif 128