From 959e360dd0d06ac296579e975ffa49cabc229a8a Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 3 Jun 2025 17:09:29 -0600 Subject: [PATCH] fix LineSet arithmetic (again!) and reduce redundancy The logic for "is-integral" was backwards, and the code in both branches of the conditional was identical --- libs/canvas/line_set.cc | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/libs/canvas/line_set.cc b/libs/canvas/line_set.cc index f1d3e32193..43dffbb372 100644 --- a/libs/canvas/line_set.cc +++ b/libs/canvas/line_set.cc @@ -137,29 +137,21 @@ LineSet::render (Rect const & area, Cairo::RefPtr context) const void LineSet::add_coord (Coord pos, Distance width, Gtkmm2ext::Color color) { - _lines.push_back (Line (pos, width, color)); - Line& l (_lines.back()); - - if (_orientation == Horizontal) { - /* If width is odd (width % 2 != 0) and position is on - a whole pixel, shift it to a half-pixel position. Otherwise - force it back to an integer position. See - doc/cairo-single-pixel-lines for more details. - */ - if (fmod (l.width, 2.) && fmod (l.pos, 1.0)) { - l.pos += 0.5; - } else { - l.pos = floor (l.pos); - } + /* If width is odd (width % 2 != 0) and position is on + a whole pixel, shift it to a half-pixel position. Otherwise + force it back to an integer position. See + doc/cairo-single-pixel-lines for more details. + */ + if (fmod (width, 2.) && !fmod (pos, 1.0)) { + /* odd width, integral position */ + pos += 0.5; } else { - - if (fmod (l.width, 2.) && fmod (l.pos, 1.0)) { - l.pos += 0.5; - } else { - l.pos = floor (l.pos); - } + /* even width and/or non-integral position */ + pos = floor (pos); } + + _lines.push_back (Line (pos, width, color)); } void