mirror of
https://git.coom.tech/drummyfish/small3dlib.git
synced 2024-11-21 20:39:57 +01:00
Prevent infinite loops
This commit is contained in:
parent
d20eaa1427
commit
469368530b
2 changed files with 17 additions and 14 deletions
29
s3l.h
29
s3l.h
|
@ -199,7 +199,10 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
||||||
v##Inc = v##Dx >= 0 ? 1 : -1;\
|
v##Inc = v##Dx >= 0 ? 1 : -1;\
|
||||||
v##Err = 2 * helperDxAbs - helperDyAbs;\
|
v##Err = 2 * helperDxAbs - helperDyAbs;\
|
||||||
v##ErrAdd = 2 * helperDxAbs;\
|
v##ErrAdd = 2 * helperDxAbs;\
|
||||||
v##ErrSub = 2 * helperDyAbs;
|
v##ErrSub = 2 * (helperDyAbs != 0 ? helperDyAbs : 1);\
|
||||||
|
v##ErrSub = v##ErrSub != 0 ? v##ErrSub : 1; /* don't allow 0, could lead
|
||||||
|
to an infinite substracting
|
||||||
|
loop */
|
||||||
|
|
||||||
#define stepSide(s)\
|
#define stepSide(s)\
|
||||||
while (s##Err > 0)\
|
while (s##Err > 0)\
|
||||||
|
@ -216,6 +219,18 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
||||||
|
|
||||||
while (currentY <= endY)
|
while (currentY <= endY)
|
||||||
{
|
{
|
||||||
|
if (currentY == splitY)
|
||||||
|
{
|
||||||
|
if (splitOnLeft)
|
||||||
|
{
|
||||||
|
initSide(l,l,r);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
initSide(r,r,l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
p.y = currentY;
|
p.y = currentY;
|
||||||
|
|
||||||
// draw the line
|
// draw the line
|
||||||
|
@ -229,18 +244,6 @@ void S3L_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2
|
||||||
stepSide(r)
|
stepSide(r)
|
||||||
stepSide(l)
|
stepSide(l)
|
||||||
|
|
||||||
if (currentY == splitY)
|
|
||||||
{
|
|
||||||
if (splitOnLeft)
|
|
||||||
{
|
|
||||||
initSide(l,l,r);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
initSide(r,r,l);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++currentY;
|
++currentY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ const int16_t test_coords[] =
|
||||||
100,100, 99,101, 101,101, // 0, small triangle
|
100,100, 99,101, 101,101, // 0, small triangle
|
||||||
190,50, 200,10, 400,80, // 1, arbitrary
|
190,50, 200,10, 400,80, // 1, arbitrary
|
||||||
40,80, 20,50, 100,30, // 2, arbitrary
|
40,80, 20,50, 100,30, // 2, arbitrary
|
||||||
300,300, 290,400, 310,400, // 3, regular
|
150,300, 290,400, 450,400, // 3, regular
|
||||||
105,300, 120,300, 201,300, // 4, horizontal line
|
105,300, 120,300, 201,300, // 4, horizontal line
|
||||||
400,300, 400,320, 400,400 // 5, vertical line
|
400,300, 400,320, 400,400 // 5, vertical line
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue