Skip to content

Commit

Permalink
Fix off by one error in hline and vline (tuupola#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola authored and CHiPs44 committed Mar 25, 2023
1 parent 02655e3 commit 0c9baf9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ All notable changes to this project will be documented in this file, in reverse
### Changed
- Rename `bitmap.c` to `hagl_bitmap.c` ([#100](https://github.com/tuupola/hagl/pull/100)).
- Rename `color_t` to `hagl_color_t` ([#104](https://github.com/tuupola/hagl/pull/104)).
- Initialize character buffer only when used and move it to heap ([#101](https://github.com/tuupola/hagl/pull/101), [#44](https://github.com/tuupola/hagl/issues/44)).

### Fixed
- Initialize character buffer only when used and move it to heap ([#101](https://github.com/tuupola/hagl/pull/101), [#44](https://github.com/tuupola/hagl/issues/44)) .
- Overflow bug when resizing big bitmaps ([#102](https://github.com/tuupola/hagl/pull/102), [#49](https://github.com/tuupola/hagl/issues/49)) .
- Both horizontal and vertical lines were one pixel too short ([#110](https://github.com/tuupola/hagl/pull/110)) .

### Added
- New `hagl_bitmap_init()` function ([#98](https://github.com/tuupola/hagl/pull/98)).
Expand Down
6 changes: 3 additions & 3 deletions src/hagl_hline.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ hagl_draw_hline_xyw(void const *_surface, int16_t x0, int16_t y0, uint16_t w, ha
}

/* Everything outside clip window, nothing to do. */
if (width < 0) {
if (width <= 0) {
return;
}

/* Cut anything going over right edge of clip window. */
if (((x0 + width) > surface->clip.x1)) {
width = width - (x0 + width - surface->clip.x1);
width = width - (x0 + width - 1 - surface->clip.x1);
}

surface->hline(&surface, x0, y0, width, color);
} else {
hagl_draw_line(surface, x0, y0, x0 + w, y0, color);
hagl_draw_line(surface, x0, y0, x0 + w - 1, y0, color);
}
}
6 changes: 3 additions & 3 deletions src/hagl_vline.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ hagl_draw_vline_xyh(void const *_surface, int16_t x0, int16_t y0, uint16_t h, ha
}

/* Everything outside clip window, nothing to do. */
if (height < 0) {
if (height <= 0) {
return;
}

/* Cut anything going over right edge. */
if (((y0 + height) > surface->clip.y1)) {
height = height - (y0 + height - surface->clip.y1);
height = height - (y0 + height - 1 - surface->clip.y1);
}

surface->vline(&surface, x0, y0, height, color);
} else {
hagl_draw_line(surface, x0, y0, x0, y0 + h, color);
hagl_draw_line(surface, x0, y0, x0, y0 + h - 1, color);
}
}

0 comments on commit 0c9baf9

Please sign in to comment.