commit c177599cfef76656b3480b37fe00ff3344942cb6
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Wed Apr 7 20:34:54 2021 -0600
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Wed Apr 7 20:34:54 2021 -0600
Fix bugs in print and oval drawing
Print now always increments cursor y position by 6
oval and ovalfill no longer infinite loop when both points are same
---
source/graphics.cpp | 30 ++++++++++++++++++++----------
test/graphicstests.cpp | 20 ++++++++++++++++++--
2 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 0de9d9d..d6e4b15 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -806,8 +806,9 @@ void Graphics::oval(int x0, int y0, int x1, int y1, uint8_t col) {
xa += bsq * 2;
wx++;
- if (xa >= ya)
- break;
+ if (xa >= ya) {
+ break;
+ }
_safeSetPixelFromPen(xc+wx, yc-wy);
@@ -838,8 +839,12 @@ void Graphics::oval(int x0, int y0, int x1, int y1, uint8_t col) {
ya += asq * 2;
wy++;
- if (ya > xa)
- break;
+ if (ya > xa) {
+ break;
+ }
+ if (ya == 0 && xa == 0) {
+ break;
+ }
_safeSetPixelFromPen(xc+wx, yc-wy);
_safeSetPixelFromPen(xc-wx, yc-wy);
@@ -895,8 +900,9 @@ void Graphics::ovalfill(int x0, int y0, int x1, int y1, uint8_t col){
xa += bsq * 2;
wx++;
- if (xa >= ya)
- break;
+ if (xa >= ya) {
+ break;
+ }
_private_h_line(xc+wx, xc-wx, yc-wy);
_private_h_line(xc+wx, xc-wx, yc+wy);
@@ -923,8 +929,12 @@ void Graphics::ovalfill(int x0, int y0, int x1, int y1, uint8_t col){
ya += asq * 2;
wy++;
- if (ya > xa)
- break;
+ if (ya > xa) {
+ break;
+ }
+ if (ya == 0 && xa == 0) {
+ break;
+ }
_private_h_line(xc+wx, xc-wx, yc-wy);
_private_h_line(xc+wx, xc-wx, yc+wy);
@@ -1007,8 +1017,6 @@ fix32 Graphics::fillp(fix32 pat) {
int Graphics::print(std::string str) {
int result = this->print(str, _memory->drawState.text_x, _memory->drawState.text_y);
- _memory->drawState.text_y += 6;
-
return result;
}
@@ -1058,6 +1066,8 @@ int Graphics::print(std::string str, int x, int y, uint8_t c) {
}
//todo: auto scrolling
+ _memory->drawState.text_y += 6;
+
return x;
}
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 93ecee3..1b3f75d 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -527,6 +527,14 @@ TEST_CASE("graphics class behaves as expected") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("oval({x0}, {x1}, {y0}, {y1}, {c}) with zeroes doesn't infinite loop") {
+ graphics->cls();
+ graphics->oval(40, 40, 40, 40, 13);
+
+ std::vector<coloredPoint> expectedPoints = {};
+
+ checkPoints(graphics, expectedPoints);
+ }
SUBCASE("ovalfill({x0}, {x1}, {y0}, {y1}, {c}) fills an ellipse") {
graphics->cls();
graphics->ovalfill(40, 40, 45, 42, 13);
@@ -547,6 +555,14 @@ TEST_CASE("graphics class behaves as expected") {
checkPoints(graphics, expectedPoints);
}
+ SUBCASE("ovalfill({x0}, {x1}, {y0}, {y1}, {c}) with zeroes doesn't infinite loop") {
+ graphics->cls();
+ graphics->ovalfill(40, 40, 40, 40, 13);
+
+ std::vector<coloredPoint> expectedPoints = {};
+
+ checkPoints(graphics, expectedPoints);
+ }
SUBCASE("rect({x1}, {y1}, {x2}, {y2}) uses pen color") {
graphics->cls();
graphics->color(15);
@@ -689,7 +705,7 @@ TEST_CASE("graphics class behaves as expected") {
graphics->print("doesnt matter", 42, 99);
CHECK(picoRam.drawState.text_x == 42);
- CHECK(picoRam.drawState.text_y == 99);
+ CHECK(picoRam.drawState.text_y == 105);
}
SUBCASE("print({str}, {x}, {y}, {c}) updates text location and color") {
graphics->cls();
@@ -700,7 +716,7 @@ TEST_CASE("graphics class behaves as expected") {
graphics->print("doesnt matter", 16, 18, 14);
CHECK(picoRam.drawState.text_x == 16);
- CHECK(picoRam.drawState.text_y == 18);
+ CHECK(picoRam.drawState.text_y == 24);
CHECK(picoRam.drawState.color == 14);
}
SUBCASE("print({str}) uses pal mapped color") {