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

Fixed binary search end case bug and added more complete tests #35

Merged
merged 1 commit into from
Dec 20, 2016

Conversation

kronick
Copy link
Contributor

@kronick kronick commented Dec 20, 2016

There was a bug in my binary search code that would cause off-by-one errors on odd indices for interpolated values. I confirmed that was an issue in isolation, and I believe it is the cause of the bug being observed here: mapbox/mapbox-gl-js#3838

This PR should fix that bug by having a correct end search case for this flavor of binary search, where we want to return the lower index if a value is interpolated (not just exact matches).

This wasn't caught with our old tests because we only were using one, two, or three stops. I added a more complete test case with 13 not-evenly-spaced stops based on real user data from the issue above.

cc/ @lucaswoj @mourner
fixes mapbox/mapbox-gl-js#3838

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

Copy link

@lucaswoj lucaswoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix & thorough tests @kronick 😄

if (currentValue === input) {
currentIndex += 1;
break;
upperValue = stops[currentIndex + 1][0];
Copy link

@vdumont vdumont Mar 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: you might want to handle the case where n==1 in this function since this new line would be problematic with n==1. (ie: don't rely on the caller doing the n==1 check)

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.

fill-extrusion-color data-driven styling error in v0.29
4 participants