From 6481d5225ce7aba7c838412fdbff02a26d7ca50e Mon Sep 17 00:00:00 2001 From: Piotr Piastucki Date: Thu, 23 Jan 2020 21:30:11 +0100 Subject: [PATCH] Fix pixelateLine Add proper checks before advancing the position in the special case in pixelateLine to avoid creating pixels outside of the given range. --- mgraph440/pixelbase.cpp | 12 ++++++++---- salalib/spacepix.cpp | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mgraph440/pixelbase.cpp b/mgraph440/pixelbase.cpp index 2d13ad30..a02a3f63 100644 --- a/mgraph440/pixelbase.cpp +++ b/mgraph440/pixelbase.cpp @@ -79,10 +79,14 @@ PixelRefVector PixelBase::pixelateLine( Line l, int scalefactor ) const else { // Special case: exactly diagonal step (should only require one step): // (Should actually never happen) (Doesn't: checked with RFH) - a.x += 1; - pixel_list.push_back( PixelRef(a.x,parity * a.y) ); - a.y += 1; - pixel_list.push_back( PixelRef(a.x,parity * a.y) ); + if (a.x < b.x) { + a.x += 1; + pixel_list.push_back( PixelRef(a.x,parity * a.y) ); + } + if (a.y < b.y) { + a.y += 1; + pixel_list.push_back( PixelRef(a.x,parity * a.y) ); + } } } } diff --git a/salalib/spacepix.cpp b/salalib/spacepix.cpp index 2f45857b..3294eed2 100644 --- a/salalib/spacepix.cpp +++ b/salalib/spacepix.cpp @@ -128,10 +128,14 @@ PixelRefVector PixelBase::pixelateLine(Line l, int scalefactor) const { } else { // Special case: exactly diagonal step (should only require one step): // (Should actually never happen) (Doesn't: checked with RFH) - a.x += 1; - pixel_list.push_back(PixelRef(a.x, parity * a.y)); - a.y += 1; - pixel_list.push_back(PixelRef(a.x, parity * a.y)); + if (a.x < b.x) { + a.x += 1; + pixel_list.push_back(PixelRef(a.x, parity * a.y)); + } + if (a.y < b.y) { + a.y += 1; + pixel_list.push_back(PixelRef(a.x, parity * a.y)); + } } } }