summaryrefslogtreecommitdiffstats
path: root/basegfx/source/polygon/WaveLine.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /basegfx/source/polygon/WaveLine.cxx
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'basegfx/source/polygon/WaveLine.cxx')
-rw-r--r--basegfx/source/polygon/WaveLine.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/basegfx/source/polygon/WaveLine.cxx b/basegfx/source/polygon/WaveLine.cxx
new file mode 100644
index 000000000..bc85c4536
--- /dev/null
+++ b/basegfx/source/polygon/WaveLine.cxx
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <basegfx/polygon/WaveLine.hxx>
+#include <basegfx/point/b2dpoint.hxx>
+
+namespace basegfx
+{
+BASEGFX_DLLPUBLIC B2DPolygon createWaveLinePolygon(basegfx::B2DRectangle const& rRectangle)
+{
+ basegfx::B2DPolygon aPolygon;
+
+ double fWaveHeight = rRectangle.getHeight();
+ // Wavelength depends on the wave height so it looks nice
+ double fHalfWaveLength = fWaveHeight + 1.0;
+ double fWaveAmplitude = fWaveHeight / 2.0;
+
+ double fLastX = rRectangle.getMinX();
+ double fBaseY = rRectangle.getMinY() + fWaveAmplitude;
+ double fDirection = 1.0;
+
+ // In quadratic bezier the curve is 1/2 of the control height
+ // so we need to compensate for that.
+ constexpr double fHeightCompensation = 2.0;
+
+ aPolygon.append(basegfx::B2DPoint(fLastX, fBaseY));
+
+ for (double fI = fHalfWaveLength; fI <= rRectangle.getWidth(); fI += fHalfWaveLength)
+ {
+ basegfx::B2DPoint aPoint(fLastX + fHalfWaveLength, fBaseY);
+ basegfx::B2DPoint aControl(fLastX + (fHalfWaveLength / 2.0),
+ fBaseY + fDirection * fWaveAmplitude * fHeightCompensation);
+
+ aPolygon.appendQuadraticBezierSegment(aControl, aPoint);
+
+ fLastX = aPoint.getX(); // next iteration
+ fDirection *= -1.0; // fDirection iterates between 1 and -1
+ }
+
+ return aPolygon;
+}
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */