Open the context
Choose the project folder and name the files or behavior involved.
Calculate a half-open visible-row range from fixed row height, scroll offset and viewport height. Test negative scroll, overscroll and a zero-height viewport, clipping indices to the item count and rejecting an invalid row height.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
from math import isfinite, ceil
def row_window(count, row_height, offset, viewport, overscan=1):
if type(count) is not int or count < 0 or type(overscan) is not int or overscan < 0:
raise ValueError("rows.count")
if not all(type(x) in (int, float) and isfinite(x) for x in (row_height, offset, viewport)) or row_height <= 0 or viewport < 0:
raise ValueError("rows.geometry")
start_units = max(0, offset) / row_height
first = count if start_units >= count else int(start_units)
if first == count or viewport == 0:
return first, first
span = viewport / row_height
end = count if span >= count - start_units else min(count, ceil(start_units + span) + overscan)
return max(0, first - overscan), endThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.