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

Applying Magnet Alignment Algorithm to newly opened Component Browser #3366

Merged
merged 7 commits into from
Apr 5, 2022

Conversation

vitvakatu
Copy link
Contributor

@vitvakatu vitvakatu commented Mar 29, 2022

Pull Request Description

Task link

This PR enables new node position adjustment using the Magnet Alignment algorithm for the following cases:

  • When creating node with (+) button without nodes selected
  • When creating node with "Mouse pointer dictated placement." not under the source node
  • When the node is pushed left due to lack of space - only horizontally

The size of the alignment area around node is slightly enlarged, so that it's impossible to create a node that is being too close to other nodes.

Videos with AC demonstration:

2022-03-29.11-05-11.mp4
2022-03-29.11-06-40.mp4
2022-03-29.11-09-38.mp4

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the Scala, Java, and Rust style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH ./run dist and ./run watch.

@vitvakatu vitvakatu self-assigned this Mar 29, 2022
@vitvakatu vitvakatu force-pushed the wip/vitvakatu/magnet-algorithm-181076145 branch 2 times, most recently from b2a96c4 to 5f697df Compare March 31, 2022 20:35
@vitvakatu vitvakatu force-pushed the wip/vitvakatu/magnet-algorithm-181076145 branch from 5f697df to fdcaf8e Compare March 31, 2022 20:41
@vitvakatu vitvakatu marked this pull request as ready for review March 31, 2022 20:49
@vitvakatu vitvakatu changed the title [Blocked] Applying Magnet Alignment Algorithm to newly opened Component Browser Applying Magnet Alignment Algorithm to newly opened Component Browser Mar 31, 2022
@@ -29,6 +29,12 @@ pub mod free_place_finder;
/// === New Node Positioning ===
/// ============================

/// The maximum distance to the nearest grid line in Magnet Alignment algorithm.
Copy link
Contributor

Choose a reason for hiding this comment

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

Distance is in pixels, isn't it? Add the info to the docs (or to the constant name, e.g. in suffix _PX)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the distance is in "scene units" (as coordinates). I mentioned it in the docs.

fn magnet_alignment(
graph_editor: &GraphEditorModel,
position: Vector2,
only_horizontally: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing bool as argument, we could make an enum with explanatory names. Then we could have only one public magnet_alginment method instead of three (there will be no need for _x/_xy variants if enum names will be self-explanatory).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

CHANGELOG.md Outdated
Comment on lines 5 to 7
- [Magnet Alignment algorithm is used while placing new nodes][3366]. The new
node position now depends on the positions of the surrounding nodes. This
makes the resulting graph prettier.
Copy link
Member

Choose a reason for hiding this comment

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

This description does not really tell what is happening here. I'd add some info about empty space on the screen and why we do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to express it shortly, so I ask for help if you don't like an updated description.

///
/// This value defines the "sensitivity" of the Magnet Alignment for new nodes - greater values
/// lead to more "aggressive" snapping.
const MAGNET_ALIGNMENT_THRESHOLD: f32 = 150.0;
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the videos I feel that this area is too big now. But to know exactly we need to test it live. Just saying, nothing to be fixed here for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, totally, this requires some additional testing.

Comment on lines 131 to 132
// Perform Magnet Alignment if the node is pushed left to the free space.
if pos.x != align_x {
Copy link
Member

Choose a reason for hiding this comment

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

instead of comments, do variables. was_pushed_left = ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@vitvakatu vitvakatu added the CI: Ready to merge This PR is eligible for automatic merge label Apr 5, 2022
@mergify mergify bot merged commit fb52c1a into develop Apr 5, 2022
@mergify mergify bot deleted the wip/vitvakatu/magnet-algorithm-181076145 branch April 5, 2022 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants