0 up): negative = toward the top. */ public function steps(float $wheel): int { if ($wheel == 0.0 || !is_finite($wheel)) { return 0; } if ($this->acc * $wheel < 0) { $this->acc = 0.0; } $this->acc += $wheel; $n = (int) ($this->acc > 0 ? floor($this->acc + 1e-9) : ceil($this->acc - 1e-9)); $this->acc -= $n; return -$n; } public function reset(): void { $this->acc = 0.0; } /** A first row clamped to [0, rows - visible]. */ public static function clamp(int $top, int $rows, int $visible): int { return max(0, min($top, max(0, $rows - $visible))); } }