[Libreoffice-commits] libcdr.git: src/lib

David Tardon dtardon at redhat.com
Mon Mar 12 13:03:28 UTC 2018


 src/lib/CDRContentCollector.cpp |   27 +++++++++++----------------
 src/lib/CDRParser.cpp           |   18 +++++++++---------
 2 files changed, 20 insertions(+), 25 deletions(-)

New commits:
commit 6c957a8bb3639bd47a8b697e665772ce84baf788
Author: David Tardon <dtardon at redhat.com>
Date:   Mon Mar 12 13:57:08 2018 +0100

    speed up angle normalization
    
    Change-Id: I788422726995f95eb3d040978887fb0dcf647ebf

diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index 0487319..c8a556f 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -50,6 +50,13 @@ void normalize(double &d)
   }
 }
 
+void normalizeAngle(double &angle)
+{
+  angle = fmod(angle, 360);
+  if (angle < 0)
+    angle += 360;
+}
+
 }
 }
 
@@ -718,10 +725,7 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
         else if (m_currentFillStyle.gradient.m_stops.size() == 2)
         {
           double angle = m_currentFillStyle.gradient.m_angle * 180 / M_PI;
-          while (angle < 0.0)
-            angle += 360.0;
-          while (angle > 360.0)
-            angle -= 360.0;
+          normalizeAngle(angle);
           propList.insert("draw:fill", "gradient");
           propList.insert("draw:start-color", m_ps.getRGBColorString(m_currentFillStyle.gradient.m_stops[0].m_color));
           propList.insert("draw:end-color", m_ps.getRGBColorString(m_currentFillStyle.gradient.m_stops[1].m_color));
@@ -732,10 +736,7 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
           case 3: // conical
             propList.insert("draw:style", "linear");
             angle += 90.0;
-            while (angle < 0.0)
-              angle += 360.0;
-            while (angle > 360.0)
-              angle -= 360.0;
+            normalizeAngle(angle);
             propList.insert("draw:angle", (int)angle);
             propList.insert("draw:border", (double)(m_currentFillStyle.gradient.m_edgeOffset)/100.0, librevenge::RVNG_PERCENT);
             break;
@@ -754,10 +755,7 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
           default:
             propList.insert("draw:style", "linear");
             angle += 90.0;
-            while (angle < 0.0)
-              angle += 360.0;
-            while (angle > 360.0)
-              angle -= 360.0;
+            normalizeAngle(angle);
             propList.insert("draw:angle", (int)angle);
             librevenge::RVNGPropertyListVector vec;
             for (auto &gradStop : m_currentFillStyle.gradient.m_stops)
@@ -778,10 +776,7 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
           propList.insert("draw:style", "linear");
           double angle = m_currentFillStyle.gradient.m_angle * 180 / M_PI;
           angle += 90.0;
-          while (angle < 0.0)
-            angle += 360.0;
-          while (angle > 360.0)
-            angle -= 360.0;
+          normalizeAngle(angle);
           propList.insert("draw:angle", (int)angle);
           librevenge::RVNGPropertyListVector vec;
           for (auto &gradStop : m_currentFillStyle.gradient.m_stops)
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index 6528d32..1dd4bfa 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -148,6 +148,13 @@ static int parseColourString(const char *colourString, libcdr::CDRColor &colour,
   return 1;
 }
 
+void normalizeAngle(double &angle)
+{
+  angle = std::fmod(angle, 2*M_PI);
+  if (angle < 0)
+    angle += 2*M_PI;
+}
+
 } // anonymous namespace
 
 libcdr::CDRParser::CDRParser(const std::vector<librevenge::RVNGInputStream *> &externalStreams, libcdr::CDRCollector *collector)
@@ -1283,15 +1290,8 @@ void libcdr::CDRParser::readEllipse(librevenge::RVNGInputStream *input)
   double rx = fabs(cx);
   double ry = fabs(cy);
 
-  while (angle1 < 0.0)
-    angle1 += 2*M_PI;
-  while (angle1 > 2*M_PI)
-    angle1 -= 2*M_PI;
-
-  while (angle2 < 0.0)
-    angle2 += 2*M_PI;
-  while (angle2 > 2*M_PI)
-    angle2 -= 2*M_PI;
+  normalizeAngle(angle1);
+  normalizeAngle(angle2);
 
   CDRPath path;
   if (angle1 != angle2)


More information about the Libreoffice-commits mailing list