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

Wrong decision on distance measurement SpatialNavigation.ts : getSecondaryAxisDistance() #134

Closed
a-roz opened this issue Jun 4, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@a-roz
Copy link

a-roz commented Jun 4, 2024

SpatialNavigation.ts

has getSecondaryAxisDistance() , which has logically incorrect behavior when measure distance between Ref an Sibling
it's done by measure on all corners and leads to wrong choose in case of elements of a VARIOUS WIDTH / HEIGHT

To correct this, have to use CENTER coordinate between corners and measure the distance between them

so instead of

    const distancesToCompare = [];

    distancesToCompare.push(Math.abs(siblingCoordinateA - refCoordinateA));
    distancesToCompare.push(Math.abs(siblingCoordinateA - refCoordinateB));
    distancesToCompare.push(Math.abs(siblingCoordinateB - refCoordinateA));
    distancesToCompare.push(Math.abs(siblingCoordinateB - refCoordinateB));

    return Math.min(...distancesToCompare);

simply to put

    const refCoordinateCenter = (refCoordinateA + refCoordinateB) / 2;
    const siblingCoordinateCenter = (siblingCoordinateA + siblingCoordinateB) / 2;
    return Math.abs(refCoordinateCenter - siblingCoordinateCenter)

and it works perfect

@a-roz
Copy link
Author

a-roz commented Jun 4, 2024

demo at https://github.com/a-roz/Norigin-Spatial-Navigation

@predikament predikament self-assigned this Jul 11, 2024
@predikament predikament added the enhancement New feature or request label Jul 11, 2024
@predikament
Copy link
Collaborator

@a-roz: Hello!

You're quite right, the current comparison can be somewhat incorrect due to the way it compares using the corners.

We're discussing making it possible to define this in some way, for example by making it possible to overwrite this distance comparison function, so that you can define the origins you want to compare yourself.

The current approach is more performant for uniformly sized elements, so I think having some option for some customization would be good here, for those who could benefit from it.

Thanks for the feedback. We'll get back to this topic over the summer.

@Braggiouy
Copy link
Contributor

Update: The PR with the changes has been successfully merged. I'll now proceed to close the related issue. 🎉

Thank you for your valuable feedback, @a-roz!

You can view the PR here: PR #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants