Compare commits

..

2 Commits

Author SHA1 Message Date
Annika 1d27f6e5d1 fixed issue with vertex sorting leading to segfault 2026-07-05 21:05:15 -07:00
Annika c8db7a8933 added helper function to git 2026-07-05 20:56:28 -07:00
2 changed files with 15 additions and 5 deletions
BIN
View File
Binary file not shown.
+15 -5
View File
@@ -263,7 +263,7 @@ namespace UwU {
Coord2 mid = Coord2();
Coord2 btm = Coord2();
// cases: flat top, flat bottom, left point, right point
if (coords.y0 < coords.y1 && coords.y0 < coords.y2) {
if (coords.y0 <= coords.y1 && coords.y0 <= coords.y2) {
top.x = coords.x0;
top.y = coords.y0;
if (coords.y1 < coords.y2) {
@@ -277,7 +277,7 @@ namespace UwU {
btm.x = coords.x1;
btm.y = coords.y1;
}
} else if (coords.y1 < coords.y0 && coords.y1 < coords.y2) {
} else if (coords.y1 <= coords.y0 && coords.y1 <= coords.y2) {
top.x = coords.x1;
top.y = coords.y1;
if (coords.y0 < coords.y2) {
@@ -306,17 +306,24 @@ namespace UwU {
btm.y = coords.y0;
}
}
printf("top: (%u, %u)\n", top.x, top.y);
printf("mid: (%u, %u)\n", mid.x, mid.y);
printf("btm: (%u, %u)\n", btm.x, btm.y);
uint16_t height = 1 + btm.y - top.y;
int16_t longBound[height];
int16_t splitBound[height];
// int16_t rightBound[height];
Helpers::bresenham(0, top.x, height - 1, btm.x, longBound);
printf("longBound\n");
if ((int16_t)mid.x < longBound[mid.y - top.y]) {
// left-handed triangle
printf("left-handed\n");
// rightBound = longBound;
Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound);
printf("splitTop\n");
Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound);
printf("splitBtm\n");
for (uint32_t i = 0; i < height; i++) {
for (uint32_t x = (uint32_t)splitBound[i]; x <= (uint32_t)longBound[i]; x++) {
putPixel(x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a);
@@ -324,9 +331,12 @@ namespace UwU {
}
} else {
// right-handed triangle
printf("right-handed\n");
// leftBound = longBound;
Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound);
printf("splitTop\n");
Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound);
printf("splitBtm\n");
for (uint32_t i = 0; i < height; i++) {
for (uint32_t x = (uint32_t)longBound[i]; x <= (uint32_t)splitBound[i]; x++) {
putPixel(x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a);
@@ -399,10 +409,10 @@ int main(void) {
draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia);
draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
// draw.rectangleGradient(UwU::Coord2(200, 200), UwU::Coord2(600, 400), red, blue, alpha, red);
draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 400), green);
draw.triangle(UwU::Triangle(200, 100, 240, 100, 320, 300), green);
// draw.trapezoid(UwU::Trapezoid(300, 400, 360, 380, 600, 400), green);
draw.triangle(UwU::Triangle(280, 100, 240, 100, 320, 300), green);
draw.point(UwU::Coord2(387, 43), green);