From 825c77a81d317141591f83089bc2edba6660214a 2013-03-20 13:42:51 From: Miikka Heikkinen Date: 2013-03-20 13:42:51 Subject: [PATCH] Compensate for rounding errors when determining label visibility If the label bordered exactly the axis boundary, there was a chance it would not be shown because of half pixel rounding error somewhere down the line. Task-number: QTRD-1932 Reviewed-by: Mika Salmela --- diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index d09cb5f..5d2bfbd 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -142,10 +142,10 @@ void HorizontalAxis::updateGeometry() labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); } - //label overlap detection + //label overlap detection - compensate one pixel for rounding errors if(labelItem->pos().x() < width || - labelItem->pos().x() < axisRect.left() || - labelItem->pos().x() + boundingRect.width() -1 > axisRect.right()){ + labelItem->pos().x() < (axisRect.left() - 1.0) || + (labelItem->pos().x() + boundingRect.width() - 1.0) > axisRect.right()){ labelItem->setVisible(false); } else { labelItem->setVisible(true); diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 0c6ecac..9c9d462 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -152,10 +152,10 @@ void VerticalAxis::updateGeometry() labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); } - //label overlap detection - if(labelItem->pos().y() + boundingRect.height() > height || - labelItem->pos().y() + boundingRect.height()/2 > axisRect.bottom() || - labelItem->pos().y() + boundingRect.height()/2 < axisRect.top()) { + //label overlap detection - compensate one pixel for rounding errors + if (labelItem->pos().y() + boundingRect.height() > height || + (labelItem->pos().y() + (boundingRect.height() / 2.0) - 1.0) > axisRect.bottom() || + labelItem->pos().y() + (boundingRect.height() / 2.0) < (axisRect.top() - 1.0)) { labelItem->setVisible(false); } else {