summaryrefslogtreecommitdiffstats
path: root/generic/tkScale.c
diff options
context:
space:
mode:
authorfvogel <fvogelnew1@free.fr>2019-01-13 14:35:13 (GMT)
committerfvogel <fvogelnew1@free.fr>2019-01-13 14:35:13 (GMT)
commitcff021b2dc7bf601b37714ae36bfa4fd510dbd1d (patch)
treeed33358062af1e6de083eb539d2fea6497324236 /generic/tkScale.c
parent3866cadb1cfcaf4145fed26ace23efb3a0d16254 (diff)
downloadtk-cff021b2dc7bf601b37714ae36bfa4fd510dbd1d.zip
tk-cff021b2dc7bf601b37714ae36bfa4fd510dbd1d.tar.gz
tk-cff021b2dc7bf601b37714ae36bfa4fd510dbd1d.tar.bz2
Fix [3003895fff] and [1899040fff] with a different fix, this time it does not resurrect [220665ffff] or duplicates [220265ffff] [779559ffff]. All scale.test tests do pass now.
Diffstat (limited to 'generic/tkScale.c')
-rw-r--r--generic/tkScale.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/generic/tkScale.c b/generic/tkScale.c
index 547f698..979d39d 100644
--- a/generic/tkScale.c
+++ b/generic/tkScale.c
@@ -1142,17 +1142,8 @@ TkRoundValueToResolution(
TkScale *scalePtr, /* Information about scale widget. */
double value) /* Value to round. */
{
- double rem, start;
-
- if (scalePtr->resolution <= 0) {
- return value;
- }
- start = fmod(scalePtr->fromValue, scalePtr->resolution);
- rem = fmod(value - start + scalePtr->resolution/2, scalePtr->resolution);
- if (rem < 0) {
- rem += scalePtr->resolution;
- }
- return value + scalePtr->resolution/2 - rem;
+ return TkRoundIntervalToResolution(scalePtr, value - scalePtr->fromValue)
+ + scalePtr->fromValue;
}
double
@@ -1160,16 +1151,24 @@ TkRoundIntervalToResolution(
TkScale *scalePtr, /* Information about scale widget. */
double value) /* Value to round. */
{
- double rem;
+ double rem, rounded, tick;
if (scalePtr->resolution <= 0) {
return value;
}
- rem = fmod(value + scalePtr->resolution/2, scalePtr->resolution);
+ tick = floor(value/scalePtr->resolution);
+ rounded = scalePtr->resolution * tick;
+ rem = value - rounded;
if (rem < 0) {
- rem += scalePtr->resolution;
+ if (rem <= -scalePtr->resolution/2) {
+ rounded = (tick - 1.0) * scalePtr->resolution;
+ }
+ } else {
+ if (rem >= scalePtr->resolution/2) {
+ rounded = (tick + 1.0) * scalePtr->resolution;
+ }
}
- return value + scalePtr->resolution/2 - rem;
+ return rounded;
}
/*