LibreOffice Module basegfx (master) 1
WaveLine.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 */
10
13
14namespace basegfx
15{
17{
18 basegfx::B2DPolygon aPolygon;
19
20 double fWaveHeight = rRectangle.getHeight();
21 // Wavelength depends on the wave height so it looks nice
22 double fHalfWaveLength = fWaveHeight + 1.0;
23 double fWaveAmplitude = fWaveHeight / 2.0;
24
25 double fLastX = rRectangle.getMinX();
26 double fBaseY = rRectangle.getMinY() + fWaveAmplitude;
27 double fDirection = 1.0;
28
29 // In quadratic bezier the curve is 1/2 of the control height
30 // so we need to compensate for that.
31 constexpr double fHeightCompensation = 2.0;
32
33 aPolygon.append(basegfx::B2DPoint(fLastX, fBaseY));
34
35 for (double fI = fHalfWaveLength; fI <= rRectangle.getWidth(); fI += fHalfWaveLength)
36 {
37 basegfx::B2DPoint aPoint(fLastX + fHalfWaveLength, fBaseY);
38 basegfx::B2DPoint aControl(fLastX + (fHalfWaveLength / 2.0),
39 fBaseY + fDirection * fWaveAmplitude * fHeightCompensation);
40
41 aPolygon.appendQuadraticBezierSegment(aControl, aPoint);
42
43 fLastX = aPoint.getX(); // next iteration
44 fDirection *= -1.0; // fDirection iterates between 1 and -1
45 }
46
47 return aPolygon;
48}
49
50} // end of namespace basegfx
51
52/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
Base Point class with two double values.
Definition: b2dpoint.hxx:42
void appendQuadraticBezierSegment(const basegfx::B2DPoint &rQuadControlPoint, const basegfx::B2DPoint &rPoint)
This is a shortcut to append a quadratic bezier segment.
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
A two-dimensional interval over doubles.
Definition: b2drange.hxx:54
TYPE getWidth() const
return difference between upper and lower X value. returns 0 for empty sets.
Definition: Range2D.hxx:106
TYPE getMinX() const
get lower bound of the set. returns arbitrary values for empty sets.
Definition: Range2D.hxx:94
TYPE getMinY() const
get lower bound of the set. returns arbitrary values for empty sets.
Definition: Range2D.hxx:97
TYPE getHeight() const
return difference between upper and lower Y value. returns 0 for empty sets.
Definition: Range2D.hxx:109
TYPE getX() const
Get X-Coordinate of 2D Tuple.
Definition: Tuple2D.hxx:63
BASEGFX_DLLPUBLIC B2DPolygon createWaveLinePolygon(basegfx::B2DRectangle const &rRectangle)
Definition: WaveLine.cxx:16