Consider valid candidates with overlap #28
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Motivation and Context
Here, going right from 1 would originally not go anywhere, as the target edge of 2 & 3 (their left edge) is left of the exit edge (right edge of 1).
![image](https://private-user-images.githubusercontent.com/7268569/261030156-340289b9-231a-4885-8b18-d0e17d9bfcff.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3NzAwMjksIm5iZiI6MTcxODc2OTcyOSwicGF0aCI6Ii83MjY4NTY5LzI2MTAzMDE1Ni0zNDAyODliOS0yMzFhLTQ4ODUtOGIxOC1kMGUxN2Q5YmZjZmYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTlUMDQwMjA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmI2ODk4M2UzMzhhYjliYWQ1ODYwYzkyZTU0NTU5MzE0MmYzNjQ2MjI1NGRkNDFkY2Q5Y2U3OGZhYzQzNTc0ZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.-q1UoAq_Er2kk17rJh31LyZhH-qRSEUAo7t6e4n882s)
However sometimes we want to be able to consider items that are 'right-ish' from the current focus, even if they are also offset in a different direction. So even though 3 is below 1 and therefore a valid 'down' candidate, it is offset enough to be the right that it should be a 'right' candidate too.
With this change, the target edge is effectively moved by a small amount, allowing for the actual edge of the candidate to overlap the current focus. Here the new lines represent the adjusted edges of each container. 3's adjusted edge is now to the right of 1's right edge, so it's considered a valid 'right' candidate from 1.
![image](https://private-user-images.githubusercontent.com/7268569/261034954-775b56bc-6391-4672-899f-2f6480349490.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3NzAwMjksIm5iZiI6MTcxODc2OTcyOSwicGF0aCI6Ii83MjY4NTY5LzI2MTAzNDk1NC03NzViNTZiYy02MzkxLTQ2NzItODk5Zi0yZjY0ODAzNDk0OTAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTlUMDQwMjA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDA0MGQ1Yjk5MDQzYTA0MzNhY2QxMThlZjIxYjUwOTg0YTM3NTZiYmJhMjc2ZjVkYjRlMDMxZWUyNGU3MTY1OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.twZVf9P7dQnRgz5w1OY_XNviGRx9N9D8yqHxOPRyTXg)
By default, the edge is moved by 30% of the element's width/height - effectively allowing for up to 30% of the candidate to overlap with the current focus.
The
data-lrud-overlap-threshold
attribute allows for tweaking that threshold on a per-element basis. It takes a float from 0.0 to 1.0, representing the percentage of the element that can overlap and still be a valid candidate. The default overlap is 0.3, 30%.Here item 3's allowed overlap is
![image](https://private-user-images.githubusercontent.com/7268569/261033713-e691cc50-9853-4e98-9ebd-96873fbc9d16.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3NzAwMjksIm5iZiI6MTcxODc2OTcyOSwicGF0aCI6Ii83MjY4NTY5LzI2MTAzMzcxMy1lNjkxY2M1MC05ODUzLTRlOTgtOWViZC05Njg3M2ZiYzlkMTYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MTlUMDQwMjA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDFmNTRiNjVmNmJkMzYxZjc4MTVhMGI1YjAzZjc0ZTA4YWY5MDAxMDgyOTM4MTA0ZTM2ZWEzYTNiNGZmNWY2NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.I74adA7wZg6GbakZfKn0hMPwzNFp4cOLX58v1R8dLGE)
0.1
(10% of its width), so it is no longer valid. A value of 0 would return to the original behaviour and only consider candidates that don't overlap at all as valid.How Has This Been Tested?
New integration tests.
Checklist: