From b39e4227c227b1081be21b841464ce47f7b83ad8 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 20 Nov 2019 18:30:01 +0100 Subject: [PATCH] gesture,internal/fling: fix rounding The code tried to extract a rounded whole number of pixels while preserving the fraction. However, it failed to converge for the value 0.5, rounded to 1, leaving -0.5, rounded to -1, leaving 0.5 and so on. Drop the cleverness and truncate the values instead. Signed-off-by: Elias Naur --- gesture/gesture.go | 2 +- internal/fling/animation.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gesture/gesture.go b/gesture/gesture.go index 2714890a..4d3b5bc5 100644 --- a/gesture/gesture.go +++ b/gesture/gesture.go @@ -205,7 +205,7 @@ func (s *Scroll) Scroll(cfg unit.Converter, q event.Queue, t time.Time, axis Axi case Vertical: s.scroll += e.Scroll.Y } - iscroll := int(math.Round(float64(s.scroll))) + iscroll := int(s.scroll) s.scroll -= float32(iscroll) total += iscroll if !s.dragging || s.pid != e.PointerID { diff --git a/internal/fling/animation.go b/internal/fling/animation.go index 66dfb880..4a644890 100644 --- a/internal/fling/animation.go +++ b/internal/fling/animation.go @@ -85,7 +85,7 @@ func (f *Animation) Tick(now time.Time) int { ekt := float32(math.Exp(float64(k) * t.Seconds())) x := f.v0*ekt/k - f.v0/k dist := x - f.x - idist := int(math.Round(float64(dist))) + idist := int(dist) f.x += float32(idist) // Solving for the velocity x'(t) gives us //