Commit c8709b33 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix shaky lines on 32-bit systems

The value of the mirrored x coordinate is almost exactly integer
all the time. On 64-bit systems the CPU converts it into integer
correctly, but on 32-bit systems it probably doesn't download it
from the FPU register (which are 80-bit and therefore more precise),
so the value got truncated to the decremented value. It results in the
lines becoming shaky due to random precision errors.

Now we explicitly round "almost-integer" part of the sum so no precision
fluctuations happen.

BUG:341577
parent 71f0eba3
...@@ -104,15 +104,8 @@ void KisPaintOp::setFanCornersInfo(bool fanCornersEnabled, qreal fanCornersStep) ...@@ -104,15 +104,8 @@ void KisPaintOp::setFanCornersInfo(bool fanCornersEnabled, qreal fanCornersStep)
void KisPaintOp::splitCoordinate(qreal coordinate, qint32 *whole, qreal *fraction) void KisPaintOp::splitCoordinate(qreal coordinate, qint32 *whole, qreal *fraction)
{ {
qint32 i = static_cast<qint32>(coordinate); const qint32 i = std::floor(coordinate);
const qreal f = coordinate - i;
if (coordinate < 0) {
// We always want the fractional part to be positive.
// E.g. -1.25 becomes -2 and +0.75
i--;
}
qreal f = coordinate - i;
*whole = i; *whole = i;
*fraction = f; *fraction = f;
......
...@@ -252,8 +252,8 @@ KisFixedPaintDeviceSP KisDabCache::tryFetchFromCache(const SavedDabParameters &p ...@@ -252,8 +252,8 @@ KisFixedPaintDeviceSP KisDabCache::tryFetchFromCache(const SavedDabParameters &p
} }
qreal positiveFraction(qreal x) { qreal positiveFraction(qreal x) {
int unused; qint32 unused = 0;
qreal fraction; qreal fraction = 0.0;
KisPaintOp::splitCoordinate(x, &unused, &fraction); KisPaintOp::splitCoordinate(x, &unused, &fraction);
return fraction; return fraction;
...@@ -267,8 +267,8 @@ KisDabCache::calculateDabRect(const QPointF &cursorPoint, ...@@ -267,8 +267,8 @@ KisDabCache::calculateDabRect(const QPointF &cursorPoint,
const KisPaintInformation& info, const KisPaintInformation& info,
const MirrorProperties &mirrorProperties) const MirrorProperties &mirrorProperties)
{ {
int x, y; qint32 x = 0, y = 0;
qreal subPixelX, subPixelY; qreal subPixelX = 0.0, subPixelY = 0.0;
if (mirrorProperties.coordinateSystemFlipped) { if (mirrorProperties.coordinateSystemFlipped) {
angle = 2 * M_PI - angle; angle = 2 * M_PI - angle;
...@@ -296,13 +296,13 @@ KisDabCache::calculateDabRect(const QPointF &cursorPoint, ...@@ -296,13 +296,13 @@ KisDabCache::calculateDabRect(const QPointF &cursorPoint,
if (mirrorProperties.horizontalMirror) { if (mirrorProperties.horizontalMirror) {
subPixelX = positiveFraction(-(cursorPoint.x() + hotSpot.x())); subPixelX = positiveFraction(-(cursorPoint.x() + hotSpot.x()));
width = m_d->brush->maskWidth(scaleX, angle, subPixelX, subPixelY, info); width = m_d->brush->maskWidth(scaleX, angle, subPixelX, subPixelY, info);
x = cursorPoint.x() + subPixelX + hotSpot.x() - width; x = qRound(cursorPoint.x() + subPixelX + hotSpot.x()) - width;
} }
if (mirrorProperties.verticalMirror) { if (mirrorProperties.verticalMirror) {
subPixelY = positiveFraction(-(cursorPoint.y() + hotSpot.y())); subPixelY = positiveFraction(-(cursorPoint.y() + hotSpot.y()));
height = m_d->brush->maskHeight(scaleY, angle, subPixelX, subPixelY, info); height = m_d->brush->maskHeight(scaleY, angle, subPixelX, subPixelY, info);
y = cursorPoint.y() + subPixelY + hotSpot.y() - height; y = qRound(cursorPoint.y() + subPixelY + hotSpot.y()) - height;
} }
return DabPosition(QRect(x, y, width, height), return DabPosition(QRect(x, y, width, height),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment