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

Taxi edge turn radius (i.e. smooth curve on each turn) #3142

Closed
wants to merge 9 commits into from

Conversation

Adam-Shea
Copy link

@Adam-Shea Adam-Shea commented Jul 24, 2023

Associated issues: This is a follow up to this discussion #3135

Added rounded corners to haystacks when the taxi-curve property is set to yes.
image
Happy to change property name or move elsewhere if you think there is a better format
Thanks :)

Author:

  • The proper base branch has been selected. New features go on unstable. Bug-fix patches can go on either unstable or master.
  • Automated tests have been included in this pull request, if possible, for the new feature(s) or bug fix. Check this box if tests are not pragmatically possible (e.g. rendering features could include screenshots or videos instead of automated tests).
  • The associated GitHub issues are included (above).
  • Notes have been included (above).

Reviewers:

  • All automated checks are passing (green check next to latest commit).
  • At least one reviewer has signed off on the pull request.
  • For bug fixes: Just after this pull request is merged, it should be applied to both the master branch and the unstable branch. Normally, this just requires cherry-picking the corresponding merge commit from master to unstable -- or vice versa.

@maxkfranz maxkfranz self-requested a review July 25, 2023 14:23
Copy link
Member

@maxkfranz maxkfranz left a comment

Choose a reason for hiding this comment

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

This looks like a good start, and I'm sure it would be mergeable with some iteration.

src/style/properties.js Outdated Show resolved Hide resolved
@maxkfranz
Copy link
Member

It would be useful to specify exactly how you propose your feature should be used. Give an example of how the style properties, old and new, should be specified in order to achieve your proposed effect. For instance, it's not clear why this would be coupled to haystack edges.

@hassniazi
Copy link

hassniazi commented Jul 26, 2023

Great feedback, thanks @maxkfranz - we had already begun work to make it a configurable value, will change the property name and provide some documentation on how users could make use it.

@maxkfranz maxkfranz changed the title feature: curved taxi haystack Taxi edge turn radius (i.e. smooth curve on each turn) Jul 27, 2023
@maxkfranz
Copy link
Member

Great. We're planning on releasing 3.26.0 on next week's Friday, the 4th of August. It would be great to have this feature in the release.

Looking forward to your updates.

@hassniazi
Copy link

@maxkfranz - we've made most of the changes now to get this feature in. Just in the process of testing / fixing up, will get the PR updated shortly...

@Adam-Shea
Copy link
Author

Hey, I've updated the pr with the suggestions you made.
Now when supplying taxi-radius, you can set a custom curve for your taxi corners.
I've fix the haystack removal, that was an issue with my merge sorry. Now this sits within haystack as taxi uses it by default. I have tested both with and without taxi-radius and taxi works just fine.
Happy to make anymore suggestions.

Copy link
Member

@maxkfranz maxkfranz left a comment

Choose a reason for hiding this comment

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

Great. Getting close.

