foxygit / fake-08-xbox360 Log in
commit 24953be8f113a493fb4d9c1970f104e010c99039
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Sat Aug 16 18:33:19 2025 -0600
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Sat Sep 13 20:59:48 2025 -0600

    Add new rrect functions

    radius < 16 should be pixel perfect via look up tables
    larger radius not accurate, but look OK
---
 source/graphics.cpp           | 180 +++++++++++++++++++++++++++++-
 source/graphics.h             |   6 +
 source/p8GlobalLuaFunctions.h |   6 +-
 source/picoluaapi.cpp         |  43 ++++++++
 source/picoluaapi.h           |   2 +
 source/vm.cpp                 |   2 +
 test/endtoendtests.cpp        |   3 +-
 test/graphicstests.cpp        | 251 ++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 489 insertions(+), 4 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index f03f563..e68644e 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -608,7 +608,6 @@ void Graphics::_setPixelFromPen(int x, int y) {

 	setPixelNibble(x, y, finalC, screenBuffer);
 }
-//end helper methods

 void Graphics::cls() {
 	this->cls(0);
@@ -1284,6 +1283,185 @@ void Graphics::rectfill(int x1, int y1, int x2, int y2, uint8_t col) {
 	}
 }

+#include <cmath>
+
+int Graphics::_getRRectCutAmount(int radius, int row) {
+    //reverse engineered look up tables for pixel perfect matches (and speed)
+    if (radius == 6) {
+        static int cuts[] = {5,3,2,1,1,0};
+        return (row < 6) ? cuts[row] : 0;
+    } else if (radius == 7) {
+        static int cuts[] = {6,4,3,2,1,1,0};
+        return (row < 7) ? cuts[row] : 0;
+    } else if (radius == 8) {
+        static int cuts[] = {7,5,3,2,2,1,1,0};
+        return (row < 8) ? cuts[row] : 0;
+    } else if (radius == 9) {
+        static int cuts[] = {7,5,4,3,2,1,1,0};
+        return (row < 8) ? cuts[row] : 0;
+    } else if (radius == 10) {
+        static int cuts[] = {7,5,4,3,2,1,1,0};
+        return (row < 8) ? cuts[row] : 0;
+    } else if (radius == 11 || radius == 12) {
+        static int cuts[] = {9,7,5,4,3,2,2,1,1,0,0};
+        return (row < 11) ? cuts[row] : 0;
+    } else if (radius == 13 || radius == 14) {
+        static int cuts[] = {11,8,7,5,4,3,3,2,1,1,1,0,0};
+        return (row < 13) ? cuts[row] : 0;
+    } else if (radius == 15 || radius == 16) {
+        static int cuts[] = {13,10,8,7,5,4,4,3,2,2,1,1,1,0,0};
+        return (row < 15) ? cuts[row] : 0;
+    } else {
+		//not pixel perfect, but it is rounded
+        if (row >= radius) return 0;
+
+        // Calculate using circle equation
+        double y = static_cast<double>(radius - row - 1);
+        double discriminant = static_cast<double>(radius * radius) - (y * y);
+
+        if (discriminant <= 0) return 0;
+
+        double x = static_cast<double>(radius) - std::sqrt(discriminant);
+        int cut = static_cast<int>(x + 0.5) - 1;
+
+        // Handle the tail end where cuts often stay at 1 for multiple rows
+        // This prevents premature jumps to 0
+        if (cut == 0 && row < radius - 1) {
+            double tail_y = static_cast<double>(radius - row);
+            if (tail_y <= 2.5) {
+                cut = 1;
+            }
+        }
+
+        return (cut < 0) ? 0 : cut;
+    }
+}
+
+void Graphics::rrect(int x, int y, int w, int h, int r) {
+	this->rrect(x, y, w, h, r, _memory->drawState.color);
+}
+
+void Graphics::rrect(int x, int y, int w, int h, int r, uint8_t col) {
+	color(col);
+
+	// Pico 8 docs say: "The radius used is clamped to fall the range 0 .. min(width,height)/2."
+	int maxRadius = (w < h ? w : h) / 2;
+	if (r > maxRadius) {
+		r = maxRadius;
+	}
+
+	// no radius: fall back to rect
+	if (r <= 0) {
+		this->rect(x, y, x + w - 1, y + h - 1, col);
+		return;
+	}
+
+	applyCameraToPoint(&x, &y);
+
+	for (int row = 0; row < h; row++) {
+		int cutAmount = 0;
+
+		if (row < r) {
+			//top half
+			if (r <= 5) {
+				cutAmount = r - 1 - row;
+			} else {
+				int yFromCorner = row;
+				int rSquared = r * r;
+
+				int maxX = 0;
+				for (int testX = 0; testX < r; testX++) {
+					if (testX * testX + yFromCorner * yFromCorner <= rSquared) {
+						maxX = testX;
+					}
+				}
+
+				cutAmount = r - 1 - maxX;
+			}
+		} else if (row >= h - r) {
+			// bottom half
+			int bottomRow = h - 1 - row;
+			if (r <= 5) {
+				cutAmount = r - 1 - bottomRow;
+			} else {
+				cutAmount = _getRRectCutAmount(r, bottomRow);
+			}
+		}
+
+		if (cutAmount < 0) cutAmount = 0;
+		if (cutAmount * 2 >= w) cutAmount = (w - 1) / 2;
+
+		int lineStart = x + cutAmount;
+		int lineEnd = x + w - 1 - cutAmount;
+
+		if (lineStart <= lineEnd) {
+			if (row == 0 || row == h - 1) {
+				_private_h_line(lineStart, lineEnd, y + row);
+			} else {
+				_safeSetPixelFromPen(lineStart, y + row);
+				if (lineStart != lineEnd) {
+					_safeSetPixelFromPen(lineEnd, y + row);
+				}
+			}
+		}
+	}
+}
+
+void Graphics::rrectfill(int x, int y, int w, int h, int r) {
+	this->rrectfill(x, y, w, h, r, _memory->drawState.color);
+}
+
+void Graphics::rrectfill(int x, int y, int w, int h, int r, uint8_t col) {
+	color(col);
+
+	// Pico 8 docs say: "The radius used is clamped to fall the range 0 .. min(width,height)/2."
+	int maxRadius = (w < h ? w : h) / 2;
+	if (r > maxRadius) {
+		r = maxRadius;
+	}
+
+	// no radius: fall back to rectfill
+	if (r <= 0) {
+		this->rectfill(x, y, x + w - 1, y + h - 1, col);
+		return;
+	}
+
+	applyCameraToPoint(&x, &y);
+
+	for (int row = 0; row < h; row++) {
+		int cutAmount = 0;
+
+		if (row < r) {
+			//top half
+			if (r <= 5) {
+				// Small radius appear to be a simple stepping pattern
+				cutAmount = r - 1 - row;
+			} else {
+				// Large radius: use pixel perfect look ups with fallback
+				cutAmount = _getRRectCutAmount(r, row);
+			}
+		} else if (row >= h - r) {
+			//bottom half
+			int bottomRow = h - 1 - row;
+			if (r <= 5) {
+				cutAmount = r - 1 - bottomRow;
+			} else {
+				cutAmount = _getRRectCutAmount(r, bottomRow);
+			}
+		}
+
+		if (cutAmount < 0) cutAmount = 0;
+		if (cutAmount * 2 >= w) cutAmount = (w - 1) / 2;
+
+		int lineStart = x + cutAmount;
+		int lineEnd = x + w - 1 - cutAmount;
+
+		if (lineStart <= lineEnd) {
+			_private_h_line(lineStart, lineEnd, y + row);
+		}
+	}
+}
+
 fix32 Graphics::fillp(fix32 pat) {
 	int32_t prev = (_memory->drawState.fillPattern[0] << 16)
                  | (_memory->drawState.fillPattern[1] << 24)
diff --git a/source/graphics.h b/source/graphics.h
index c05d06e..fe8810e 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -58,6 +58,7 @@ class Graphics {
 	void _safeSetPixelFromPen(int x, int y);
 	void _private_h_line (int x1, int x2, int y);
 	void _private_v_line (int y1, int y2, int x);
+	int _getRRectCutAmount(int radius, int row);

 	public:
 	Graphics(std::string fontdata, PicoRam* memory);
@@ -108,6 +109,11 @@ class Graphics {
 	void rectfill(int x1, int y1, int x2, int y2);
 	void rectfill(int x1, int y1, int x2, int y2, uint8_t col);

+	void rrect(int x, int y, int w, int h, int r);
+	void rrect(int x, int y, int w, int h, int r, uint8_t col);
+	void rrectfill(int x, int y, int w, int h, int r);
+	void rrectfill(int x, int y, int w, int h, int r, uint8_t col);
+
 	fix32 fillp(fix32 pat);

 	int drawCharacter(
diff --git a/source/p8GlobalLuaFunctions.h b/source/p8GlobalLuaFunctions.h
index 82c69cd..70657bf 100644
--- a/source/p8GlobalLuaFunctions.h
+++ b/source/p8GlobalLuaFunctions.h
@@ -270,7 +270,8 @@ ovalfill, line, spr, sspr, mget, mset,
 tline, peek, poke, peek2, poke2, peek4,
 poke4, memcpy, memset, max, min, mid, flr,
 ceil, cos, sin, atan2, rnd, srand, band,
-bor, bxor, bnot, shl, shr, lshr, rotl, rotr =
+bor, bxor, bnot, shl, shr, lshr, rotl, rotr,
+rrect, rrectfill =

 time, t, sub, chr, ord, tostr, tonum,
 add, del, deli, clip, color, pal, palt,
@@ -280,7 +281,8 @@ ovalfill, line, spr, sspr, mget, mset,
 tline, peek, poke, peek2, poke2, peek4,
 poke4, memcpy, memset, max, min, mid, flr,
 ceil, cos, sin, atan2, rnd, srand, band,
-bor, bxor, bnot, shl, shr, lshr, rotl, rotr
+bor, bxor, bnot, shl, shr, lshr, rotl, rotr,
+rrect, rrectfill

 --save state code modified from ps4-p8
 //https://github.com/voliva/ps4-p8/blob/ecba7f93ef9ba73ccb121b45ede6f46e651cef65/pico8_ps4/lua_lang_fns.cpp
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index a720481..5cbdfde 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -295,6 +295,49 @@ int rectfill(lua_State *L){
     return 0;
 }

+int rrect(lua_State *L){
+
+    if (lua_gettop(L) >= 5) {
+        int x = lua_tonumber(L,1);
+        int y = lua_tonumber(L,2);
+        int w = lua_tonumber(L,3);
+        int h = lua_tonumber(L,4);
+        int r = lua_tonumber(L,5);
+
+        if (lua_gettop(L) == 5){
+            _graphicsForLuaApi->rrect(x, y, w, h, r);
+        }
+        else {
+            uint8_t c = lua_tonumber(L,6);
+
+            _graphicsForLuaApi->rrect(x, y, w, h, r, c);
+        }
+    }
+
+    return 0;
+}
+
+int rrectfill(lua_State *L){
+    if (lua_gettop(L) >= 5) {
+        int x = lua_tonumber(L,1);
+        int y = lua_tonumber(L,2);
+        int w = lua_tonumber(L,3);
+        int h = lua_tonumber(L,4);
+        int r = lua_tonumber(L,5);
+
+        if (lua_gettop(L) == 5){
+            _graphicsForLuaApi->rrectfill(x, y, w, h, r);
+        }
+        else {
+            fix32 c = lua_tonumber(L,6);
+
+            _graphicsForLuaApi->rrectfill(x, y, w, h, r, c);
+        }
+    }
+
+    return 0;
+}
+
 int print(lua_State *L){
     int numArgs = lua_gettop(L);
     if (numArgs == 0){
diff --git a/source/picoluaapi.h b/source/picoluaapi.h
index 48c3eb8..15e7045 100644
--- a/source/picoluaapi.h
+++ b/source/picoluaapi.h
@@ -29,6 +29,8 @@ int oval(lua_State *L);
 int ovalfill(lua_State *L);
 int rect(lua_State *L);
 int rectfill(lua_State *L);
+int rrect(lua_State *L);
+int rrectfill(lua_State *L);
 int print(lua_State *L);
 int spr(lua_State *L);
 int sspr(lua_State *L);
diff --git a/source/vm.cpp b/source/vm.cpp
index 3631629..90867c4 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -195,6 +195,8 @@ bool Vm::loadCart(Cart* cart) {
     lua_register(_luaState, "ovalfill", ovalfill);
     lua_register(_luaState, "rect", rect);
     lua_register(_luaState, "rectfill", rectfill);
+    lua_register(_luaState, "rrect", rrect);
+    lua_register(_luaState, "rrectfill", rrectfill);
     lua_register(_luaState, "print", print);
     lua_register(_luaState, "cursor", cursor);
     lua_register(_luaState, "spr", spr);
diff --git a/test/endtoendtests.cpp b/test/endtoendtests.cpp
index 6ec850e..947f959 100644
--- a/test/endtoendtests.cpp
+++ b/test/endtoendtests.cpp
@@ -451,7 +451,8 @@ TEST_CASE("Loading and running carts") {
                 "poke4", "memcpy", "memset", "max", "min", "mid", "flr",
                 "ceil", "cos", "sin", "atan2", "rnd", "srand", "band",
                 "bor", "bxor", "bnot", "shl", "shr", "lshr", "rotl", "rotr",
-                "mapdraw", "extcmd", "next", "inext", "pairs", "ipairs"
+                "mapdraw", "extcmd", "next", "inext", "pairs", "ipairs",
+                "rrect", "rrectfill"
             };

             string missing = "";
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index c73402a..4c1c265 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -2425,6 +2425,257 @@ TEST_CASE("graphics class behaves as expected") {

         checkPoints(graphics, expectedPoints);
     }
+    SUBCASE("rrect with no radius draws a rect") {
+        graphics->cls();
+        graphics->rrect(40, 40, 3, 3, 0, 15);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {40, 40, 15},
+            {40, 41, 15},
+            {40, 42, 15},
+            {40, 43, 0},
+            {41, 40, 15},
+            {41, 41, 0},
+            {41, 42, 15},
+            {42, 40, 15},
+            {42, 41, 15},
+            {42, 42, 15},
+            {42, 43, 0},
+            {43, 40, 0},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrectfill with no radius draws a rect") {
+        graphics->cls();
+        graphics->rrectfill(40, 40, 3, 3, 0, 15);
+
+        std::vector<coloredPoint> expectedPoints = {
+            {40, 40, 15},
+            {40, 41, 15},
+            {40, 42, 15},
+            {40, 43, 0},
+            {41, 40, 15},
+            {41, 41, 15},
+            {41, 42, 15},
+            {42, 40, 15},
+            {42, 41, 15},
+            {42, 42, 15},
+            {42, 43, 0},
+            {43, 40, 0},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrect with radius 1 produces some output") {
+        graphics->cls();
+        graphics->rrect(10, 10, 6, 6, 1, 8);
+
+        // Just check that some pixels are drawn (not testing exact pattern)
+        bool hasPixels = false;
+        for (int y = 10; y < 16; y++) {
+            for (int x = 10; x < 16; x++) {
+                if (graphics->pget(x, y) == 8) {
+                    hasPixels = true;
+                    break;
+                }
+            }
+        }
+        CHECK(hasPixels);
+    }
+    SUBCASE("rrectfill with radius 1 draws stepped corners") {
+        graphics->cls();
+        graphics->rrectfill(10, 10, 6, 6, 1, 8);
+
+        std::vector<coloredPoint> expectedPoints = {
+            // Row 0: cut 0 (full width)
+            {10, 10, 8}, {11, 10, 8}, {12, 10, 8}, {13, 10, 8}, {14, 10, 8}, {15, 10, 8},
+            // Row 1-4: full width
+            {10, 11, 8}, {11, 11, 8}, {12, 11, 8}, {13, 11, 8}, {14, 11, 8}, {15, 11, 8},
+            {10, 12, 8}, {11, 12, 8}, {12, 12, 8}, {13, 12, 8}, {14, 12, 8}, {15, 12, 8},
+            {10, 13, 8}, {11, 13, 8}, {12, 13, 8}, {13, 13, 8}, {14, 13, 8}, {15, 13, 8},
+            {10, 14, 8}, {11, 14, 8}, {12, 14, 8}, {13, 14, 8}, {14, 14, 8}, {15, 14, 8},
+            // Row 5: cut 0 (full width)
+            {10, 15, 8}, {11, 15, 8}, {12, 15, 8}, {13, 15, 8}, {14, 15, 8}, {15, 15, 8},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrect with radius 2 produces some output") {
+        graphics->cls();
+        graphics->rrect(20, 20, 8, 8, 2, 7);
+
+        // Just check that some pixels are drawn
+        bool hasPixels = false;
+        for (int y = 20; y < 28; y++) {
+            for (int x = 20; x < 28; x++) {
+                if (graphics->pget(x, y) == 7) {
+                    hasPixels = true;
+                    break;
+                }
+            }
+        }
+        CHECK(hasPixels);
+    }
+    SUBCASE("rrectfill with radius 2 draws stepped corners") {
+        graphics->cls();
+        graphics->rrectfill(20, 20, 8, 8, 2, 7);
+
+        std::vector<coloredPoint> expectedPoints = {
+            // Row 0: cut 1 from each side
+            {21, 20, 7}, {22, 20, 7}, {23, 20, 7}, {24, 20, 7}, {25, 20, 7}, {26, 20, 7},
+            // Row 1: cut 0 (full width)
+            {20, 21, 7}, {21, 21, 7}, {22, 21, 7}, {23, 21, 7}, {24, 21, 7}, {25, 21, 7}, {26, 21, 7}, {27, 21, 7},
+            // Middle rows: full width
+            {20, 22, 7}, {21, 22, 7}, {22, 22, 7}, {23, 22, 7}, {24, 22, 7}, {25, 22, 7}, {26, 22, 7}, {27, 22, 7},
+            {20, 23, 7}, {21, 23, 7}, {22, 23, 7}, {23, 23, 7}, {24, 23, 7}, {25, 23, 7}, {26, 23, 7}, {27, 23, 7},
+            {20, 24, 7}, {21, 24, 7}, {22, 24, 7}, {23, 24, 7}, {24, 24, 7}, {25, 24, 7}, {26, 24, 7}, {27, 24, 7},
+            {20, 25, 7}, {21, 25, 7}, {22, 25, 7}, {23, 25, 7}, {24, 25, 7}, {25, 25, 7}, {26, 25, 7}, {27, 25, 7},
+            // Row 6: cut 1 from each side
+            {21, 26, 7}, {22, 26, 7}, {23, 26, 7}, {24, 26, 7}, {25, 26, 7}, {26, 26, 7},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrect with large radius produces output") {
+        graphics->cls();
+        graphics->rrect(10, 10, 16, 16, 6, 12);
+
+        // Just check that some pixels are drawn
+        bool hasPixels = false;
+        for (int y = 10; y < 26; y++) {
+            for (int x = 10; x < 26; x++) {
+                if (graphics->pget(x, y) == 12) {
+                    hasPixels = true;
+                    break;
+                }
+            }
+        }
+        CHECK(hasPixels);
+    }
+    SUBCASE("rrectfill with large radius uses lookup tables") {
+        graphics->cls();
+        graphics->rrectfill(10, 10, 16, 16, 6, 12);
+
+        std::vector<coloredPoint> expectedPoints = {
+            // Test key points based on r=6 pattern: {5,3,2,1,1,0}
+            // Row 0: cut 5 from each side -> width 6
+            {15, 10, 12}, {16, 10, 12}, {17, 10, 12}, {18, 10, 12}, {19, 10, 12}, {20, 10, 12},
+            // Row 1: cut 3 from each side -> width 10
+            {13, 11, 12}, {14, 11, 12}, {15, 11, 12}, {16, 11, 12}, {17, 11, 12},
+            {18, 11, 12}, {19, 11, 12}, {20, 11, 12}, {21, 11, 12}, {22, 11, 12},
+            // Row 5: cut 0 -> full width (16 pixels)
+            {10, 15, 12}, {11, 15, 12}, {12, 15, 12}, {13, 15, 12}, {14, 15, 12}, {15, 15, 12},
+            {16, 15, 12}, {17, 15, 12}, {18, 15, 12}, {19, 15, 12}, {20, 15, 12}, {21, 15, 12},
+            {22, 15, 12}, {23, 15, 12}, {24, 15, 12}, {25, 15, 12},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrect radius clamped to max allowed") {
+        graphics->cls();
+        graphics->rrect(30, 30, 10, 8, 10, 5); // radius 10 should be clamped to 4 (8/2)
+
+        // Should behave like radius 4: pattern {3,2,1,0}
+        std::vector<coloredPoint> expectedPoints = {
+            // Row 0: cut 3 from each side -> start at x=33, end at x=36
+            {33, 30, 5}, {34, 30, 5}, {35, 30, 5}, {36, 30, 5},
+            // Row 1: cut 2 from each side -> start at x=32, end at x=37
+            {32, 31, 5}, {37, 31, 5},
+            // Row 2: cut 1 from each side -> start at x=31, end at x=38
+            {31, 32, 5}, {38, 32, 5},
+            // Row 3: cut 0 -> full width
+            {30, 33, 5}, {39, 33, 5},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrectfill radius clamped to max allowed") {
+        graphics->cls();
+        graphics->rrectfill(30, 30, 10, 8, 10, 5); // radius 10 should be clamped to 4 (8/2)
+
+        // Should behave like radius 4: pattern {3,2,1,0}
+        std::vector<coloredPoint> expectedPoints = {
+            // Row 0: cut 3 from each side -> width 4
+            {33, 30, 5}, {34, 30, 5}, {35, 30, 5}, {36, 30, 5},
+            // Row 1: cut 2 from each side -> width 6
+            {32, 31, 5}, {33, 31, 5}, {34, 31, 5}, {35, 31, 5}, {36, 31, 5}, {37, 31, 5},
+            // Row 3: cut 0 -> full width (10 pixels)
+            {30, 33, 5}, {31, 33, 5}, {32, 33, 5}, {33, 33, 5}, {34, 33, 5},
+            {35, 33, 5}, {36, 33, 5}, {37, 33, 5}, {38, 33, 5}, {39, 33, 5},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+    SUBCASE("rrect basic functionality") {
+        graphics->cls();
+        graphics->rrect(50, 50, 10, 10, 2, 9);
+
+        // Just check that some pixels are drawn
+        bool hasPixels = false;
+        for (int y = 50; y < 60; y++) {
+            for (int x = 50; x < 60; x++) {
+                if (graphics->pget(x, y) == 9) {
+                    hasPixels = true;
+                    break;
+                }
+            }
+        }
+        CHECK(hasPixels);
+    }
+    SUBCASE("rrectfill basic functionality") {
+        graphics->cls();
+        graphics->rrectfill(50, 50, 10, 10, 2, 9);
+
+        // Just check that some pixels are drawn
+        bool hasPixels = false;
+        for (int y = 50; y < 60; y++) {
+            for (int x = 50; x < 60; x++) {
+                if (graphics->pget(x, y) == 9) {
+                    hasPixels = true;
+                    break;
+                }
+            }
+        }
+        CHECK(hasPixels);
+    }
+    SUBCASE("rrect basic clipping test") {
+        graphics->cls();
+        graphics->clip(50, 50, 20, 20); // large clip area
+        graphics->rrect(55, 55, 10, 10, 2, 11);
+
+        // Just check that some pixels are drawn
+        bool hasPixels = false;
+        for (int y = 55; y < 65; y++) {
+            for (int x = 55; x < 65; x++) {
+                if (graphics->pget(x, y) == 11) {
+                    hasPixels = true;
+                    break;
+                }
+            }
+        }
+        CHECK(hasPixels);
+    }
+    SUBCASE("rrectfill respects clipping") {
+        graphics->cls();
+        graphics->clip(12, 12, 4, 4); // clip to small area
+        graphics->rrectfill(10, 10, 8, 8, 1, 11);
+
+        // Only pixels within clip area (12-15, 12-15) should be drawn
+        std::vector<coloredPoint> expectedPoints = {
+            // Check that pixels outside clip are not drawn
+            {10, 10, 0}, {11, 10, 0},
+            {10, 11, 0}, {11, 11, 0},
+            // Check that pixels inside clip are drawn (filled)
+            {12, 12, 11}, {13, 12, 11}, {14, 12, 11}, {15, 12, 11},
+            {12, 13, 11}, {13, 13, 11}, {14, 13, 11}, {15, 13, 11},
+            {12, 14, 11}, {13, 14, 11}, {14, 14, 11}, {15, 14, 11},
+            {12, 15, 11}, {13, 15, 11}, {14, 15, 11}, {15, 15, 11},
+        };
+
+        checkPoints(graphics, expectedPoints);
+    }
+

     //general teardown
     delete graphics;