for (size_t i = 1; i < m_gdData->ddataLen; i++) {
int toXPix = relToXPix(m_gdData->ddata[i].first);
int toYPix = relToYPix(m_gdData->ddata[i].second);
- p.drawLine(fromXPix, fromYPix, toXPix, toYPix);
+
+ if (fromYPix > m_gHeight && toYPix > m_gHeight) {
+ /* Draw nothing */
+ } else if (toXPix == fromXPix)
+ p.drawLine(fromXPix, (fromYPix >= m_gHeight) ? m_gHeight : fromYPix, toXPix, (toYPix >= m_gHeight) ? m_gHeight : toYPix);
+ else if (toYPix >= m_gHeight) {
+ double k = static_cast<double>(toYPix - fromYPix) / static_cast<double>(toXPix - fromXPix);
+ double cToYPix = m_gHeight;
+ double cToXPix = (cToYPix - fromYPix + k * fromXPix) / k;
+ if (isnan(cToXPix))
+ cToXPix = fromXPix;
+ else
+ cToXPix = floor(cToXPix + 0.5);
+ p.drawLine(fromXPix, fromYPix, cToXPix, m_gHeight);
+ } else if (fromYPix >= m_gHeight) {
+ double k = static_cast<double>(toYPix - fromYPix) / static_cast<double>(toXPix - fromXPix);
+ double cFromYPix = m_gHeight;
+ double cFromXPix = (cFromYPix - fromYPix + k * fromXPix) / k;
+ if (isnan(cFromXPix))
+ cFromXPix = fromXPix;
+ else
+ cFromXPix = floor(cFromXPix + 0.5);
+ p.drawLine(cFromXPix, m_gHeight, toXPix, toYPix);
+ } else
+ p.drawLine(fromXPix, fromYPix, toXPix, toYPix);
+
fromXPix = toXPix;
fromYPix = toYPix;
}