mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 06:37:24 +02:00
Fixed incorrect search of index by value in statistical chart data.
This commit is contained in:
parent
f8e80bc266
commit
79442fde97
2 changed files with 10 additions and 10 deletions
|
@ -67,8 +67,8 @@ QString StatisticalChart::getDayString(int i) const {
|
|||
return daysLookup[int((x[i] - x[0]) / timeStep)];
|
||||
}
|
||||
|
||||
int StatisticalChart::findStartIndex(float v) const {
|
||||
if (v == 0) {
|
||||
int StatisticalChart::findStartIndex(float64 v) const {
|
||||
if (!v) {
|
||||
return 0;
|
||||
}
|
||||
const auto n = int(xPercentage.size());
|
||||
|
@ -82,7 +82,7 @@ int StatisticalChart::findStartIndex(float v) const {
|
|||
while (left <= right) {
|
||||
const auto middle = (right + left) >> 1;
|
||||
if (v < xPercentage[middle]
|
||||
&& (middle == 0 || v > xPercentage[middle - 1])) {
|
||||
&& (!middle || (v > xPercentage[middle - 1]))) {
|
||||
return middle;
|
||||
}
|
||||
if (v == xPercentage[middle]) {
|
||||
|
@ -97,7 +97,7 @@ int StatisticalChart::findStartIndex(float v) const {
|
|||
return left;
|
||||
}
|
||||
|
||||
int StatisticalChart::findEndIndex(int left, float v) const {
|
||||
int StatisticalChart::findEndIndex(int left, float64 v) const {
|
||||
const auto n = int(xPercentage.size());
|
||||
if (v == 1.) {
|
||||
return n - 1;
|
||||
|
@ -107,7 +107,7 @@ int StatisticalChart::findEndIndex(int left, float v) const {
|
|||
while (left <= right) {
|
||||
const auto middle = (right + left) >> 1;
|
||||
if (v > xPercentage[middle]
|
||||
&& (middle == n - 1 || v < xPercentage[middle + 1])) {
|
||||
&& ((middle == n - 1) || (v < xPercentage[middle + 1]))) {
|
||||
return middle;
|
||||
}
|
||||
if (v == xPercentage[middle]) {
|
||||
|
@ -123,7 +123,7 @@ int StatisticalChart::findEndIndex(int left, float v) const {
|
|||
}
|
||||
|
||||
|
||||
int StatisticalChart::findIndex(int left, int right, float v) const {
|
||||
int StatisticalChart::findIndex(int left, int right, float64 v) const {
|
||||
const auto n = int(xPercentage.size());
|
||||
|
||||
if (v <= xPercentage[left]) {
|
||||
|
@ -136,7 +136,7 @@ int StatisticalChart::findIndex(int left, int right, float v) const {
|
|||
while (left <= right) {
|
||||
const auto middle = (right + left) >> 1;
|
||||
if (v > xPercentage[middle]
|
||||
&& (middle == n - 1 || v < xPercentage[middle + 1])) {
|
||||
&& ((middle == n - 1) || (v < xPercentage[middle + 1]))) {
|
||||
return middle;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ struct StatisticalChart {
|
|||
|
||||
[[nodiscard]] QString getDayString(int i) const;
|
||||
|
||||
[[nodiscard]] int findStartIndex(float v) const;
|
||||
[[nodiscard]] int findEndIndex(int left, float v) const;
|
||||
[[nodiscard]] int findIndex(int left, int right, float v) const;
|
||||
[[nodiscard]] int findStartIndex(float64 v) const;
|
||||
[[nodiscard]] int findEndIndex(int left, float64 v) const;
|
||||
[[nodiscard]] int findIndex(int left, int right, float64 v) const;
|
||||
|
||||
struct Line final {
|
||||
std::vector<int> y;
|
||||
|
|
Loading…
Add table
Reference in a new issue