commit 3f537f3667d9c44448bdff4cf7ca4b952ff167a6
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sun Sep 6 20:36:14 2020 -0600
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Tue Sep 15 17:09:08 2020 -0600
Add tests for and fix bugs applying camera to line, circ, and rect methods
---
source/graphics.cpp | 3 ++
test/graphicstests.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 1525951..5ad086c 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -597,6 +597,9 @@ void Graphics::rectfill(int x1, int y1, int x2, int y2) {
void Graphics::rectfill(int x1, int y1, int x2, int y2, uint8_t col) {
color(col);
+ applyCameraToPoint(&x1, &y1);
+ applyCameraToPoint(&x2, &y2);
+
sortCoordsForRect(&x1, &y1, &x2, &y2);
for (int y = y1; y <= y2; y++) {
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 4f2f5f1..a7e1d88 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -1006,6 +1006,85 @@ TEST_CASE("graphics class behaves as expected") {
CHECK_EQ(result, col);
}
+ SUBCASE("camera values apply to line") {
+ graphics->cls();
+ graphics->camera(-10, -10);
+ graphics->line(20, 20, 18, 22, 10);
+ graphics->camera();
+
+ std::vector<coloredPoint> expectedPoints = {
+ {30, 30, 10},
+ {29, 31, 10},
+ {28, 32, 10}
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("camera values apply to circ") {
+ graphics->cls();
+ graphics->camera(-20, -20);
+ graphics->circ(40, 40, 1, 14);
+ graphics->camera();
+
+ std::vector<coloredPoint> expectedPoints = {
+ {60, 59, 14},
+ {61, 60, 14},
+ {60, 61, 14},
+ {59, 60, 14},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("camera values apply to circfill") {
+ graphics->cls();
+ graphics->camera(-30, -30);
+ graphics->circfill(40, 40, 1, 3);
+ graphics->camera();
+
+ std::vector<coloredPoint> expectedPoints = {
+ {70, 70, 3},
+ {70, 69, 3},
+ {71, 70, 3},
+ {70, 71, 3},
+ {69, 70, 3},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("camera values apply to rect") {
+ graphics->cls();
+ graphics->camera(-50, -50);
+ graphics->rect(-10, -10, -8, -8, 4);
+ graphics->camera();
+
+ std::vector<coloredPoint> expectedPoints = {
+ {40, 40, 4},
+ {41, 40, 4},
+ {42, 40, 4},
+ {40, 41, 4},
+ {40, 42, 4},
+ {40, 42, 4},
+ {41, 42, 4},
+ {42, 42, 4},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
+ SUBCASE("camera values apply to rectfill") {
+ graphics->cls();
+ graphics->camera(-100, -100);
+ graphics->rectfill(0, 0, 1, 1, 3);
+ graphics->camera();
+
+ std::vector<coloredPoint> expectedPoints = {
+ {100, 100, 3},
+ {100, 101, 3},
+ {101, 100, 3},
+ {101, 101, 3},
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }