LCOV - code coverage report
Current view: top level - chart2/source/tools - RegressionCalculationHelper.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 13 32 40.6 %
Date: 2014-04-11 Functions: 2 8 25.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef INCLUDED_CHART2_SOURCE_TOOLS_REGRESSIONCALCULATIONHELPER_HXX
      20             : #define INCLUDED_CHART2_SOURCE_TOOLS_REGRESSIONCALCULATIONHELPER_HXX
      21             : 
      22             : #include <rtl/math.hxx>
      23             : 
      24             : #include <utility>
      25             : #include <functional>
      26             : #include <vector>
      27             : 
      28             : #define NUMBER_TO_STR(number) (OStringToOUString(::rtl::math::doubleToString( \
      29             :           number, rtl_math_StringFormat_G, 4, '.', true ),RTL_TEXTENCODING_ASCII_US ))
      30             : 
      31             : #define UC_SPACE (sal_Unicode(' '))
      32             : #define UC_MINUS_SIGN (sal_Unicode('-'))
      33             : // #define UC_MINUS_SIGN (sal_Unicode(0x2212))
      34             : 
      35             : namespace chart
      36             : {
      37             : namespace RegressionCalculationHelper
      38             : {
      39             : 
      40             : typedef ::std::pair< ::std::vector< double >, ::std::vector< double > > tDoubleVectorPair;
      41             : 
      42             : /** takes the given x- and y-values and copyies them into the resulting pair,
      43             :     which contains x-values in the first element and the y-values in the second
      44             :     one.  All tuples for which aPred is false are not copied.
      45             : 
      46             :     <p>The functors below provide a set of useful predicates that can be
      47             :     used to pass as parameter aPred.</p>
      48             :  */
      49             : template< class Pred >
      50             : tDoubleVectorPair
      51          21 :     cleanup( const ::com::sun::star::uno::Sequence< double > & rXValues,
      52             :              const ::com::sun::star::uno::Sequence< double > & rYValues,
      53             :              Pred aPred )
      54             : {
      55          21 :     tDoubleVectorPair aResult;
      56          21 :     sal_Int32 nSize = ::std::min( rXValues.getLength(), rYValues.getLength());
      57         168 :     for( sal_Int32 i=0; i<nSize; ++i )
      58             :     {
      59         147 :         if( aPred( rXValues[i], rYValues[i] ))
      60             :         {
      61         147 :             aResult.first.push_back( rXValues[i] );
      62         147 :             aResult.second.push_back( rYValues[i] );
      63             :         }
      64             :     }
      65             : 
      66          21 :     return aResult;
      67             : }
      68             : 
      69             : class isValid : public ::std::binary_function< double, double, bool >
      70             : {
      71             : public:
      72         147 :     inline bool operator()( double x, double y )
      73         294 :     { return ! ( ::rtl::math::isNan( x ) ||
      74         294 :                  ::rtl::math::isNan( y ) ||
      75         147 :                  ::rtl::math::isInf( x ) ||
      76         294 :                  ::rtl::math::isInf( y ) );
      77             :     }
      78             : };
      79             : 
      80             : class isValidAndXPositive : public ::std::binary_function< double, double, bool >
      81             : {
      82             : public:
      83           0 :     inline bool operator()( double x, double y )
      84           0 :     { return ! ( ::rtl::math::isNan( x ) ||
      85           0 :                  ::rtl::math::isNan( y ) ||
      86           0 :                  ::rtl::math::isInf( x ) ||
      87           0 :                  ::rtl::math::isInf( y ) ||
      88           0 :                  x <= 0.0 );
      89             :     }
      90             : };
      91             : 
      92             : class isValidAndYPositive : public ::std::binary_function< double, double, bool >
      93             : {
      94             : public:
      95           0 :     inline bool operator()( double x, double y )
      96           0 :     { return ! ( ::rtl::math::isNan( x ) ||
      97           0 :                  ::rtl::math::isNan( y ) ||
      98           0 :                  ::rtl::math::isInf( x ) ||
      99           0 :                  ::rtl::math::isInf( y ) ||
     100           0 :                  y <= 0.0 );
     101             :     }
     102             : };
     103             : 
     104             : class isValidAndBothPositive : public ::std::binary_function< double, double, bool >
     105             : {
     106             : public:
     107           0 :     inline bool operator()( double x, double y )
     108           0 :     { return ! ( ::rtl::math::isNan( x ) ||
     109           0 :                  ::rtl::math::isNan( y ) ||
     110           0 :                  ::rtl::math::isInf( x ) ||
     111           0 :                  ::rtl::math::isInf( y ) ||
     112           0 :                  x <= 0.0 ||
     113           0 :                  y <= 0.0 );
     114             :     }
     115             : };
     116             : 
     117             : } //  namespace RegressionCalculationHelper
     118             : } //  namespace chart
     119             : 
     120             : // INCLUDED_CHART2_SOURCE_TOOLS_REGRESSIONCALCULATIONHELPER_HXX
     121             : #endif
     122             : 
     123             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10