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

Generated by: LCOV version 1.11