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

Make selection rectangle correspond to zoom window when respecting ratio #1033

Merged
merged 3 commits into from
Mar 28, 2022

Conversation

loichuder
Copy link
Member

@loichuder loichuder commented Mar 25, 2022

Fix #1025

I also put the ratio-respecting SelectionRect in its own component. This is a separate commit if you want to read the algorithmic changes first.

As discussed, I could not reuse directly the code in moveCameraTo as it relies on the camera FOV which does not change when drawing rectangles. Instead, I made new utilities to clamp a rectangle in an area.

Given a starting and an end point of a rectangle, the utility will compute the new center of the rectangle so that the rectangle with its actual height/width stays inside the area (the vis in our case). For the selection rectangle, I then compute the shift between the new center and the old one and apply it to the starting and end point. As this is a simple shift, it conserves the ratio of the rectangle.

I could refactor the code in moveCameraTo to make use of the new utilities but I wasn't sure it was worth it.

@loichuder loichuder requested a review from axelboc March 25, 2022 14:46
Copy link
Contributor

@axelboc axelboc left a comment

Choose a reason for hiding this comment

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

Nicely done 👏

@loichuder loichuder force-pushed the bound-select-zoom-vis branch from ebfd83f to a974765 Compare March 28, 2022 07:14
@loichuder
Copy link
Member Author

/approve

clamp(y, -yBound, yBound),
position.z
const clampedPosition = clampRectangleToArea(
new Vector2(x, y),
Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! I think this even opens the door, in a future PR, to let moveCameraTo and clampRectangleToArea accept Vector2 | Vector3.

Only minor thing that bugs me is the naming of clampRectangleToArea, which doesn't fit the return type (Vector2). Perhaps clampPositionToArea would make more sense?

@loichuder loichuder force-pushed the bound-select-zoom-vis branch from 96eb58b to fab64ac Compare March 28, 2022 07:48
@loichuder loichuder force-pushed the bound-select-zoom-vis branch from fab64ac to f1bd0d0 Compare March 28, 2022 07:56
@loichuder loichuder merged commit fed567f into main Mar 28, 2022
@loichuder loichuder deleted the bound-select-zoom-vis branch March 28, 2022 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants