summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-11-12 10:56:19 +0100
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-11-12 10:56:19 +0100
commit2337214e4e734f7601799aa50b0020c3ff89aede (patch)
treedc0f457ecb9badcf270b7d11d02bf1dad28363d2 /src
parent0d4c8c8534e1e9ad24c29642f763b37e233112fa (diff)
Fix for Windows and X11: Rounding issues with Fl_RGB_Image::draw() (#1120)
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Graphics_Driver.cxx9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx
index 50889bccf..95716530a 100644
--- a/src/Fl_Graphics_Driver.cxx
+++ b/src/Fl_Graphics_Driver.cxx
@@ -759,6 +759,15 @@ void Fl_Scalable_Graphics_Driver::rect(int x, int y, int w, int h)
}
}
+// This function aims to compute accurately int(x * s) in
+// presence of rounding errors existing with floating point numbers
+// and that sometimes differ between 32 and 64 bits.
+int Fl_Scalable_Graphics_Driver::floor(int x, float s) {
+ if (s == 1) return x;
+ int retval = int(abs(x) * s + 0.001f);
+ return (x >= 0 ? retval : -retval);
+}
+
void Fl_Scalable_Graphics_Driver::rectf(int x, int y, int w, int h)
{
if (w <= 0 || h <= 0) return;