summaryrefslogtreecommitdiff
path: root/basegfx/source/polygon
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2019-06-25 10:45:48 +0900
committerTomaž Vajngerl <quikee@gmail.com>2019-06-28 03:15:08 +0200
commit80eb3fd393dd6d67f931c03b261b2558c7198da2 (patch)
tree49d4437af42942f3dee68c39b858e5d8762bf0cc /basegfx/source/polygon
parent3aa02e11e489c0f82024f5e323d6b63b4dcc3193 (diff)
add appendQuadraticBezierSegment to B2DPolygon
This adds a convenience method to B2DPolygon to add a quadratic bezier segment, which converts its one control point to two control points of a cubic bezier segment. The SVG path import is also modified to use this new method instead of converting inside the importer itself. Change-Id: I96e9b306066d9ccf2542b17a117db01fa235f405 Reviewed-on: https://gerrit.libreoffice.org/74809 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'basegfx/source/polygon')
-rw-r--r--basegfx/source/polygon/b2dpolygon.cxx22
-rw-r--r--basegfx/source/polygon/b2dsvgpolypolygon.cxx8
2 files changed, 23 insertions, 7 deletions
diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx
index 54d2844c3821..87343028ecfe 100644
--- a/basegfx/source/polygon/b2dpolygon.cxx
+++ b/basegfx/source/polygon/b2dpolygon.cxx
@@ -1330,6 +1330,28 @@ namespace basegfx
}
}
+ void B2DPolygon::appendQuadraticBezierSegment(const B2DPoint& rControlPoint, const B2DPoint& rPoint)
+ {
+ if (mpPolygon->count() == 0)
+ {
+ mpPolygon->append(rPoint);
+ const double nX((rControlPoint.getX() * 2.0 + rPoint.getX()) / 3.0);
+ const double nY((rControlPoint.getY() * 2.0 + rPoint.getY()) / 3.0);
+ setPrevControlPoint(0, B2DPoint(nX, nY));
+ }
+ else
+ {
+ const B2DPoint aPreviousPoint(mpPolygon->getPoint(mpPolygon->count() - 1));
+
+ const double nX1((rControlPoint.getX() * 2.0 + aPreviousPoint.getX()) / 3.0);
+ const double nY1((rControlPoint.getY() * 2.0 + aPreviousPoint.getY()) / 3.0);
+ const double nX2((rControlPoint.getX() * 2.0 + rPoint.getX()) / 3.0);
+ const double nY2((rControlPoint.getY() * 2.0 + rPoint.getY()) / 3.0);
+
+ appendBezierSegment(B2DPoint(nX1, nY1), B2DPoint(nX2, nY2), rPoint);
+ }
+ }
+
bool B2DPolygon::areControlPointsUsed() const
{
return mpPolygon->areControlPointsUsed();
diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
index 43ad5ee95596..991e50bf60f0 100644
--- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx
+++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx
@@ -375,12 +375,6 @@ namespace basegfx
nY += nLastY;
}
- // calculate the cubic bezier coefficients from the quadratic ones
- const double nX1Prime((nX1 * 2.0 + nLastX) / 3.0);
- const double nY1Prime((nY1 * 2.0 + nLastY) / 3.0);
- const double nX2Prime((nX1 * 2.0 + nX) / 3.0);
- const double nY2Prime((nY1 * 2.0 + nY) / 3.0);
-
// ensure existence of start point
if(!aCurrPoly.count())
{
@@ -388,7 +382,7 @@ namespace basegfx
}
// append curved edge
- aCurrPoly.appendBezierSegment(B2DPoint(nX1Prime, nY1Prime), B2DPoint(nX2Prime, nY2Prime), B2DPoint(nX, nY));
+ aCurrPoly.appendQuadraticBezierSegment(B2DPoint(nX1, nY1), B2DPoint(nX, nY));
// set last position
nLastX = nX;