aboutsummaryrefslogtreecommitdiff
path: root/drawing.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-02-18 18:52:21 +0000
committerBen Harris <bjh21@bjh21.me.uk>2023-02-19 12:41:13 +0000
commite8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6 (patch)
tree325d20828f8389a2c5f287f56b5e8082b4d0c2a3 /drawing.c
parent26c7f3aa285a45176c940afebe3885ad2be2ed65 (diff)
downloadpuzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.zip
puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.tar.gz
puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.tar.bz2
puzzles-e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6.tar.xz
Convert a lot of floating-point constants to single precision
For reasons now lost to history, Puzzles generally uses single-precision floating point. However, C floating-point constants are by default double-precision, and if they're then operated on along with a single-precision variable the value of the variable gets promoted to double precision, then the operation gets done, and then often the result gets converted back to single precision again. This is obviously silly, so I've used Clang's "-Wdouble-promotion" to find instances of this and mark the constants as single-precision as well. This is a bit awkward for PI, which ends up with a cast. Maybe there should be a PIF, or maybe PI should just be single-precision. This doesn't eliminate all warnings from -Wdouble-promotion. Some of the others might merit fixing but adding explicit casts to double just to shut the compiler up would be going too far, I feel.
Diffstat (limited to 'drawing.c')
-rw-r--r--drawing.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drawing.c b/drawing.c
index 3584936..5fb8a31 100644
--- a/drawing.c
+++ b/drawing.c
@@ -90,8 +90,8 @@ void draw_line(drawing *dr, int x1, int y1, int x2, int y2, int colour)
void draw_thick_line(drawing *dr, float thickness,
float x1, float y1, float x2, float y2, int colour)
{
- if (thickness < 1.0)
- thickness = 1.0;
+ if (thickness < 1.0F)
+ thickness = 1.0F;
if (dr->api->draw_thick_line) {
dr->api->draw_thick_line(dr->handle, thickness,
x1, y1, x2, y2, colour);
@@ -101,8 +101,8 @@ void draw_thick_line(drawing *dr, float thickness,
* polygon rendering uses integer coordinates.
*/
float len = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
- float tvhatx = (x2 - x1)/len * (thickness/2 - 0.2);
- float tvhaty = (y2 - y1)/len * (thickness/2 - 0.2);
+ float tvhatx = (x2 - x1)/len * (thickness/2 - 0.2F);
+ float tvhaty = (y2 - y1)/len * (thickness/2 - 0.2F);
int p[8];
p[0] = x1 - tvhaty;