added some checks for trapezoid ordering
This commit is contained in:
@@ -205,6 +205,24 @@ namespace UwU {
|
||||
}
|
||||
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:
|
||||
struct waymini* wm;
|
||||
@@ -325,22 +343,37 @@ namespace UwU {
|
||||
}
|
||||
}
|
||||
|
||||
// Draw a horizontally bounded trapezoid
|
||||
// coords.y1 >= coords.y0
|
||||
// Draws a horizontally bounded trapezoid
|
||||
void trapezoid (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);
|
||||
}
|
||||
UwU::Trapezoid saneCoords = coords;
|
||||
if (coords.y0 > coords.y1) {
|
||||
saneCoords.y0 = coords.y1;
|
||||
saneCoords.y1 = coords.y0;
|
||||
saneCoords.xl0 = coords.xl1;
|
||||
saneCoords.xl1 = coords.xl0;
|
||||
saneCoords.xr0 = coords.xr1;
|
||||
saneCoords.xr1 = coords.xr0;
|
||||
}
|
||||
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.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);
|
||||
|
||||
Reference in New Issue
Block a user