From 44c0f2da567b49ef8a539958a834f1bc841c2003 Mon Sep 17 00:00:00 2001 From: Regina Henschel Date: Thu, 17 Aug 2023 19:30:56 +0200 Subject: tdf#112687 Simplify polylines from slideshow annotations Drawing with 'mouse as pen' in a slideshow creates hundreds of points. By commit 631964a2ce1da3fbbeb53a5550c0e6728ba644aa they are at least already combines to a polyline. The patch here now reduces the amount of points in such polyline to a reasonable number. If at some point the drawings in the slideshow are improved, this can be removed. The reduction is performed using the Douglas-Peucker algorithm. I have added the method to b2dpolygontools because I think it could be useful in other contexts. Change-Id: I9224ec3546d4442da8bc348aea8ce7b88fcc46dc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155811 Tested-by: Jenkins Reviewed-by: Regina Henschel --- include/basegfx/polygon/b2dpolygontools.hxx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/basegfx') diff --git a/include/basegfx/polygon/b2dpolygontools.hxx b/include/basegfx/polygon/b2dpolygontools.hxx index d5aa092ed9cb..2f73b76d33c6 100644 --- a/include/basegfx/polygon/b2dpolygontools.hxx +++ b/include/basegfx/polygon/b2dpolygontools.hxx @@ -524,6 +524,25 @@ namespace basegfx::utils */ BASEGFX_DLLPUBLIC OUString exportToSvgPoints( const B2DPolygon& rPoly ); + /** Reduces the number of points using the Ramer-Douglas-Peucker (RDP) algorithm. If the input + polygon has control points or less than three points, the input polygon is returned + unchanged. Otherwise, a simplified polygon is returned. If the input polygon is closed, + the caller is expected to ensure that the first and last points of the polygon are + identical. The polygon is treated as open in this case. Closing the result polygon is not + performed here, but left to the caller. + + @param rCandidate + The source polygon from which the reduced polygon is generated + + @param fTolerance + The tolerance for the RDP algorithm. + + @return + A newly created polygon with reduced point count. + */ + BASEGFX_DLLPUBLIC B2DPolygon createSimplifiedPolygon(const B2DPolygon& rCandidate, + const double fTolerance); + } // end of namespace basegfx::utils /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit