LibreOffice Module slideshow (master) 1
snakewipe.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <cmath>
23
24#include <o3tl/temporary.hxx>
25#include <osl/diagnose.h>
30#include "snakewipe.hxx"
31#include "transitiontools.hxx"
32
33
34namespace slideshow::internal {
35
36SnakeWipe::SnakeWipe( sal_Int32 nElements, bool diagonal, bool flipOnYAxis )
37 : m_sqrtElements( static_cast<sal_Int32>(
38 sqrt( static_cast<double>(nElements) ) ) ),
39 m_elementEdge( 1.0 / m_sqrtElements ),
40 m_diagonal(diagonal),
41 m_flipOnYAxis(flipOnYAxis)
42{
43}
44
46{
48 const double area = t * m_sqrtElements * m_sqrtElements;
49 const sal_Int32 line_ = static_cast<sal_Int32>(area) / m_sqrtElements;
50 const double line = ::basegfx::pruneScaleValue(
51 static_cast<double>(line_) / m_sqrtElements );
52 const double col = ::basegfx::pruneScaleValue(
53 (area - (line_ * m_sqrtElements)) / m_sqrtElements );
54
55 if (! ::basegfx::fTools::equalZero( line )) {
57 poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
58 poly.append( ::basegfx::B2DPoint( 0.0, line ) );
59 poly.append( ::basegfx::B2DPoint( 1.0, line ) );
60 poly.append( ::basegfx::B2DPoint( 1.0, 0.0 ) );
61 poly.setClosed(true);
62 res.append(poly);
63 }
64 if (! ::basegfx::fTools::equalZero( col ))
65 {
66 double offset = 0.0;
67 if ((line_ & 1) == 1) {
68 // odd line: => right to left
69 offset = (1.0 - col);
70 }
72 poly.append( ::basegfx::B2DPoint( offset, line ) );
73 poly.append( ::basegfx::B2DPoint( offset,
74 line + m_elementEdge ) );
75 poly.append( ::basegfx::B2DPoint( offset + col,
76 line + m_elementEdge ) );
77 poly.append( ::basegfx::B2DPoint( offset + col, line ) );
78 poly.setClosed(true);
79 res.append(poly);
80 }
81
82 return res;
83}
84
86 double t, bool in ) const
87{
89
90 if (in) {
91 const double sqrtArea2 = sqrt( t * m_sqrtElements * m_sqrtElements );
92 const double edge = ::basegfx::pruneScaleValue(
93 std::trunc(sqrtArea2) /
95
97 if (! ::basegfx::fTools::equalZero( edge )) {
98 poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
99 poly.append( ::basegfx::B2DPoint( 0.0, edge ) );
100 poly.append( ::basegfx::B2DPoint( edge, 0.0 ) );
101 poly.setClosed(true);
102 res.append(poly);
103 }
104 const double a = M_SQRT1_2 / m_sqrtElements;
105 const double d = std::modf(sqrtArea2, &o3tl::temporary(double()));
106 const double len = t * M_SQRT2 * d;
107 const double height = ::basegfx::pruneScaleValue( M_SQRT1_2 / m_sqrtElements );
108 poly.clear();
109 poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
110 poly.append( ::basegfx::B2DPoint( 0.0, height ) );
111 poly.append( ::basegfx::B2DPoint( len + a, height ) );
112 poly.append( ::basegfx::B2DPoint( len + a, 0.0 ) );
113 poly.setClosed(true);
114 ::basegfx::B2DHomMatrix aTransform;
115
116 if ((static_cast<sal_Int32>(sqrtArea2) & 1) == 1)
117 {
118 // odd line
119 aTransform = basegfx::utils::createRotateB2DHomMatrix(M_PI_2 + M_PI_4);
120 aTransform.translate(edge + m_elementEdge, 0.0);
121 }
122 else
123 {
125 aTransform.rotate( -M_PI_4 );
126 aTransform.translate( 0.0, edge );
127 }
128
129 poly.transform( aTransform );
130 res.append(poly);
131 }
132 else // out
133 {
134 const double sqrtArea2 = sqrt( t * m_sqrtElements * m_sqrtElements );
135 const double edge = ::basegfx::pruneScaleValue(
136 std::trunc(sqrtArea2) /
138
140 if (! ::basegfx::fTools::equalZero( edge )) {
141 poly.append( ::basegfx::B2DPoint( 0.0, 1.0 ) );
142 poly.append( ::basegfx::B2DPoint( edge, 1.0 ) );
143 poly.append( ::basegfx::B2DPoint( 1.0, edge ) );
144 poly.append( ::basegfx::B2DPoint( 1.0, 0.0 ) );
145 poly.setClosed(true);
146 res.append(poly);
147 }
148 const double a = M_SQRT1_2 / m_sqrtElements;
149 const double d = std::modf(sqrtArea2, &o3tl::temporary(double()));
150 const double len = (1.0 - t) * M_SQRT2 * d;
151 const double height = ::basegfx::pruneScaleValue( M_SQRT1_2 / m_sqrtElements );
152 poly.clear();
153 poly.append( ::basegfx::B2DPoint( 0.0, 0.0 ) );
154 poly.append( ::basegfx::B2DPoint( 0.0, height ) );
155 poly.append( ::basegfx::B2DPoint( len + a, height ) );
156 poly.append( ::basegfx::B2DPoint( len + a, 0.0 ) );
157 poly.setClosed(true);
158 ::basegfx::B2DHomMatrix aTransform;
159
160 if ((static_cast<sal_Int32>(sqrtArea2) & 1) == 1)
161 {
162 // odd line
163 aTransform = basegfx::utils::createTranslateB2DHomMatrix(0.0, -height);
164 aTransform.rotate( M_PI_2 + M_PI_4 );
165 aTransform.translate( 1.0, edge );
166 }
167 else
168 {
169 aTransform = basegfx::utils::createRotateB2DHomMatrix(-M_PI_4);
170 aTransform.translate( edge, 1.0 );
171 }
172 poly.transform( aTransform );
173 res.append(poly);
174 }
175
176 return res;
177}
178
180{
182 if (m_diagonal)
183 {
184 if (t >= 0.5) {
185 res.append( calcHalfDiagonalSnake( 1.0, true ) );
186 res.append( calcHalfDiagonalSnake( 2.0 * (t - 0.5), false ) );
187 }
188 else
189 res.append( calcHalfDiagonalSnake( 2.0 * t, true ) );
190 }
191 else
192 res = calcSnake(t);
193
194 return m_flipOnYAxis ? flipOnYAxis(res) : res;
195}
196
198{
200 if (m_diagonal)
201 {
202 OSL_ASSERT( m_opposite );
204 calcHalfDiagonalSnake( t, false /* out */ ) );
205 // flip on x axis and rotate 90 degrees:
207 aTransform.translate( -0.5, 0.5 );
208 aTransform.rotate( M_PI_2 );
209 aTransform.translate( 0.5, 0.5 );
210 half.transform( aTransform );
211 half.flip();
212 res.append( half );
213
214 // rotate 180 degrees:
215 aTransform = basegfx::utils::createTranslateB2DHomMatrix(-0.5, -0.5);
216 aTransform.rotate( M_PI );
217 aTransform.translate( 0.5, 0.5 );
218 half.transform( aTransform );
219 res.append( half );
220 }
221 else
222 {
223 ::basegfx::B2DPolyPolygon half( calcSnake( t / 2.0 ) );
224 // rotate 90 degrees:
226 aTransform.rotate( M_PI_2 );
227 aTransform.translate( 0.5, 0.5 );
228 half.transform( aTransform );
229 res.append( flipOnYAxis(half) );
230 res.append( m_opposite ? flipOnXAxis(half) : half );
231 }
232
233 return m_flipOnYAxis ? flipOnYAxis(res) : res;
234}
235
236}
237
238/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
double d
void rotate(double fRadiant)
void translate(double fX, double fY)
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void transform(const basegfx::B2DHomMatrix &rMatrix)
void transform(const basegfx::B2DHomMatrix &rMatrix)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void setClosed(bool bNew)
virtual ::basegfx::B2DPolyPolygon operator()(double t) override
Retrieve the poly-polygon for value t.
Definition: snakewipe.cxx:197
virtual ::basegfx::B2DPolyPolygon operator()(double t) override
Retrieve the poly-polygon for value t.
Definition: snakewipe.cxx:179
::basegfx::B2DPolyPolygon calcSnake(double t) const
Definition: snakewipe.cxx:45
::basegfx::B2DPolyPolygon calcHalfDiagonalSnake(double t, bool in) const
Definition: snakewipe.cxx:85
SnakeWipe(sal_Int32 nElements, bool diagonal, bool flipOnYAxis)
Definition: snakewipe.cxx:36
const sal_Int32 m_sqrtElements
Definition: snakewipe.hxx:41
sal_Int32 nElements
uno_Any a
RttiCompleteObjectLocator col
B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
B2DHomMatrix createRotateB2DHomMatrix(double fRadiant)
line
constexpr T & temporary(T &&x)
::basegfx::B2DPolyPolygon flipOnYAxis(::basegfx::B2DPolyPolygon const &polypoly)
Flips on Y-axis:
::basegfx::B2DPolyPolygon flipOnXAxis(::basegfx::B2DPolyPolygon const &polypoly)
Flips on X-axis: