LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/controller - SlsAnimationFunction.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 5 0.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             : 
      20             : #include "controller/SlsAnimationFunction.hxx"
      21             : #include "model/SlsPageDescriptor.hxx"
      22             : #include "view/SlideSorterView.hxx"
      23             : 
      24             : 
      25             : #include <osl/diagnose.hxx>
      26             : #include <rtl/math.hxx>
      27             : 
      28             : namespace sd { namespace slidesorter { namespace controller {
      29             : 
      30             : //===== AnimationBezierFunction ===============================================
      31             : 
      32           0 : AnimationBezierFunction::AnimationBezierFunction (
      33             :     const double nX1,
      34             :     const double nY1)
      35             :     : mnX1(nX1),
      36             :       mnY1(nY1),
      37           0 :       mnX2(1-nY1),
      38           0 :       mnY2(1-nX1)
      39             : {
      40           0 : }
      41             : 
      42             : 
      43             : 
      44             : 
      45           0 : ::basegfx::B2DPoint AnimationBezierFunction::operator() (const double nT)
      46             : {
      47             :     return ::basegfx::B2DPoint(
      48             :         EvaluateComponent(nT, mnX1, mnX2),
      49           0 :         EvaluateComponent(nT, mnY1, mnY2));
      50             : }
      51             : 
      52             : 
      53             : 
      54             : 
      55           0 : double AnimationBezierFunction::EvaluateComponent (
      56             :     const double nT,
      57             :     const double nV1,
      58             :     const double nV2)
      59             : {
      60           0 :     const double nS (1-nT);
      61             : 
      62             :     // While the control point values 1 and 2 are explicitly given the start
      63             :     // and end values are implicitly given.
      64           0 :     const double nV0 (0);
      65           0 :     const double nV3 (1);
      66             : 
      67           0 :     const double nV01 (nS*nV0 + nT*nV1);
      68           0 :     const double nV12 (nS*nV1 + nT*nV2);
      69           0 :     const double nV23 (nS*nV2 + nT*nV3);
      70             : 
      71           0 :     const double nV012 (nS*nV01 + nT*nV12);
      72           0 :     const double nV123 (nS*nV12 + nT*nV23);
      73             : 
      74           0 :     const double nV0123 (nS*nV012 + nT*nV123);
      75             : 
      76           0 :     return nV0123;
      77             : }
      78             : 
      79             : 
      80             : 
      81             : 
      82             : //===== AnimationParametricFunction ===========================================
      83             : 
      84           0 : AnimationParametricFunction::AnimationParametricFunction (const ParametricFunction& rFunction)
      85           0 :     : maY()
      86             : {
      87           0 :     const sal_Int32 nSampleCount (64);
      88             : 
      89             :     // Sample the given parametric function.
      90           0 :     ::std::vector<basegfx::B2DPoint> aPoints;
      91           0 :     aPoints.reserve(nSampleCount);
      92           0 :     for (sal_Int32 nIndex=0; nIndex<nSampleCount; ++nIndex)
      93             :     {
      94           0 :         const double nT (nIndex/double(nSampleCount-1));
      95           0 :         aPoints.push_back(basegfx::B2DPoint(rFunction(nT)));
      96             :     }
      97             : 
      98             :     // Interpolate at evenly spaced points.
      99           0 :     maY.clear();
     100           0 :     maY.reserve(nSampleCount);
     101           0 :     double nX0 (aPoints[0].getX());
     102           0 :     double nY0 (aPoints[0].getY());
     103           0 :     double nX1 (aPoints[1].getX());
     104           0 :     double nY1 (aPoints[1].getY());
     105           0 :     sal_Int32 nIndex (1);
     106           0 :     for (sal_Int32 nIndex2=0; nIndex2<nSampleCount; ++nIndex2)
     107             :     {
     108           0 :         const double nX (nIndex2 / double(nSampleCount-1));
     109           0 :         while (nX > nX1 && nIndex<nSampleCount)
     110             :         {
     111           0 :             nX0 = nX1;
     112           0 :             nY0 = nY1;
     113           0 :             nX1 = aPoints[nIndex].getX();
     114           0 :             nY1 = aPoints[nIndex].getY();
     115           0 :             ++nIndex;
     116             :         }
     117           0 :         const double nU ((nX-nX1) / (nX0 - nX1));
     118           0 :         const double nY (nY0*nU + nY1*(1-nU));
     119           0 :         maY.push_back(nY);
     120           0 :     }
     121           0 : }
     122             : 
     123             : 
     124             : 
     125             : 
     126           0 : double AnimationParametricFunction::operator() (const double nX)
     127             : {
     128           0 :     const sal_Int32 nIndex0 (static_cast<sal_Int32>(nX * maY.size()));
     129           0 :     const double nX0 (nIndex0 / double(maY.size()-1));
     130           0 :     const sal_uInt32 nIndex1 (nIndex0 + 1);
     131           0 :     const double nX1 (nIndex1 / double(maY.size()-1));
     132             : 
     133           0 :     if (nIndex0<=0)
     134           0 :         return maY[0];
     135           0 :     else if (sal_uInt32(nIndex0)>=maY.size() || nIndex1>=maY.size())
     136           0 :         return maY[maY.size()-1];
     137             : 
     138           0 :     const double nU ((nX-nX1) / (nX0 - nX1));
     139           0 :     return maY[nIndex0]*nU + maY[nIndex1]*(1-nU);
     140             : }
     141             : 
     142             : 
     143             : } } } // end of namespace ::sd::slidesorter::controller
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10