LCOV - code coverage report
Current view: top level - libreoffice/slideshow/source/engine/transitions - snakewipe.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 124 0.0 %
Date: 2012-12-27 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             : 
      21             : #include <canvas/debug.hxx>
      22             : #include <basegfx/matrix/b2dhommatrix.hxx>
      23             : #include <basegfx/point/b2dpoint.hxx>
      24             : #include <basegfx/polygon/b2dpolygon.hxx>
      25             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      26             : #include "snakewipe.hxx"
      27             : #include "transitiontools.hxx"
      28             : 
      29             : 
      30             : namespace slideshow {
      31             : namespace internal {
      32             : 
      33           0 : SnakeWipe::SnakeWipe( sal_Int32 nElements, bool diagonal, bool flipOnYAxis )
      34             :     : m_sqrtElements( static_cast<sal_Int32>(
      35           0 :                           sqrt( static_cast<double>(nElements) ) ) ),
      36             :       m_elementEdge( 1.0 / m_sqrtElements ),
      37             :       m_diagonal(diagonal),
      38           0 :       m_flipOnYAxis(flipOnYAxis)
      39             : {
      40           0 : }
      41             : 
      42           0 : ::basegfx::B2DPolyPolygon SnakeWipe::calcSnake( double t ) const
      43             : {
      44           0 :     ::basegfx::B2DPolyPolygon res;
      45           0 :     const double area = (t * m_sqrtElements * m_sqrtElements);
      46           0 :     const sal_Int32 line_ = (static_cast<sal_Int32>(area) / m_sqrtElements);
      47             :     const double line = ::basegfx::pruneScaleValue(
      48           0 :         static_cast<double>(line_) / m_sqrtElements );
      49             :     const double col = ::basegfx::pruneScaleValue(
      50           0 :         (area - (line_ * m_sqrtElements)) / m_sqrtElements );
      51             : 
      52           0 :     if (! ::basegfx::fTools::equalZero( line )) {
      53           0 :         ::basegfx::B2DPolygon poly;
      54           0 :         poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
      55           0 :         poly.append( ::basegfx::B2DPoint( 0.0, line ) );
      56           0 :         poly.append( ::basegfx::B2DPoint( 1.0, line ) );
      57           0 :         poly.append( ::basegfx::B2DPoint( 1.0, 0.0 ) );
      58           0 :         poly.setClosed(true);
      59           0 :         res.append(poly);
      60             :     }
      61           0 :     if (! ::basegfx::fTools::equalZero( col ))
      62             :     {
      63           0 :         double offset = 0.0;
      64           0 :         if ((line_ & 1) == 1) {
      65             :             // odd line: => right to left
      66           0 :             offset = (1.0 - col);
      67             :         }
      68           0 :         ::basegfx::B2DPolygon poly;
      69           0 :         poly.append( ::basegfx::B2DPoint( offset, line ) );
      70             :         poly.append( ::basegfx::B2DPoint( offset,
      71           0 :                                           line + m_elementEdge ) );
      72             :         poly.append( ::basegfx::B2DPoint( offset + col,
      73           0 :                                           line + m_elementEdge ) );
      74           0 :         poly.append( ::basegfx::B2DPoint( offset + col, line ) );
      75           0 :         poly.setClosed(true);
      76           0 :         res.append(poly);
      77             :     }
      78             : 
      79           0 :     return res;
      80             : }
      81             : 
      82           0 : ::basegfx::B2DPolyPolygon SnakeWipe::calcHalfDiagonalSnake(
      83             :     double t, bool in ) const
      84             : {
      85           0 :     ::basegfx::B2DPolyPolygon res;
      86             : 
      87           0 :     if (in) {
      88           0 :         const double sqrtArea2 = sqrt( t * m_sqrtElements * m_sqrtElements );
      89             :         const double edge = ::basegfx::pruneScaleValue(
      90             :             static_cast<double>( static_cast<sal_Int32>(sqrtArea2) ) /
      91           0 :             m_sqrtElements );
      92             : 
      93           0 :         ::basegfx::B2DPolygon poly;
      94           0 :         if (! ::basegfx::fTools::equalZero( edge )) {
      95           0 :             poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
      96           0 :             poly.append( ::basegfx::B2DPoint( 0.0, edge ) );
      97           0 :             poly.append( ::basegfx::B2DPoint( edge, 0.0 ) );
      98           0 :             poly.setClosed(true);
      99           0 :             res.append(poly);
     100             :         }
     101           0 :         const double a = (M_SQRT1_2 / m_sqrtElements);
     102           0 :         const double d = (sqrtArea2 - static_cast<sal_Int32>(sqrtArea2));
     103           0 :         const double len = (t * M_SQRT2 * d);
     104           0 :         const double height = ::basegfx::pruneScaleValue( M_SQRT1_2 / m_sqrtElements );
     105           0 :         poly.clear();
     106           0 :         poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
     107           0 :         poly.append( ::basegfx::B2DPoint( 0.0, height ) );
     108           0 :         poly.append( ::basegfx::B2DPoint( len + a, height ) );
     109           0 :         poly.append( ::basegfx::B2DPoint( len + a, 0.0 ) );
     110           0 :         poly.setClosed(true);
     111           0 :         ::basegfx::B2DHomMatrix aTransform;
     112             : 
     113           0 :         if ((static_cast<sal_Int32>(sqrtArea2) & 1) == 1)
     114             :         {
     115             :             // odd line
     116           0 :             aTransform = basegfx::tools::createRotateB2DHomMatrix(M_PI_2 + M_PI_4);
     117           0 :             aTransform.translate(edge + m_elementEdge, 0.0);
     118             :         }
     119             :         else
     120             :         {
     121           0 :             aTransform = basegfx::tools::createTranslateB2DHomMatrix(-a, 0.0);
     122           0 :             aTransform.rotate( -M_PI_4 );
     123           0 :             aTransform.translate( 0.0, edge );
     124             :         }
     125             : 
     126           0 :         poly.transform( aTransform );
     127           0 :         res.append(poly);
     128             :     }
     129             :     else // out
     130             :     {
     131           0 :         const double sqrtArea2 = sqrt( t * m_sqrtElements * m_sqrtElements );
     132             :         const double edge = ::basegfx::pruneScaleValue(
     133             :             static_cast<double>( static_cast<sal_Int32>(sqrtArea2) ) /
     134           0 :             m_sqrtElements );
     135             : 
     136           0 :         ::basegfx::B2DPolygon poly;
     137           0 :         if (! ::basegfx::fTools::equalZero( edge )) {
     138           0 :             poly.append( ::basegfx::B2DPoint( 0.0, 1.0 ) );
     139           0 :             poly.append( ::basegfx::B2DPoint( edge, 1.0 ) );
     140           0 :             poly.append( ::basegfx::B2DPoint( 1.0, edge ) );
     141           0 :             poly.append( ::basegfx::B2DPoint( 1.0, 0.0 ) );
     142           0 :             poly.setClosed(true);
     143           0 :             res.append(poly);
     144             :         }
     145           0 :         const double a = (M_SQRT1_2 / m_sqrtElements);
     146           0 :         const double d = (sqrtArea2 - static_cast<sal_Int32>(sqrtArea2));
     147           0 :         const double len = ((1.0 - t) * M_SQRT2 * d);
     148           0 :         const double height = ::basegfx::pruneScaleValue( M_SQRT1_2 / m_sqrtElements );
     149           0 :         poly.clear();
     150           0 :         poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
     151           0 :         poly.append( ::basegfx::B2DPoint( 0.0, height ) );
     152           0 :         poly.append( ::basegfx::B2DPoint( len + a, height ) );
     153           0 :         poly.append( ::basegfx::B2DPoint( len + a, 0.0 ) );
     154           0 :         poly.setClosed(true);
     155           0 :         ::basegfx::B2DHomMatrix aTransform;
     156             : 
     157           0 :         if ((static_cast<sal_Int32>(sqrtArea2) & 1) == 1)
     158             :         {
     159             :             // odd line
     160           0 :             aTransform = basegfx::tools::createTranslateB2DHomMatrix(0.0, -height);
     161           0 :             aTransform.rotate( M_PI_2 + M_PI_4 );
     162           0 :             aTransform.translate( 1.0, edge );
     163             :         }
     164             :         else
     165             :         {
     166           0 :             aTransform = basegfx::tools::createRotateB2DHomMatrix(-M_PI_4);
     167           0 :             aTransform.translate( edge, 1.0 );
     168             :         }
     169           0 :         poly.transform( aTransform );
     170           0 :         res.append(poly);
     171             :     }
     172             : 
     173           0 :     return res;
     174             : }
     175             : 
     176           0 : ::basegfx::B2DPolyPolygon SnakeWipe::operator () ( double t )
     177             : {
     178           0 :     ::basegfx::B2DPolyPolygon res;
     179           0 :     if (m_diagonal)
     180             :     {
     181           0 :         if (t >= 0.5) {
     182           0 :             res.append( calcHalfDiagonalSnake( 1.0, true ) );
     183           0 :             res.append( calcHalfDiagonalSnake( 2.0 * (t - 0.5), false ) );
     184             :         }
     185             :         else
     186           0 :             res.append( calcHalfDiagonalSnake( 2.0 * t, true ) );
     187             :     }
     188             :     else
     189           0 :         res = calcSnake(t);
     190             : 
     191           0 :     return m_flipOnYAxis ? flipOnYAxis(res) : res;
     192             : }
     193             : 
     194           0 : ::basegfx::B2DPolyPolygon ParallelSnakesWipe::operator () ( double t )
     195             : {
     196           0 :     ::basegfx::B2DPolyPolygon res;
     197           0 :     if (m_diagonal)
     198             :     {
     199             :         OSL_ASSERT( m_opposite );
     200             :         ::basegfx::B2DPolyPolygon half(
     201           0 :             calcHalfDiagonalSnake( t, false /* out */ ) );
     202             :         // flip on x axis and rotate 90 degrees:
     203           0 :         basegfx::B2DHomMatrix aTransform(basegfx::tools::createScaleB2DHomMatrix(1.0, -1.0));
     204           0 :         aTransform.translate( -0.5, 0.5 );
     205           0 :         aTransform.rotate( M_PI_2 );
     206           0 :         aTransform.translate( 0.5, 0.5 );
     207           0 :         half.transform( aTransform );
     208           0 :         half.flip();
     209           0 :         res.append( half );
     210             : 
     211             :         // rotate 180 degrees:
     212           0 :         aTransform = basegfx::tools::createTranslateB2DHomMatrix(-0.5, -0.5);
     213           0 :         aTransform.rotate( M_PI );
     214           0 :         aTransform.translate( 0.5, 0.5 );
     215           0 :         half.transform( aTransform );
     216           0 :         res.append( half );
     217             :     }
     218             :     else
     219             :     {
     220           0 :         ::basegfx::B2DPolyPolygon half( calcSnake( t / 2.0 ) );
     221             :         // rotate 90 degrees:
     222           0 :         basegfx::B2DHomMatrix aTransform(basegfx::tools::createTranslateB2DHomMatrix(-0.5, -0.5));
     223           0 :         aTransform.rotate( M_PI_2 );
     224           0 :         aTransform.translate( 0.5, 0.5 );
     225           0 :         half.transform( aTransform );
     226           0 :         res.append( flipOnYAxis(half) );
     227           0 :         res.append( m_opposite ? flipOnXAxis(half) : half );
     228             :     }
     229             : 
     230           0 :     return m_flipOnYAxis ? flipOnYAxis(res) : res;
     231             : }
     232             : 
     233             : }
     234             : }
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10