mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
guard against all negative values in PowerHist
This patch unifies the way in which we handle negative values in the Power Histogram by ignoring all values (speed, hr, cadence, power, and torque) less than zero. I'm not sure if this is the right way to handle such values long term, but it sure beats dumping core.
This commit is contained in:
@@ -415,38 +415,35 @@ PowerHist::setData(RideItem *_rideItem)
|
||||
const RideFilePoint *p1 = j.next();
|
||||
|
||||
int wattsIndex = int(floor(p1->watts / wattsDelta));
|
||||
if (wattsIndex < maxSize) {
|
||||
if (wattsIndex >= 0 && wattsIndex < maxSize) {
|
||||
if (wattsIndex >= wattsArray.size())
|
||||
wattsArray.resize(wattsIndex + 1);
|
||||
wattsArray[wattsIndex]++;
|
||||
}
|
||||
|
||||
if (p1->nm > 0) {
|
||||
int nmIndex = int(floor(p1->nm * torque_factor / nmDelta));
|
||||
if (nmIndex < maxSize) {
|
||||
if (nmIndex >= nmArray.size())
|
||||
nmArray.resize(nmIndex + 1);
|
||||
nmArray[nmIndex]++;
|
||||
}
|
||||
int nmIndex = int(floor(p1->nm * torque_factor / nmDelta));
|
||||
if (nmIndex >= 0 && nmIndex < maxSize) {
|
||||
if (nmIndex >= nmArray.size())
|
||||
nmArray.resize(nmIndex + 1);
|
||||
nmArray[nmIndex]++;
|
||||
}
|
||||
|
||||
int hrIndex = int(floor(p1->hr / hrDelta));
|
||||
if (hrIndex < 0) hrIndex = 0; // fix for index out of bounds with hr of -1. could happen with *any* dataa types?
|
||||
if (hrIndex < maxSize) {
|
||||
if (hrIndex >= 0 && hrIndex < maxSize) {
|
||||
if (hrIndex >= hrArray.size())
|
||||
hrArray.resize(hrIndex + 1);
|
||||
hrArray[hrIndex]++;
|
||||
}
|
||||
|
||||
int kphIndex = int(floor(p1->kph * speed_factor / kphDelta));
|
||||
if (kphIndex < maxSize) {
|
||||
if (kphIndex >= 0 && kphIndex < maxSize) {
|
||||
if (kphIndex >= kphArray.size())
|
||||
kphArray.resize(kphIndex + 1);
|
||||
kphArray[kphIndex]++;
|
||||
}
|
||||
|
||||
int cadIndex = int(floor(p1->cad / cadDelta));
|
||||
if (cadIndex < maxSize) {
|
||||
if (cadIndex >= 0 && cadIndex < maxSize) {
|
||||
if (cadIndex >= cadArray.size())
|
||||
cadArray.resize(cadIndex + 1);
|
||||
cadArray[cadIndex]++;
|
||||
|
||||
Reference in New Issue
Block a user