Skip to content

test: pin how fractional positions and sizes are drawn and hit-tested - #62

Merged
dmccoystephenson merged 2 commits into
mainfrom
test/pin-fractional-coordinates
Oct 31, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
test/pin-fractional-coordinates

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Stage B (unit-test expansion) cycle. How the draw methods handle fractional (float) positions and sizes had no tests and no documentation. Consumers lay out grids from divisions such as displayWidth / columns, so float arguments are common.

  • drawRectangle, drawButton, drawImage: each of xpos, ypos, width and height is pinned as truncated toward zero on its own. It is not rounded, and the far edge is not computed from the unrounded xpos + width. A box at 10.7 with width 5.9 covers pixels 10..14. A size below one pixel draws nothing.
  • drawText: a fractional center is accepted. A fractional size raises TypeError from pygame.font.Font, and that is now pinned and stated in the docstring.
  • drawButton hit test: the hit test compares the mouse against the unrounded floats, so with fractional arguments the clickable region can drift up to a pixel from the painted box on each edge. This contradicts the documented "clickable region is exactly the drawn box". It is characterized by a test and documented as an integer-only guarantee. The production code is unchanged, and the possible fix is filed as drawButton: with fractional arguments the clickable region drifts up to a pixel from the drawn box #61 for a maintainer decision.

The graphik.py edit is docstring-only. Behavior (including truncation of negative fractions toward zero) was verified on pygame 2.1.2 and 2.6.1 before it was written down.

Test plan

  • python3 -m py_compile src/main/python/preponderous/graphik/graphik.py
  • python3 -m pytest (headless via conftest.py): 130 passed, 19 of them new. Run locally on Python 3.8.10 with pygame 2.1.2.
  • Same behavior confirmed with a standalone probe against pygame 2.6.1.
  • CI 3.9-3.13 green.

Backlog skip reasons

No tracking issue — gap found during triage. #60 was closed this cycle, because the fix landed in #59 and main's 3.9 job is green again. The remaining open issues are human-gated:

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

dmccoystephenson and others added 2 commits October 30, 2026 22:42
Floats are truncated toward zero per argument by drawRectangle,
drawButton and drawImage; drawText accepts a fractional center but
rejects a fractional size. drawButton's hit test uses the unrounded
values, so its clickable region can drift from the drawn box by up to a
pixel per edge -- characterized here and documented, not changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The class docstring said fractional sizes are accepted, contradicting
drawText's int-only font size. Also rename two parametrize ids that
described each tuple as wholly above/below half when it mixes both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (performed inline; no independent reviewer is available, and Copilot could not be added as a reviewer):

  • Scope: PASS — three files: the new tests, the README paragraph describing the pinned behavior, and docstring-only edits in graphik.py. No executable line of graphik.py changed.
  • Tests-new: PASS (n/a) — no new public method was added.
  • Tests-fix: PASS (n/a, characterization) — no fix is made. Sensitivity was checked empirically instead: the hit test was temporarily rewritten to int() its four bounds, and 4 of the 5 test_draw_button_with_fractional_bounds_hit_tests_the_unrounded_box cases failed. With the original restored, all 130 passed.
  • Sibling structure: PASS — the new helpers and parametrized tests follow the _draw_*_sized / _paint_on_fresh_display pattern directly above them.
  • Sibling renames: PASS (n/a) — nothing was renamed in the library.
  • Docs: FAIL → fixed — the class docstring first said "fractional positions and sizes are accepted", which contradicted drawText's int-only size. Fixed in the follow-up commit. README and the drawText/drawButton docstrings now agree with the tests.
  • Issue resolution: PASS (n/a) — no Closes. The drawButton behavior gap is filed as drawButton: with fractional arguments the clickable region drifts up to a pixel from the drawn box #61 rather than fixed here.
  • Manual validation: PASS — py_compile OK; pytest 130 passed locally (pygame 2.1.2) and on CI for 3.9-3.13 (pygame 2.6.1).
  • camelCase: PASS (n/a) — no new public method.
  • Backward-compat: PASS — no public member's signature or behavior changed.
  • Headless: PASS — the new tests use the conftest.py dummy drivers like their siblings.
  • Version sync: PASS (n/a) — no version string touched.
  • No new deps: PASS — no imports added.

Notes:

  • src/test/python/preponderous/graphik/test_graphik.py (parametrize ids) — the ids fractions_above_half/fractions_below_half were misleading because each tuple mixes both. They were renamed to x_axis_above_half_y_axis_below / x_axis_below_half_y_axis_above.
  • test_draw_text_accepts_a_fractional_center asserts only that ink is painted, not where. The exact pixel the Rect.center setter lands a fractional center on was not verified, so it is deliberately not pinned.

This review comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit a7b4837 into main Oct 31, 2026
5 checks passed
@dmccoystephenson
dmccoystephenson deleted the test/pin-fractional-coordinates branch October 31, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant