Skip to content

Commit 4a42bc9

Browse files
committed
Hopefully fixed double-float problems
1 parent 0417771 commit 4a42bc9

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src_c/draw.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,55 +2528,55 @@ draw_circle_xaolinwu(SDL_Surface *surf, int x0, int y0, int radius,
25282528
for (int radius_ = radius - thickness; radius_ <= radius; radius_++) {
25292529
int x = 0;
25302530
int y = radius_;
2531-
float prev_opacity = 0;
2531+
double prev_opacity = 0;
25322532
if (radius_ == radius - thickness) {
25332533
while (x < y) {
2534-
float height = sqrt(pow(radius_, 2) - pow(x, 2));
2535-
float opacity = 255 * (ceil(height) - height);
2534+
double height = sqrt(pow(radius_, 2) - pow(x, 2));
2535+
double opacity = 255 * (ceil(height) - height);
25362536
if (opacity < prev_opacity) {
25372537
--y;
25382538
}
25392539
prev_opacity = opacity;
2540-
draw_eight_symetric_pixels(surf, x0, y0, color, x, y, 255,
2540+
draw_eight_symetric_pixels(surf, x0, y0, color, x, y, 255.0f,
25412541
top_right, top_left, bottom_left,
25422542
bottom_right, drawn_area);
25432543
draw_eight_symetric_pixels(
2544-
surf, x0, y0, color, x, y - 1, opacity, top_right,
2544+
surf, x0, y0, color, x, y - 1, (float)opacity, top_right,
25452545
top_left, bottom_left, bottom_right, drawn_area);
25462546
++x;
25472547
}
25482548
}
25492549
else if (radius_ == radius) {
25502550
while (x < y) {
2551-
float height = sqrt(pow(radius_, 2) - pow(x, 2));
2552-
float opacity = 255 * (ceil(height) - height);
2551+
double height = sqrt(pow(radius_, 2) - pow(x, 2));
2552+
double opacity = 255 * (ceil(height) - height);
25532553
if (opacity < prev_opacity) {
25542554
--y;
25552555
}
25562556
prev_opacity = opacity;
25572557
draw_eight_symetric_pixels(
2558-
surf, x0, y0, color, x, y, 255 - opacity, top_right,
2558+
surf, x0, y0, color, x, y, 255 - (float)opacity, top_right,
25592559
top_left, bottom_left, bottom_right, drawn_area);
2560-
draw_eight_symetric_pixels(surf, x0, y0, color, x, y - 1, 255,
2561-
top_right, top_left, bottom_left,
2562-
bottom_right, drawn_area);
2560+
draw_eight_symetric_pixels(
2561+
surf, x0, y0, color, x, y - 1, 255.0f, top_right, top_left,
2562+
bottom_left, bottom_right, drawn_area);
25632563
++x;
25642564
}
25652565
}
25662566
else {
25672567
while (x < y) {
2568-
float height = sqrt(pow(radius_, 2) - pow(x, 2));
2569-
float opacity = 255 * (ceil(height) - height);
2568+
double height = sqrt(pow(radius_, 2) - pow(x, 2));
2569+
double opacity = 255 * (ceil(height) - height);
25702570
if (opacity < prev_opacity) {
25712571
--y;
25722572
}
25732573
prev_opacity = opacity;
2574-
draw_eight_symetric_pixels(surf, x0, y0, color, x, y, 255,
2575-
top_right, top_left, bottom_left,
2576-
bottom_right, drawn_area);
2577-
draw_eight_symetric_pixels(surf, x0, y0, color, x, y - 1, 255,
2574+
draw_eight_symetric_pixels(surf, x0, y0, color, x, y, 255.0f,
25782575
top_right, top_left, bottom_left,
25792576
bottom_right, drawn_area);
2577+
draw_eight_symetric_pixels(
2578+
surf, x0, y0, color, x, y - 1, 255.0f, top_right, top_left,
2579+
bottom_left, bottom_right, drawn_area);
25802580
++x;
25812581
}
25822582
}
@@ -2590,20 +2590,20 @@ draw_circle_xaolinwu_thin(SDL_Surface *surf, int x0, int y0, int radius,
25902590
{
25912591
int x = 0;
25922592
int y = radius;
2593-
float prev_opacity = 0;
2593+
double prev_opacity = 0;
25942594
while (x < y) {
2595-
float height = sqrt(pow(radius, 2) - pow(x, 2));
2596-
float opacity = 255 * (ceil(height) - height);
2595+
double height = sqrt(pow(radius, 2) - pow(x, 2));
2596+
double opacity = 255 * (ceil(height) - height);
25972597
if (opacity < prev_opacity) {
25982598
--y;
25992599
}
26002600
prev_opacity = opacity;
2601-
draw_eight_symetric_pixels(surf, x0, y0, color, x, y, 255 - opacity,
2602-
top_right, top_left, bottom_left,
2603-
bottom_right, drawn_area);
2604-
draw_eight_symetric_pixels(surf, x0, y0, color, x, y - 1, opacity,
2605-
top_right, top_left, bottom_left,
2606-
bottom_right, drawn_area);
2601+
draw_eight_symetric_pixels(surf, x0, y0, color, x, y,
2602+
255 - (float)opacity, top_right, top_left,
2603+
bottom_left, bottom_right, drawn_area);
2604+
draw_eight_symetric_pixels(surf, x0, y0, color, x, y - 1,
2605+
(float)opacity, top_right, top_left,
2606+
bottom_left, bottom_right, drawn_area);
26072607
++x;
26082608
}
26092609
}

0 commit comments

Comments
 (0)