added some checks for trapezoid ordering
This commit is contained in:
@@ -205,6 +205,24 @@ namespace UwU {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw a horizontally bounded trapezoid
|
||||||
|
// coords.y1 >= coords.y0
|
||||||
|
void pTrapezoid (Trapezoid coords, Color color) {
|
||||||
|
uint16_t height = 1 + coords.y1 - coords.y0;
|
||||||
|
int16_t LeftBound[height];
|
||||||
|
int16_t RightBound[height];
|
||||||
|
|
||||||
|
this->bresenham(coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound);
|
||||||
|
this->bresenham(coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound);
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i <= height; i++) {
|
||||||
|
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
|
||||||
|
this->putPixel((uint32_t)x, (uint32_t)i + coords.y0, color.r, color.g, color.b, color.a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct waymini* wm;
|
struct waymini* wm;
|
||||||
@@ -325,22 +343,37 @@ namespace UwU {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a horizontally bounded trapezoid
|
// Draws a horizontally bounded trapezoid
|
||||||
// coords.y1 >= coords.y0
|
|
||||||
void trapezoid (Trapezoid coords, Color color) {
|
void trapezoid (Trapezoid coords, Color color) {
|
||||||
uint16_t height = 1 + coords.y1 - coords.y0;
|
UwU::Trapezoid saneCoords = coords;
|
||||||
int16_t LeftBound[height];
|
if (coords.y0 > coords.y1) {
|
||||||
int16_t RightBound[height];
|
saneCoords.y0 = coords.y1;
|
||||||
|
saneCoords.y1 = coords.y0;
|
||||||
this->bresenham(coords.xl0, coords.y1 - coords.y0, coords.xl1, LeftBound);
|
saneCoords.xl0 = coords.xl1;
|
||||||
this->bresenham(coords.xr0, coords.y1 - coords.y0, coords.xr1, RightBound);
|
saneCoords.xl1 = coords.xl0;
|
||||||
|
saneCoords.xr0 = coords.xr1;
|
||||||
for (uint16_t i = 0; i <= height; i++) {
|
saneCoords.xr1 = coords.xr0;
|
||||||
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
|
|
||||||
this->putPixel((uint32_t)x, (uint32_t)i + coords.y0, color.r, color.g, color.b, color.a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
uint16_t tempVal;
|
||||||
|
bool hflip0 = false;
|
||||||
|
if (saneCoords.xl0 > saneCoords.xr0) {
|
||||||
|
tempVal = saneCoords.xl0;
|
||||||
|
saneCoords.xl0 = saneCoords.xr0;
|
||||||
|
saneCoords.xr0 = tempVal;
|
||||||
|
hflip0 = true;
|
||||||
|
}
|
||||||
|
if (saneCoords.xl1 > saneCoords.xr1) {
|
||||||
|
if (!hflip0) {
|
||||||
|
// invalid geometry; emit console warning and don't attempt to draw
|
||||||
|
// possible options are: don't draw, lazy draw (incorrect geometry) -
|
||||||
|
// or split into two (way more work)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tempVal = saneCoords.xl1;
|
||||||
|
saneCoords.xl1 = saneCoords.xr1;
|
||||||
|
saneCoords.xr1 = tempVal;
|
||||||
|
}
|
||||||
|
this->pTrapezoid(saneCoords, color);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -363,7 +396,7 @@ int main(void) {
|
|||||||
draw.rectangle(UwU::Coord2(69, 69), UwU::Coord2(420, 420), fuchsia);
|
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, 360, 600, 401), green);
|
draw.trapezoid(UwU::Trapezoid(500, 400, 360, 360, 600, 401), green);
|
||||||
|
|
||||||
|
|
||||||
draw.point(UwU::Coord2(387, 43), green);
|
draw.point(UwU::Coord2(387, 43), green);
|
||||||
|
|||||||
Reference in New Issue
Block a user