Skip to content

Commit

Permalink
LineRenderable: Fix rendering of cross-hatched areas
Browse files Browse the repository at this point in the history
The assumption that the first point lies in the top left corner of the
bounding box is not valid. As a result, the rendering of cross-hatched
area patterns was broken when the area extended beyond the viewport.

Amends commit 3590c35 (LineRenderable: Fix extent calculation in
simple constructor).
  • Loading branch information
lpechacek committed Apr 5, 2024
1 parent 87a7f97 commit c3f86a7
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/core/renderables/renderable_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "renderable_implementation.h"

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <iterator>
#include <memory>
Expand All @@ -21,6 +23,7 @@
#include <QPainter>
#include <QPen>
#include <QPoint>
#include <QSizeF>
#include <QTransform>
// IWYU pragma: no_include <QVariant>

Expand Down Expand Up @@ -269,17 +272,18 @@ LineRenderable::LineRenderable(const LineSymbol* symbol, QPointF first, QPointF
, cap_style(Qt::FlatCap)
, join_style(Qt::MiterJoin)
{
qreal half_line_width = (color_priority < 0) ? 0 : line_width/2;

auto right = MapCoordF(second - first).perpRight();
right.normalize();
right *= half_line_width;

extent.setTopLeft(first + right);
rectInclude(extent, first - right);
rectInclude(extent, second - right);
rectInclude(extent, second + right);

auto line_width_vector = MapCoordF(second - first).perpRight();
line_width_vector.normalize();
line_width_vector *= (color_priority < 0) ? 0 : line_width;

// Might possibly be simplified with QRectf::normalized() and addition of QMarginsF.
// We prefer tighter control of the control flow in this calculation though.
auto const origin = QPointF { std::min(first.x(), second.x()) - std::abs(line_width_vector.x()/2),
std::min(first.y(), second.y()) - std::abs(line_width_vector.y()/2) };
auto const size = QSizeF { std::abs(first.x() - second.x()) + std::abs(line_width_vector.x()),
std::abs(first.y() - second.y()) + std::abs(line_width_vector.y()) };

extent = QRectF { origin, size };
path.moveTo(first);
path.lineTo(second);
}
Expand Down

0 comments on commit c3f86a7

Please sign in to comment.