Skip to content

Correct negative half-tie rounding in symmetric shadowcasting - #9

Merged
HexDecimal merged 1 commit into
libtcod:mainfrom
antonsoo:fix/symmetric-shadow-half-ties
Oct 17, 2026
Merged

HexDecimal merged 1 commit into
libtcod:mainfrom
antonsoo:fix/symmetric-shadow-half-ties

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Port the rounding correction from libtcod/libtcod#204, as requested there.

The epsilon-scaled roundf helpers round negative half-ties in the wrong directions. At -0.5, the lower bound should round to 0 and the upper bound to -1; they currently return -1 and 0. Use floorf(n + 0.5f) and ceilf(n - 0.5f), matching the linked symmetric-shadowcasting reference.

A public-API regression checks the complete visibility mask of a small corner layout in all four rotations and both wall-lighting modes. It fails 12 assertions before the correction and passes afterward.

The standalone library was also checked against an independent rational-slope reference on 576 visibility calls using libtcod's sample dungeon, including rotations, radius options and wall modes. This corrects 132 masks and 212 tile decisions, including 40 floor decisions. The 444 already-correct masks and 56 open-room controls across the existing algorithms remain byte-identical.

Validation: CMake shared-library build, the ordinary/symmetric native test selection (6 cases, 465 assertions), and applicable formatting hooks pass on Linux/GCC 13. Tests use Catch2 3.11.0 and GSL 4.0.0; the other platforms and fovtool are not exercised locally. Existing unrelated FOV regression cases are outside this validation. No API, allocation, radius convention or float-to-rational redesign is included.

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@HexDecimal
HexDecimal merged commit 8175fbf into libtcod:main Oct 17, 2026
14 checks passed
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.

2 participants