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 76 { 77 public: 78 typedef double first_argument_type; 79 typedef double second_argument_type; 80 typedef bool result_type; operator ()(double x,double y)81 inline bool operator()( double x, double y ) 82 { return ! ( ::rtl::math::isNan( x ) || 83 ::rtl::math::isNan( y ) || 84 ::rtl::math::isInf( x ) || 85 ::rtl::math::isInf( y ) ); 86 } 87 }; 88 89 class isValidAndXPositive 90 { 91 public: 92 typedef double first_argument_type; 93 typedef double second_argument_type; 94 typedef bool result_type; operator ()(double x,double y)95 inline bool operator()( double x, double y ) 96 { return ! ( ::rtl::math::isNan( x ) || 97 ::rtl::math::isNan( y ) || 98 ::rtl::math::isInf( x ) || 99 ::rtl::math::isInf( y ) || 100 x <= 0.0 ); 101 } 102 }; 103 104 class isValidAndYPositive 105 { 106 public: 107 typedef double first_argument_type; 108 typedef double second_argument_type; 109 typedef bool result_type; operator ()(double x,double y)110 inline bool operator()( double x, double y ) 111 { return ! ( ::rtl::math::isNan( x ) || 112 ::rtl::math::isNan( y ) || 113 ::rtl::math::isInf( x ) || 114 ::rtl::math::isInf( y ) || 115 y <= 0.0 ); 116 } 117 }; 118 119 class isValidAndBothPositive 120 { 121 public: 122 typedef double first_argument_type; 123 typedef double second_argument_type; 124 typedef bool result_type; operator ()(double x,double y)125 inline bool operator()( double x, double y ) 126 { return ! ( ::rtl::math::isNan( x ) || 127 ::rtl::math::isNan( y ) || 128 ::rtl::math::isInf( x ) || 129 ::rtl::math::isInf( y ) || 130 x <= 0.0 || 131 y <= 0.0 ); 132 } 133 }; 134 135 } // namespace RegressionCalculationHelper 136 } // namespace chart 137 138 // CHART2_REGRESSIONCALCULATIONHELPER_HXX 139 #endif 140