[Libreoffice-commits] core.git: basegfx/source include/basegfx slideshow/source

2023-08-24 Thread Regina Henschel (via logerrit)
 basegfx/source/polygon/b2dpolygontools.cxx  |  100 
 include/basegfx/polygon/b2dpolygontools.hxx |   19 +
 slideshow/source/engine/slideshowimpl.cxx   |   38 +++---
 3 files changed, 144 insertions(+), 13 deletions(-)

New commits:
commit 44c0f2da567b49ef8a539958a834f1bc841c2003
Author: Regina Henschel 
AuthorDate: Thu Aug 17 19:30:56 2023 +0200
Commit: Regina Henschel 
CommitDate: Thu Aug 24 17:54:46 2023 +0200

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 

diff --git a/basegfx/source/polygon/b2dpolygontools.cxx 
b/basegfx/source/polygon/b2dpolygontools.cxx
index 900ab735a1e0..04a22df578a6 100644
--- a/basegfx/source/polygon/b2dpolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolygontools.cxx
@@ -18,6 +18,7 @@
  */
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -3574,6 +3575,105 @@ namespace basegfx::utils
 }
 }
 
+B2DPolygon createSimplifiedPolygon(const B2DPolygon& rCandidate, const double 
fTolerance)
+{
+const sal_uInt32 nPointCount(rCandidate.count());
+if (nPointCount < 3 || rCandidate.areControlPointsUsed())
+return rCandidate;
+
+// The solution does not use recursion directly, since this could lead to 
a stack overflow if
+// nPointCount is very large. Instead, an own stack is used. This does not 
contain points, but
+// pairs of low and high index of a range in rCandidate. A parallel 
boolean vector is used to note
+// whether a point of rCandidate belongs to the output polygon or not.
+std::vector bIsKeptVec(nPointCount, false);
+bIsKeptVec[0] = true;
+bIsKeptVec[nPointCount - 1] = true;
+sal_uInt32 nKept = 2;
+std::stack> aUnfinishedRangesStack;
+
+// The RDP algorithm draws a straight line from the first point to the 
last point of a range.
+// Then, from the inner points of the range, the point that has the 
largest distance to the line
+// is determined. If the distance is greater than the tolerance, this 
point is kept and the lower
+// and upper sub-segments of the range are treated in the same way. If the 
distance is smaller
+// than the tolerance, none of the inner points will be kept.
+sal_uInt32 nLowIndex = 0;
+sal_uInt32 nHighIndex = nPointCount - 1;
+bool bContinue = true;
+do
+{
+bContinue = false;
+if (nHighIndex - nLowIndex < 2) // maximal two points, range is 
finished.
+{
+// continue with sibling upper range if any
+if (!aUnfinishedRangesStack.empty())
+{
+std::pair aIndexPair = 
aUnfinishedRangesStack.top();
+aUnfinishedRangesStack.pop();
+nLowIndex = aIndexPair.first;
+nHighIndex = aIndexPair.second;
+bContinue = true;
+}
+}
+else // the range needs examine the max distance
+{
+// Get maximal distance of inner points of the range to the 
straight line from start to
+// end point of the range.
+// For calculation of the distance we use the Hesse normal form of 
the straight line.
+B2DPoint aLowPoint = rCandidate.getB2DPoint(nLowIndex);
+B2DPoint aHighPoint = rCandidate.getB2DPoint(nHighIndex);
+B2DVector aNormalVec
+= basegfx::getNormalizedPerpendicular(B2DVector(aHighPoint) - 
B2DVector(aLowPoint));
+double fLineOriginDistance = 
aNormalVec.scalar(B2DVector(aLowPoint));
+double fMaxDist = 0;
+sal_uInt32 nMaxPointIndex = nLowIndex;
+for (sal_uInt32 i = nLowIndex + 1; i < nHighIndex; i++)
+{
+double fDistance
+= aNormalVec.scalar(B2DVector(rCandidate.getB2DPoint(i))) 
- fLineOriginDistance;
+if (std::fabs(fDistance) > fMaxDist)
+{
+fMaxDist = std::fabs(fDistance);
+nMaxPointIndex = i;
+}
+}
+
+if (fMaxDist >= fTolerance)
+{
+// We need to divide the current range into two sub ranges.
+bIsKeptVec[nMaxPointIndex] = true;
+nKept++;
+// 

[Libreoffice-commits] core.git: basegfx/source include/basegfx slideshow/source

2021-10-06 Thread Noel Grandin (via logerrit)
 basegfx/source/tools/keystoplerp.cxx |4 
++--
 include/basegfx/utils/keystoplerp.hxx|2 +-
 slideshow/source/engine/activities/continuouskeytimeactivitybase.cxx |2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

New commits:
commit e0117eff7f16277e7d6df18be60a6d6138b8611c
Author: Noel Grandin 
AuthorDate: Wed Oct 6 15:53:21 2021 +0200
Commit: Noel Grandin 
CommitDate: Wed Oct 6 19:37:44 2021 +0200

loplugin:moveparam in basegfx

Change-Id: I68d0de099641ae5b2ae92f46e86bdf4a43c468a4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123141
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/basegfx/source/tools/keystoplerp.cxx 
b/basegfx/source/tools/keystoplerp.cxx
index 0610dd19c228..e5d0d76304e2 100644
--- a/basegfx/source/tools/keystoplerp.cxx
+++ b/basegfx/source/tools/keystoplerp.cxx
@@ -42,8 +42,8 @@ static void validateInput(const std::vector& 
rKeyStops)
 
 namespace basegfx::utils
 {
-KeyStopLerp::KeyStopLerp( const std::vector& rKeyStops ) :
-maKeyStops(rKeyStops),
+KeyStopLerp::KeyStopLerp( std::vector&& rKeyStops ) :
+maKeyStops(std::move(rKeyStops)),
 mnLastIndex(0)
 {
 validateInput(maKeyStops);
diff --git a/include/basegfx/utils/keystoplerp.hxx 
b/include/basegfx/utils/keystoplerp.hxx
index 302020ac337e..f8a821e7a58f 100644
--- a/include/basegfx/utils/keystoplerp.hxx
+++ b/include/basegfx/utils/keystoplerp.hxx
@@ -53,7 +53,7 @@ namespace basegfx::utils
 need key stop lerping in the first place). All
 elements must be of monotonically increasing value.
  */
-explicit KeyStopLerp( const std::vector& rKeyStops );
+explicit KeyStopLerp( std::vector&& rKeyStops );
 
 /** Create lerper with given sequence of stops
 
diff --git 
a/slideshow/source/engine/activities/continuouskeytimeactivitybase.cxx 
b/slideshow/source/engine/activities/continuouskeytimeactivitybase.cxx
index 38d3590da3b6..db25d2dd4333 100644
--- a/slideshow/source/engine/activities/continuouskeytimeactivitybase.cxx
+++ b/slideshow/source/engine/activities/continuouskeytimeactivitybase.cxx
@@ -28,7 +28,7 @@ namespace slideshow::internal
 {
 ContinuousKeyTimeActivityBase::ContinuousKeyTimeActivityBase( const 
ActivityParameters& rParms ) :
 SimpleContinuousActivityBase( rParms ),
-maLerper( rParms.maDiscreteTimes )
+maLerper( std::vector(rParms.maDiscreteTimes) )
 {
 ENSURE_OR_THROW( rParms.maDiscreteTimes.size() > 1,
   
"ContinuousKeyTimeActivityBase::ContinuousKeyTimeActivityBase(): key times 
vector must have two entries or more" );


[Libreoffice-commits] core.git: basegfx/source include/basegfx slideshow/source xmlhelp/source

2017-12-29 Thread Noel Grandin
 basegfx/source/polygon/b3dpolygon.cxx|2 +-
 include/basegfx/polygon/b3dpolygon.hxx   |2 +-
 slideshow/source/engine/animationnodes/animationbasenode.cxx |2 +-
 slideshow/source/engine/animationnodes/animationbasenode.hxx |2 +-
 slideshow/source/engine/opengl/TransitionerImpl.cxx  |2 +-
 slideshow/source/engine/slide/userpaintoverlay.cxx   |2 +-
 slideshow/source/engine/slide/userpaintoverlay.hxx   |2 +-
 slideshow/source/engine/smilfunctionparser.cxx   |4 ++--
 slideshow/source/inc/smilfunctionparser.hxx  |4 ++--
 xmlhelp/source/cxxhelp/provider/urlparameter.cxx |2 +-
 xmlhelp/source/cxxhelp/provider/urlparameter.hxx |2 +-
 11 files changed, 13 insertions(+), 13 deletions(-)

New commits:
commit e21ae87458b0b6e0ad4cc9b41ed02fc8b6a20736
Author: Noel Grandin 
Date:   Fri Dec 29 09:20:44 2017 +0200

loplugin:passstuffbyref improved return in xmlhelp,slideshow

Change-Id: I57e235ecec733f1b5dd03f95f4e022769a369ae2
Reviewed-on: https://gerrit.libreoffice.org/47165
Tested-by: Jenkins 
Reviewed-by: Noel Grandin 

diff --git a/basegfx/source/polygon/b3dpolygon.cxx 
b/basegfx/source/polygon/b3dpolygon.cxx
index d28d31c7f2d8..ed564228e0fb 100644
--- a/basegfx/source/polygon/b3dpolygon.cxx
+++ b/basegfx/source/polygon/b3dpolygon.cxx
@@ -1548,7 +1548,7 @@ namespace basegfx
 mpPolygon->clearBColors();
 }
 
-B3DVector B3DPolygon::getNormal() const
+B3DVector const & B3DPolygon::getNormal() const
 {
 return mpPolygon->getNormal();
 }
diff --git a/include/basegfx/polygon/b3dpolygon.hxx 
b/include/basegfx/polygon/b3dpolygon.hxx
index 765762730f20..1d3dd515b757 100644
--- a/include/basegfx/polygon/b3dpolygon.hxx
+++ b/include/basegfx/polygon/b3dpolygon.hxx
@@ -79,7 +79,7 @@ namespace basegfx
 void clearBColors();
 
 // Normals interface
-B3DVector getNormal() const; // plane normal
+B3DVector const & getNormal() const; // plane normal
 B3DVector getNormal(sal_uInt32 nIndex) const; // normal in each point
 void setNormal(sal_uInt32 nIndex, const B3DVector& rValue);
 void transformNormals(const B3DHomMatrix& rMatrix);
diff --git a/slideshow/source/engine/animationnodes/animationbasenode.cxx 
b/slideshow/source/engine/animationnodes/animationbasenode.cxx
index 678c4a51a9ff..6c7eebed0ad1 100644
--- a/slideshow/source/engine/animationnodes/animationbasenode.cxx
+++ b/slideshow/source/engine/animationnodes/animationbasenode.cxx
@@ -465,7 +465,7 @@ AnimationBaseNode::fillCommonParameters() const
 getSlideSize());
 }
 
-AttributableShapeSharedPtr AnimationBaseNode::getShape() const
+AttributableShapeSharedPtr const & AnimationBaseNode::getShape() const
 {
 // any subsetting at all?
 if (mpShapeSubset)
diff --git a/slideshow/source/engine/animationnodes/animationbasenode.hxx 
b/slideshow/source/engine/animationnodes/animationbasenode.hxx
index d2c03a4ec4d3..84b3d5a82b5e 100644
--- a/slideshow/source/engine/animationnodes/animationbasenode.hxx
+++ b/slideshow/source/engine/animationnodes/animationbasenode.hxx
@@ -56,7 +56,7 @@ protected:
 /// Create parameter struct for ActivitiesFactory
 ActivitiesFactory::CommonParameters fillCommonParameters() const;
 ::basegfx::B2DVector const& getSlideSize() const { return 
maSlideSize; }
-AttributableShapeSharedPtr  getShape() const;
+AttributableShapeSharedPtr const &  getShape() const;
 
 private:
 virtual bool hasPendingAnimation() const override;
diff --git a/slideshow/source/engine/opengl/TransitionerImpl.cxx 
b/slideshow/source/engine/opengl/TransitionerImpl.cxx
index f8018c0275e6..8e21e6768616 100644
--- a/slideshow/source/engine/opengl/TransitionerImpl.cxx
+++ b/slideshow/source/engine/opengl/TransitionerImpl.cxx
@@ -808,7 +808,7 @@ namespace
 }
 };
 
-uno::Reference
+uno::Reference const &
 getOGLColorSpace()
 {
 return OGLColorSpaceHolder::get();
diff --git a/slideshow/source/engine/slide/userpaintoverlay.cxx 
b/slideshow/source/engine/slide/userpaintoverlay.cxx
index f1a1789ad8c9..096efe6b1284 100644
--- a/slideshow/source/engine/slide/userpaintoverlay.cxx
+++ b/slideshow/source/engine/slide/userpaintoverlay.cxx
@@ -468,7 +468,7 @@ namespace slideshow
 mrMultiplexer.addUserPaintHandler(mpHandler);
 }
 
-PolyPolygonVector UserPaintOverlay::getPolygons()
+PolyPolygonVector const & UserPaintOverlay::getPolygons()
 {
 return mpHandler->getPolygons();
 }
diff --git a/slideshow/source/engine/slide/userpaintoverlay.hxx 
b/slideshow/source/engine/slide/userpaintoverlay.hxx
index 4c2e16288c88..3dc6fa976a7f 100644
--- a/slideshow/source/engine/slide/userpaintoverlay.hxx
+++