Fix bug in horizontal step histograms (#2830)

This fixes #2830 and adds a test that will catch it if it pops up again. HT to @ycopin for both finding the bug and figuring out the fix; I just implemented it.