From f08299ea1eeec955989ba471365244b23c919da6 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 17 Jul 2023 05:05:20 +0200 Subject: [PATCH] Fix lineset drawing for lines > 1px width This is a follow up to 248e37ac0c. A line at 0 with 1px width should draw from 0.5 to 1.5 (cairo pixel offset). The same line with a width of 3px is -0.5 to 2.5. The self.intersection code calculates this correctly, subtracting shift, the drawing code however incorrectly added it. This fixes MIDI track grid/note offset as well as a bleed below the track. --- libs/canvas/line_set.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/canvas/line_set.cc b/libs/canvas/line_set.cc index 45aadf957d..017c3e7617 100644 --- a/libs/canvas/line_set.cc +++ b/libs/canvas/line_set.cc @@ -101,7 +101,7 @@ LineSet::render (Rect const & area, Cairo::RefPtr context) const for (auto const & l : _lines) { Rect self; - const double shift = l.width * 0.5; + const double shift = l.width * 0.5 - 1; if (_orientation == Horizontal) { self = Rect (0, l.pos - (l.width/2.0), _extent, l.pos + (l.width/2.0)); @@ -135,12 +135,12 @@ LineSet::render (Rect const & area, Cairo::RefPtr context) const if (_orientation == Horizontal) { const double y = item_to_window (Duple (0, l.pos)).y; - context->move_to (intersection.x0, y + shift); - context->line_to (intersection.x1, y + shift); + context->move_to (intersection.x0, y - shift); + context->line_to (intersection.x1, y - shift); } else { const double x = item_to_window (Duple (l.pos, 0)).x; - context->move_to (x + shift, intersection.y0); - context->line_to (x + shift, intersection.y1); + context->move_to (x - shift, intersection.y0); + context->line_to (x - shift, intersection.y1); } context->stroke ();