mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
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 <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -205,7 +205,7 @@ func (s *Scroll) Scroll(cfg unit.Converter, q event.Queue, t time.Time, axis Axi
|
|||||||
case Vertical:
|
case Vertical:
|
||||||
s.scroll += e.Scroll.Y
|
s.scroll += e.Scroll.Y
|
||||||
}
|
}
|
||||||
iscroll := int(math.Round(float64(s.scroll)))
|
iscroll := int(s.scroll)
|
||||||
s.scroll -= float32(iscroll)
|
s.scroll -= float32(iscroll)
|
||||||
total += iscroll
|
total += iscroll
|
||||||
if !s.dragging || s.pid != e.PointerID {
|
if !s.dragging || s.pid != e.PointerID {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func (f *Animation) Tick(now time.Time) int {
|
|||||||
ekt := float32(math.Exp(float64(k) * t.Seconds()))
|
ekt := float32(math.Exp(float64(k) * t.Seconds()))
|
||||||
x := f.v0*ekt/k - f.v0/k
|
x := f.v0*ekt/k - f.v0/k
|
||||||
dist := x - f.x
|
dist := x - f.x
|
||||||
idist := int(math.Round(float64(dist)))
|
idist := int(dist)
|
||||||
f.x += float32(idist)
|
f.x += float32(idist)
|
||||||
// Solving for the velocity x'(t) gives us
|
// Solving for the velocity x'(t) gives us
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user