[Renderers/Tigr] Fixed Asan errors when accessing arc sectors

This commit is contained in:
Noah Breedy 2026-06-22 12:22:57 -04:00
parent 42e7bcb5f1
commit 4b12d41dd2

View file

@ -14,18 +14,18 @@ enum ARC_STATES {
#define R_TO_D 57.29578
/* global memory for our arc renderer */
int arc_sector[8];
int arc_sector[9];
void PositiveSectorPoint(Tigr* ctx, int x, int y, int s, int sp, int ep, TPixel col) {
if (arc_sector[s] == NOT_DRAWN) return;
/* Draw all points of this sector */
if (arc_sector[s] == ALL_DRAWN) {
tigrPlot(ctx, x, y, col);
return;
}
/* draw all points flowing to right */
if (arc_sector[s] == STARTS_HERE) {
if (x >=sp) {
@ -33,7 +33,7 @@ void PositiveSectorPoint(Tigr* ctx, int x, int y, int s, int sp, int ep, TPixel
return;
}
}
/* draw all points flowing from left */
if (arc_sector[s] == ENDS_HERE) {
if (x <= ep) {
@ -41,22 +41,22 @@ void PositiveSectorPoint(Tigr* ctx, int x, int y, int s, int sp, int ep, TPixel
return;
}
}
/* fill only sections of this sector if ((x >= sp) && (x <= ep)) pixel (x, y); */
if (arc_sector[s] == STARTS_ENDS_HERE) {
}
}
}
void NegativeSectorPoint(Tigr* ctx, int x, int y, int s, int sp, int ep, TPixel col) {
if (arc_sector[s] == NOT_DRAWN) return;
/* Draw all points in this sector */
if (arc_sector[s] == ALL_DRAWN) {
tigrPlot(ctx, x, y, col);
return;
}
/* Draw all points flowing to the left */
if (arc_sector[s] == STARTS_HERE) {
if (x <= sp) {
@ -64,11 +64,11 @@ void NegativeSectorPoint(Tigr* ctx, int x, int y, int s, int sp, int ep, TPixel
return;
}
}
/* Draw all points flowing from the right if (x >= ep) {plot(x, y); return; } */
if (arc_sector[s] == ENDS_HERE) {
}
/* fill only sections of this sector */
if (arc_sector[s] == STARTS_ENDS_HERE) {
if ((x >= ep) && (x <= sp)) {
@ -99,7 +99,7 @@ void tigrArc(Tigr* ctx, int xc, int yc, int sa, int ea, int r, TPixel col) {
}else {
/* Set all of the possible drawn sector flags */
for(i = start_sector; i < end_sector; i++) {
arc_sector[i] = ALL_DRAWN;
arc_sector[i] = ALL_DRAWN;
}
arc_sector[start_sector] = STARTS_HERE;
arc_sector[end_sector] = ENDS_HERE;
@ -112,7 +112,7 @@ void tigrArc(Tigr* ctx, int xc, int yc, int sa, int ea, int r, TPixel col) {
sp = ((double)xc + (double)r * cos((double)sa/R_TO_D));
ep = ((double)xc + (double)r * cos((double)ea/R_TO_D));
d = 2 * (1 - r);
while(y > x) {
NegativeSectorPoint(ctx, xc + y, yc + x, 0, sp, ep, col);
NegativeSectorPoint(ctx, xc + x, yc + y, 1, sp, ep, col);
@ -142,18 +142,18 @@ void tigrArcRect(Tigr* ctx, int x, int y, int w, int h, int r, TPixel col) {
tigrArc(ctx, x - r + w, y, 270, 360, r, col); // top right
tigrArc(ctx, x - r + w, y + h, 0, 90, r, col); // bottom right
tigrArc(ctx, x + r, y + h, 90, 180, r, col); // bottom left
/* These are the connecting in lines */
tigrLine(ctx, x + r, y - r, x + w - r, y - r, col); // top
tigrLine(ctx, x + r, y + h + r, x + w - r, y + h + r, col); // bottom
tigrLine(ctx, x, y, x, y + h, col); // left
tigrLine(ctx, x + w, y, x + w, y + h, col); // right
}
/* The reason I dont call the tigrArcRect function is to save on draw calls */
void tigrFillArcRect(Tigr* ctx, int x, int y, int w, int h, int r, TPixel col) {
/* Build the base frame */
tigrFillRect(ctx, x - 1, y, w + 3, h, col);
tigrFillRect(ctx, x + r, y - r - 1, w - (r * 2) , h + (r * 2) + 3, col);
@ -163,13 +163,13 @@ void tigrFillArcRect(Tigr* ctx, int x, int y, int w, int h, int r, TPixel col) {
tigrArc(ctx, x - r + w, y, 270, 360, r, col); // top right
tigrArc(ctx, x - r + w, y + h, 0, 90, r, col); // bottom right
tigrArc(ctx, x + r, y + h, 90, 180, r, col); // bottom left
/* Fill in the gaps */
tigrFillCircle(ctx, x + r, y, r, col); // top left
tigrFillCircle(ctx, x + w - r, y, r, col); // top right
tigrFillCircle(ctx, x + w - r, y + h, r, col); // bottom right
tigrFillCircle(ctx, x + r, y + h, r, col); // bottom left
}