for( let i = 2; i + 1 < pts.length; i += 2 ){
context.lineTo( pts[ i ], pts[ i + 1] );
const taxiRadius= edge.pstyle( 'taxi-radius' )
const taxiRadiusValue = taxiRadius ? taxiRadius.value : 0
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const taxiRadiusValue = taxiRadius ? taxiRadius.value : 0
const taxiRadiusValue = taxiRadius ? taxiRadius.pfValue : 0

Copy link
Member

Choose a reason for hiding this comment

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

Preferred value (pfValue, i.e. px), not raw value (value, e.g. 1em has value of 1)

const taxiRadius= edge.pstyle( 'taxi-radius' )
const taxiRadiusValue = taxiRadius ? taxiRadius.value : 0

if( taxiRadiusValue > 0) {
Copy link
Member

@maxkfranz maxkfranz Aug 1, 2023

Choose a reason for hiding this comment

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

This block should only apply to taxi edges, or the property should explicitly support all the affected cases.

Currently, it's breaking other edges. E.g. on the debug page with all edges set with taxi-radius: 32px:


Expected:

Screenshot 2023-08-01 at 08 46 33

Actual:

Screenshot 2023-08-01 at 08 46 18

src/style/properties.js Show resolved Hide resolved
@hassniazi
Copy link

We've pushed up the latest changes @maxkfranz - let us know if you need anything else

@maxkfranz maxkfranz self-requested a review August 3, 2023 18:43
Copy link
Member

@maxkfranz maxkfranz left a comment

Choose a reason for hiding this comment

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

Great. We're making progress. I've attached some comments below:

* This property makes the taxi edge be re-routed when the turns would be otherwise too close to the source or target. As such, it also helps to avoid turns overlapping edge endpoint arrows.
* This property makes the taxi edge be re-routed when the turns would be otherwise too close to the source or target. As such, it also helps to avoid turns overlapping edge endpoint arrows
* **`taxi-radius`** : The taxi-radius property applies a curve to a taxi edge, providing a rounded appearance to any 90 degree bend.
* This value should be a floating point number (e.g. `3.14`).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* This value should be a floating point number (e.g. `3.14`).
* This value should be a floating point length (e.g. `3.14px`).

Copy link
Member

Choose a reason for hiding this comment

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

Just a clarification

){
addEle( edge, sqDist );
return true;
if( rs.edgeType === 'segments' && edge.pstyle( 'taxi-radius' ).value > 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

I understand that this is intended to be a performant simplification, but it doesn't seem to work as intended, e.g. you get clear false positives on the debug page example:

Screen.Recording.2023-08-03.at.14.53.06.mov

The curved taxi edge gets false positives way off the edge. You can compare to other edges, such as the haystacks in the video, to get a sense of how it should feel in proximity.

The corners need to be handled more accurately. For instance, you could

  1. use the centre of the curve's circle to precisely calculate the distance for the corner's hit test (i.e. using the inequality of the squared tap threshold and the squared distance to avoid the performance downside of using square roots); or
  2. make corner checks that mimic the curve with a reasonably-close bezier approximation -- using the existing math.inBezierVicinity() function; or
  3. replace the drawing of the corner of a curved taxi with a quadratic bezier -- and then you can use math.inBezierVicinity() with perfect accuracy (with the downside that it's not really a circle anymore).

If you try (2), temporarily using (3) would help to visualise your approximation even if you don't actually do (3) in the end result.

Copy link
Member

Choose a reason for hiding this comment

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

Also: Hit test code that is curved-taxi-specific should check edge.pstyle( 'curve-style' ).value === 'taxi', just like your drawing code, so that it's explicit and bounded.

* This property makes the taxi edge be re-routed when the turns would be otherwise too close to the source or target. As such, it also helps to avoid turns overlapping edge endpoint arrows
* **`taxi-radius`** : The taxi-radius property applies a curve to a taxi edge, providing a rounded appearance to any 90 degree bend.
* This value should be a floating point number (e.g. `3.14`).

Copy link
Member

Choose a reason for hiding this comment

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

Even if we cap the radius (see the comments later on), it may be useful to have another sub-bullet-point that notes that the radius should not be too large. It depends on how your other taxi properties are specified, the layout, etc.

for( let i = 2; i + 1 < pts.length; i += 2 ){
context.lineTo( pts[ i ], pts[ i + 1] );
const taxiRadius= edge.pstyle( 'taxi-radius' )
const taxiRadiusValue = taxiRadius ? taxiRadius.pfValue : 0
Copy link
Member

Choose a reason for hiding this comment

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

Similar to how border-radius works in ordinary CSS, it would be useful to cap the taxi radius based on the available space. For instance, a div that's a 10px by 10px square can't have a radius greater than 5px effectively.

For the edges, the radius could be capped by the available space on the line.

If you have a larger radius, then the edge will bug out depending on the orientation of the nodes:

Screen.Recording.2023-08-03.at.15.29.33.mov

Copy link
Member

Choose a reason for hiding this comment

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

N.b. this issue also effects smaller radii, but not as obviously.

@maxkfranz
Copy link
Member

@Adam-Shea @hassniazi, let us know if any of the feedback is unclear.

Looking forward to your updates

@Adam-Shea
Copy link
Author

Heya, all clear! Just finding some time to get the last few changes in

@stale
Copy link

stale bot commented Sep 3, 2023

This issue has been automatically marked as stale, because it has not had activity within the past 14 days. It will be closed if no further activity occurs within the next 7 days. If a feature request is important to you, please consider making a pull request. Thank you for your contributions.

@stale stale bot added the stale label Sep 3, 2023
@stale stale bot closed this Sep 10, 2023
@maxkfranz
Copy link
Member

@Adam-Shea, are you still interested in this feature?

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

Successfully merging this pull request may close these issues.

3 participants