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