summaryrefslogtreecommitdiff
path: root/chart2/source
diff options
context:
space:
mode:
authorofftkp <parisoplop@gmail.com>2022-03-24 11:32:24 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2022-03-28 11:43:28 +0200
commitab9896bfda4d2ef16f3cbb373edced33f9021492 (patch)
tree4adab1cc2d1be48c9d2b83f8e2937e2a0201190c /chart2/source
parent2f2df626117380427d2e5e8417316f52823f1e6f (diff)
tdf#147906 change all sqrt(a * a + b * b) occurences to std::hypot(a, b)
Other changes: In Splines.cxx, no longer divides dx, dy with fDiffMax because we switched to std::hypot, and hypot avoids intermediate overflows. Change-Id: I8c459a0e56deb86606fc9b1bf3e68b132a60705d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132073 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'chart2/source')
-rw-r--r--chart2/source/view/charttypes/Splines.cxx25
1 files changed, 7 insertions, 18 deletions
diff --git a/chart2/source/view/charttypes/Splines.cxx b/chart2/source/view/charttypes/Splines.cxx
index c1acc4a4600c..2633f7798741 100644
--- a/chart2/source/view/charttypes/Splines.cxx
+++ b/chart2/source/view/charttypes/Splines.cxx
@@ -411,26 +411,19 @@ bool createParameterT(const tPointVecType& rUniquePoints, double* t)
bool bIsSuccessful = true;
const lcl_tSizeType n = rUniquePoints.size() - 1;
t[0]=0.0;
- double dx = 0.0;
- double dy = 0.0;
- double fDiffMax = 1.0; //dummy values
double fDenominator = 0.0; // initialized for summing up
for (lcl_tSizeType i=1; i<=n ; ++i)
{ // 4th root(dx^2+dy^2)
- dx = rUniquePoints[i].first - rUniquePoints[i-1].first;
- dy = rUniquePoints[i].second - rUniquePoints[i-1].second;
- // scaling to avoid underflow or overflow
- fDiffMax = std::max(fabs(dx), fabs(dy));
- if (fDiffMax == 0.0)
+ double dx = rUniquePoints[i].first - rUniquePoints[i-1].first;
+ double dy = rUniquePoints[i].second - rUniquePoints[i-1].second;
+ if (dx == 0 && dy == 0)
{
bIsSuccessful = false;
break;
}
else
{
- dx /= fDiffMax;
- dy /= fDiffMax;
- fDenominator += sqrt(sqrt(dx * dx + dy * dy)) * sqrt(fDiffMax);
+ fDenominator += sqrt(std::hypot(dx, dy));
}
}
if (fDenominator == 0.0)
@@ -444,13 +437,9 @@ bool createParameterT(const tPointVecType& rUniquePoints, double* t)
double fNumerator = 0.0;
for (lcl_tSizeType i=1; i<=j ; ++i)
{
- dx = rUniquePoints[i].first - rUniquePoints[i-1].first;
- dy = rUniquePoints[i].second - rUniquePoints[i-1].second;
- fDiffMax = std::max(fabs(dx), fabs(dy));
- // same as above, so should not be zero
- dx /= fDiffMax;
- dy /= fDiffMax;
- fNumerator += sqrt(sqrt(dx * dx + dy * dy)) * sqrt(fDiffMax);
+ double dx = rUniquePoints[i].first - rUniquePoints[i-1].first;
+ double dy = rUniquePoints[i].second - rUniquePoints[i-1].second;
+ fNumerator += sqrt(std::hypot(dx, dy));
}
t[j] = fNumerator / fDenominator;