Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in jdmath binary search algorithm #62

Merged
merged 2 commits into from
Nov 19, 2023

Conversation

hamogu
Copy link
Member

@hamogu hamogu commented Nov 19, 2023

Once an interval was narrowed down to just two elements, the binary search algorithm always returned the lower of the two. That's not correct.

This bug was found by simulations of a one-pixel source that happens to be off by one pixel. If, in that example, the source would have been located at +1 or -1 pixel compared to the test that was run, this bug would have gone unnoticed.

Changes in "s-image.c" are mostly cosmetic to make it easier to reason why the formula works,
by removing the double negative. I think there was als oa 0.5 pixel offset before, but since it's hard to reason about, I opted for simplifying and making sure it's correct by testing a simulation.

fixes #50
closes #54

Once an interval was narrowed down to just two elements, the binary search algorithm always returned the lower of the two. That's not correct.

This bug was found by simulations of a one-pixel source that happens to be off by one pixel. If, in that example, the source would have been located at +1 or -1 pixel compared to the test that was run, this bug would have gone unnoticed.

Changes in "s-image.c" are mostly cosmetic to make it easier to reason why the formula works,
by removing the double negative. I *think* there was als oa 0.5 pixel offset before, but since it's hard to reason about, I opted for simplifying and making sure it's correct by testing a simulation.

fixes Chandra-MARX#50
closes Chandra-MARX#54
@hamogu hamogu merged commit 6e8cfdb into Chandra-MARX:main Nov 19, 2023
1 check passed
@hamogu hamogu deleted the fix_50_moritz branch November 19, 2023 13:17
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.

Are images sources off by one?
1 participant