Skip to content

Commit 6b303e5

Browse files
authored
Merge pull request #64 from squix78/fix-drawVerticalLine
Fixing display bounding check in `drawVerticalLine`
2 parents 27e3686 + 4f7eca4 commit 6b303e5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

OLEDDisplay.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,18 @@ void OLEDDisplay::drawHorizontalLine(int16_t x, int16_t y, int16_t length) {
215215
}
216216

217217
void OLEDDisplay::drawVerticalLine(int16_t x, int16_t y, int16_t length) {
218-
if (y < 0 || y > DISPLAY_HEIGHT) return;
218+
if (x < 0 || x > DISPLAY_WIDTH) return;
219219

220-
if (x < 0) {
221-
length += x;
222-
x = 0;
220+
if (y < 0) {
221+
length += y;
222+
y = 0;
223+
}
224+
225+
if ( (y + length) > DISPLAY_HEIGHT) {
226+
length = (DISPLAY_HEIGHT - y);
223227
}
224228

225-
if (length < 0) return;
229+
if (length <= 0) return;
226230

227231

228232
uint8_t yOffset = y & 7;

0 commit comments

Comments
 (0)