Now conforms with style conventions
Also reworded a comment to sound more... fomal.
This commit is contained in:
parent
83d0974525
commit
aa9a59bd6d
|
|
@ -2416,19 +2416,19 @@ void ImageDrawPixelV(Image *dst, Vector2 position, Color color)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw line within an image
|
// Draw line within an image
|
||||||
void ImageDrawLine (Image *dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color){
|
void ImageDrawLine(Image *dst, int startPosX, int startPosY, int endPosX, int endPosY, Color color)
|
||||||
|
{
|
||||||
// Using Bresenham's algorithm as described in
|
// Using Bresenham's algorithm as described in
|
||||||
// Drawing Lines with Pixels - Joshua Scott - March 2012
|
// Drawing Lines with Pixels - Joshua Scott - March 2012
|
||||||
// https://classic.csunplugged.org/wp-content/uploads/2014/12/Lines.pdf
|
// https://classic.csunplugged.org/wp-content/uploads/2014/12/Lines.pdf
|
||||||
|
|
||||||
int changeInX = (endPosX - startPosX);
|
int changeInX = (endPosX - startPosX);
|
||||||
int abs_changeInX = changeInX < 0 ? -changeInX : changeInX;
|
int abs_changeInX = (changeInX < 0)? -changeInX : changeInX;
|
||||||
int changeInY = (endPosY - startPosY);
|
int changeInY = (endPosY - startPosY);
|
||||||
int abs_changeInY = changeInY < 0 ? -changeInY : changeInY;
|
int abs_changeInY = (changeInY < 0)? -changeInY : changeInY;
|
||||||
|
|
||||||
int startU, startV, endU, V_step; // Substitutions, either U = X, V = Y or vice versa. See loop at end of function
|
int startU, startV, endU, V_step; // Substitutions, either U = X, V = Y or vice versa. See loop at end of function
|
||||||
//int endV; // We never need this, i didn't just forget about it! :D
|
//int endV; // This is not needed, but to aid understanding it is left in the code below.
|
||||||
// For understanding I left it in below, too.
|
|
||||||
|
|
||||||
int A, B, P; // See linked paper above. Explained down in the main loop.
|
int A, B, P; // See linked paper above. Explained down in the main loop.
|
||||||
|
|
||||||
|
|
@ -2459,7 +2459,7 @@ void ImageDrawLine (Image *dst, int startPosX, int startPosY, int endPosX, int e
|
||||||
changeInY = -changeInY;
|
changeInY = -changeInY;
|
||||||
}
|
}
|
||||||
|
|
||||||
V_step = changeInY < 0 ? -1 : 1;
|
V_step = (changeInY < 0)? -1 : 1;
|
||||||
|
|
||||||
ImageDrawPixel(dst, startU, startV, color); // At this point they are correctly ordered...
|
ImageDrawPixel(dst, startU, startV, color); // At this point they are correctly ordered...
|
||||||
}
|
}
|
||||||
|
|
@ -2488,7 +2488,7 @@ void ImageDrawLine (Image *dst, int startPosX, int startPosY, int endPosX, int e
|
||||||
changeInY = -changeInY;
|
changeInY = -changeInY;
|
||||||
}
|
}
|
||||||
|
|
||||||
V_step = changeInX < 0 ? -1 : 1;
|
V_step = (changeInX < 0)? -1 : 1;
|
||||||
|
|
||||||
ImageDrawPixel(dst, startV, startU, color); // ... but need to be reversed here. Repeated in the main loop below.
|
ImageDrawPixel(dst, startV, startU, color); // ... but need to be reversed here. Repeated in the main loop below.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user