Chandra-MARX / marx

Chandra X-ray Observatory ray-trace simulator
http://space.mit.edu/cxc/marx/
5 stars 4 forks source link

Fix bug in jdmath binary search algorithm #62

Closed hamogu closed 9 months ago

hamogu commented 9 months ago

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