[Libreoffice-commits] libvisio.git: 5 commits - src/lib
David Tardon
dtardon at redhat.com
Tue Jun 20 08:00:45 UTC 2017
src/lib/VSDContentCollector.cpp | 43 +++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 16 deletions(-)
New commits:
commit c156c530df29972d6c9391348ec4351809cfd2e2
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jun 20 09:58:13 2017 +0200
ofz#2307 avoid division by 0
Change-Id: I963ea7f7d7349c2614572b101be559b2f365a803
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index f8f6d1e..98fae36 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -51,16 +51,25 @@ void computeRounding(double &prevX, double &prevY, double x0, double y0, double
angle -= M_PI;
sweep = !sweep;
}
- double q = fabs(rounding / tan(angle / 2.0));
- if (q > prevHalfLength)
+ double t = tan(angle / 2.0);
+ double q;
+ if (t != 0)
{
- q = prevHalfLength;
- rounding = fabs(q*tan(angle / 2.0));
+ q = fabs(rounding / t);
+ if (q > prevHalfLength)
+ {
+ q = prevHalfLength;
+ rounding = fabs(q * t);
+ }
+ if (q > halfLength)
+ {
+ q = halfLength;
+ rounding = fabs(q * t);
+ }
}
- if (q > halfLength)
+ else
{
- q = halfLength;
- rounding = fabs(q*tan(angle / 2.0));
+ q = fabs(rounding);
}
newX0 = x0-q*cos(lambda1);
newY0 = y0-q*sin(lambda1);
commit d131eedbeb087f4eae263a927ed1c253e30d007b
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jun 20 09:43:13 2017 +0200
ofz#2268 avoid division by 0
Change-Id: Iaa07db26a677557499c9a1dc8cd4ce47c283aa2b
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 639e12a..f8f6d1e 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -2430,7 +2430,8 @@ void libvisio::VSDContentCollector::transformAngle(double &angle, XForm *txtxfor
double y1 =m_xform.pinLocY + sin(angle);
transformPoint(x0, y0, txtxform);
transformPoint(x1, y1, txtxform);
- angle = fmod(2.0*M_PI + (y1 > y0 ? 1.0 : -1.0)*acos((x1-x0) / hypot(x1-x0, y1-y0)), 2.0*M_PI);
+ const double h = hypot(x1-x0, y1-y0);
+ angle = h != 0 ? fmod(2.0*M_PI + (y1 > y0 ? 1.0 : -1.0)*acos((x1-x0) / h), 2.0*M_PI) : 0;
}
void libvisio::VSDContentCollector::transformFlips(bool &flipX, bool &flipY)
commit 40a0f2216a4279942d2f8c367ff59d843062086c
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jun 20 09:25:34 2017 +0200
ofz#2252 avoid division by 0
Change-Id: Icb58538864ce87554b2777de9177995166ed2795
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index b01afa0..639e12a 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -1396,7 +1396,8 @@ void libvisio::VSDContentCollector::collectEllipse(unsigned /* id */, unsigned l
{
_handleLevelChange(level);
librevenge::RVNGPropertyList ellipse;
- double angle = fmod(2.0*M_PI + (cy > yleft ? 1.0 : -1.0)*acos((cx-xleft) / hypot(xleft - cx, yleft - cy)), 2.0*M_PI);
+ double h = hypot(xleft - cx, yleft - cy);
+ double angle = h != 0 ? fmod(2.0*M_PI + (cy > yleft ? 1.0 : -1.0)*acos((cx-xleft) / h), 2.0*M_PI) : 0;
transformPoint(cx, cy);
transformPoint(xleft, yleft);
transformPoint(xtop, ytop);
commit e5d9a09912e484db5fa9c62e27b2a1f4e13e065a
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jun 20 09:19:05 2017 +0200
use std::hypot
Change-Id: Ie15d7b3727077a45ec69e1727785a8ce16f5fafc
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index a12066a..b01afa0 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -39,8 +39,8 @@ namespace
void computeRounding(double &prevX, double &prevY, double x0, double y0, double x, double y, double &rounding,
double &newX0, double &newY0, double &newX, double &newY, bool &sweep)
{
- double prevHalfLength = sqrt((y0-prevY)*(y0-prevY)+(x0-prevX)*(x0-prevX)) / 2.0;
- double halfLength = sqrt((y-y0)*(y-y0)+(x-x0)*(x-x0)) / 2.0;
+ double prevHalfLength = hypot(y0 - prevY, x0 - prevX) / 2.0;
+ double halfLength = hypot(y - y0, x - x0) / 2.0;
double lambda1 = atan2(y0-prevY, x0-prevX);
double lambda2 = atan2(y-y0, x-x0);
double angle = M_PI - lambda2 + lambda1;
@@ -1362,7 +1362,7 @@ void libvisio::VSDContentCollector::collectEllipticalArcTo(unsigned /* id */, un
VSD_DEBUG_MSG(("Centre: (%f,%f), angle %f\n", x0, y0, angle));
- double rx = sqrt(pow(x1-x0, 2) + pow(y1-y0, 2));
+ double rx = hypot(x1 - x0, y1 - y0);
double ry = ecc != 0 ? rx / ecc : rx;
librevenge::RVNGPropertyList arc;
int largeArc = 0;
@@ -1396,14 +1396,14 @@ void libvisio::VSDContentCollector::collectEllipse(unsigned /* id */, unsigned l
{
_handleLevelChange(level);
librevenge::RVNGPropertyList ellipse;
- double angle = fmod(2.0*M_PI + (cy > yleft ? 1.0 : -1.0)*acos((cx-xleft) / sqrt((xleft - cx)*(xleft - cx) + (yleft - cy)*(yleft - cy))), 2.0*M_PI);
+ double angle = fmod(2.0*M_PI + (cy > yleft ? 1.0 : -1.0)*acos((cx-xleft) / hypot(xleft - cx, yleft - cy)), 2.0*M_PI);
transformPoint(cx, cy);
transformPoint(xleft, yleft);
transformPoint(xtop, ytop);
transformAngle(angle);
- double rx = sqrt((xleft - cx)*(xleft - cx) + (yleft - cy)*(yleft - cy));
- double ry = sqrt((xtop - cx)*(xtop - cx) + (ytop - cy)*(ytop - cy));
+ double rx = hypot(xleft - cx, yleft - cy);
+ double ry = hypot(xtop - cx, ytop - cy);
int largeArc = 0;
double centreSide = (xleft-xtop)*(cy-ytop) - (yleft-ytop)*(cx-xtop);
@@ -1853,7 +1853,7 @@ void libvisio::VSDContentCollector::collectArcTo(unsigned /* id */, unsigned lev
else
{
librevenge::RVNGPropertyList arc;
- double chord = sqrt(pow((y2 - m_y),2) + pow((x2 - m_x),2));
+ double chord = hypot(y2 - m_y, x2 - m_x);
double radius = (4 * bow * bow + chord * chord) / (8 * fabs(bow));
int largeArc = fabs(bow) > radius ? 1 : 0;
bool sweep = (bow < 0);
@@ -2429,7 +2429,7 @@ void libvisio::VSDContentCollector::transformAngle(double &angle, XForm *txtxfor
double y1 =m_xform.pinLocY + sin(angle);
transformPoint(x0, y0, txtxform);
transformPoint(x1, y1, txtxform);
- angle = fmod(2.0*M_PI + (y1 > y0 ? 1.0 : -1.0)*acos((x1-x0) / sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))), 2.0*M_PI);
+ angle = fmod(2.0*M_PI + (y1 > y0 ? 1.0 : -1.0)*acos((x1-x0) / hypot(x1-x0, y1-y0)), 2.0*M_PI);
}
void libvisio::VSDContentCollector::transformFlips(bool &flipX, bool &flipY)
commit 8e38c802d6631b4ec36a422be66fc2f12835b4db
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jun 20 08:45:27 2017 +0200
ofz#2248 avoid division by 0
Change-Id: Ic77513d0f7d315122c5c396e2e09d39cfc6e4cc8
diff --git a/src/lib/VSDContentCollector.cpp b/src/lib/VSDContentCollector.cpp
index 26c1322..a12066a 100644
--- a/src/lib/VSDContentCollector.cpp
+++ b/src/lib/VSDContentCollector.cpp
@@ -1363,7 +1363,7 @@ void libvisio::VSDContentCollector::collectEllipticalArcTo(unsigned /* id */, un
VSD_DEBUG_MSG(("Centre: (%f,%f), angle %f\n", x0, y0, angle));
double rx = sqrt(pow(x1-x0, 2) + pow(y1-y0, 2));
- double ry = rx / ecc;
+ double ry = ecc != 0 ? rx / ecc : rx;
librevenge::RVNGPropertyList arc;
int largeArc = 0;
int sweep = 1;
More information about the Libreoffice-commits
mailing list