mirror of
https://github.com/GayPizzaSpecifications/padlab.git
synced 2025-08-03 21:21:33 +00:00
offset circle & arc lines by half a pixel to improve alignment
This commit is contained in:
14
src/draw.c
14
src/draw.c
@ -59,6 +59,9 @@ void DrawLine(int x1, int y1, int x2, int y2)
|
|||||||
|
|
||||||
void DrawCircleSteps(int x, int y, int r, int steps)
|
void DrawCircleSteps(int x, int y, int r, int steps)
|
||||||
{
|
{
|
||||||
|
const float fx = (float)x - 0.5f;
|
||||||
|
const float fy = (float)y - 0.5f;
|
||||||
|
|
||||||
const float stepsz = (float)TAU / steps;
|
const float stepsz = (float)TAU / steps;
|
||||||
const float mag = (float)r;
|
const float mag = (float)r;
|
||||||
float lastx = mag;
|
float lastx = mag;
|
||||||
@ -69,8 +72,8 @@ void DrawCircleSteps(int x, int y, int r, int steps)
|
|||||||
float ofsy = sinf(stepsz * i) * mag;
|
float ofsy = sinf(stepsz * i) * mag;
|
||||||
|
|
||||||
SDL_RenderLine(rend,
|
SDL_RenderLine(rend,
|
||||||
x + lastx, y + lasty,
|
fx + lastx, fy + lasty,
|
||||||
x + ofsx, y + ofsy);
|
fx + ofsx, fy + ofsy);
|
||||||
|
|
||||||
lastx = ofsx;
|
lastx = ofsx;
|
||||||
lasty = ofsy;
|
lasty = ofsy;
|
||||||
@ -79,6 +82,9 @@ void DrawCircleSteps(int x, int y, int r, int steps)
|
|||||||
|
|
||||||
void DrawArcSteps(int x, int y, int r, int startAng, int endAng, int steps)
|
void DrawArcSteps(int x, int y, int r, int startAng, int endAng, int steps)
|
||||||
{
|
{
|
||||||
|
const float fx = (float)x - 0.5f;
|
||||||
|
const float fy = (float)y - 0.5f;
|
||||||
|
|
||||||
const float fstart = (float)startAng * (float)DEG2RAD;
|
const float fstart = (float)startAng * (float)DEG2RAD;
|
||||||
const float fstepSz = (float)(endAng - startAng) / abs(steps) * (float)DEG2RAD;
|
const float fstepSz = (float)(endAng - startAng) / abs(steps) * (float)DEG2RAD;
|
||||||
const float mag = (float)r;
|
const float mag = (float)r;
|
||||||
@ -92,8 +98,8 @@ void DrawArcSteps(int x, int y, int r, int startAng, int endAng, int steps)
|
|||||||
float ofsy = -sinf(theta) * mag;
|
float ofsy = -sinf(theta) * mag;
|
||||||
|
|
||||||
SDL_RenderLine(rend,
|
SDL_RenderLine(rend,
|
||||||
x + lastx, y + lasty,
|
fx + lastx, fy + lasty,
|
||||||
x + ofsx, y + ofsy);
|
fx + ofsx, fy + ofsy);
|
||||||
|
|
||||||
lastx = ofsx;
|
lastx = ofsx;
|
||||||
lasty = ofsy;
|
lasty = ofsy;
|
||||||
|
Reference in New Issue
Block a user