diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-06-15 09:59:46 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-06-15 17:56:51 +0200 |
commit | fdde571c6a5ec65a24c496af4c5928e22bd89ba2 (patch) | |
tree | 0f259eb34632be69e0dfc4b404b7ac27a3dcd5be /sc | |
parent | e726dcccabf0be4b880c6ddfaf0130dfd86aeb9f (diff) |
Negative percentile should be treated as 0
Change-Id: I460cd2ea6950cf9f8bc656a94c71973bd93c1fae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135879
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/data/colorscale.cxx | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sc/source/core/data/colorscale.cxx b/sc/source/core/data/colorscale.cxx index 96aeef2819c1..75f94d3bc2ed 100644 --- a/sc/source/core/data/colorscale.cxx +++ b/sc/source/core/data/colorscale.cxx @@ -540,10 +540,14 @@ Color CalcColor( double nVal, double nVal1, const Color& rCol1, double nVal2, co */ double GetPercentile( const std::vector<double>& rArray, double fPercentile ) { + assert(!rArray.empty()); + SAL_WARN_IF(fPercentile < 0, "sc", "negative percentile"); + if (fPercentile < 0) + return rArray.front(); + assert(fPercentile <= 1); size_t nSize = rArray.size(); double fFloor = ::rtl::math::approxFloor(fPercentile * (nSize-1)); - SAL_WARN_IF(fFloor < 0, "sc", "negative percentile"); - size_t nIndex = fFloor >= 0 ? static_cast<size_t>(fFloor) : 0; + size_t nIndex = static_cast<size_t>(fFloor); double fDiff = fPercentile * (nSize-1) - fFloor; std::vector<double>::const_iterator iter = rArray.begin() + nIndex; if (fDiff == 0.0) |