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

feat!: added PolylinePattern with support for solid, dotted, dashed styles #1855

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

monsieurtanuki
Copy link
Contributor

Impacted files:

  • pages/polyline.dart: added a dashed polyline as example
  • polyline_layer/polyline.dart: added the dashValues field for Polyline
  • painter.dart: now handling the dashed polylines

Screenshot (new dashed polyline between Paris and Nice):
Screenshot_1710696376

What now?

  • the use of isDotted / segmentSpacingFactor / dashValues fields is a bit clumsy
    => we would be better off with a unique field
    => new class PolylineStyle with "plain", "dotted(space)", "dashed(dashvalues)"?
  • we could reuse for the dotted style the algorithm implemented in the new method getDistanceOffset used for "dashed style" (something like: give me the offset of the point on this [A,B] segment distant from A by n pixels)
  • for the moment the "final point situation" is not dealt with: what if the latest point of the dashed line is invisible? We should explicitly put a dot here, shouldn't we?

monsieurtanuki and others added 3 commits March 17, 2024 18:23
Impacted files:
* `pages/polyline.dart`: added a dashed polyline as example
* `polyline_layer/polyline.dart`: added the `dashValues` field for `Polyline`
* `painter.dart`: now handling the dashed polylines
Deprecated `Polyline.isDotted`
Removed `Polyline.segmentSpacingFactor`
@JaffaKetchup
Copy link
Member

Hey, this looks great! Huge thanks for ticking this off the list.

the use of isDotted / segmentSpacingFactor / dashValues fields is a bit clumsy
=> we would be better off with a unique field
=> new class PolylineStyle with "plain", "dotted(space)", "dashed(dashvalues)"?

Yes, I agree with this. I've added a PolylinePattern object which does this. It's a little bit of complex logic internally, but it keeps the externals small.

we could reuse for the dotted style the algorithm implemented in the new method getDistanceOffset used for "dashed style" (something like: give me the offset of the point on this [A,B] segment distant from A by n pixels)

We generally try to avoid including these generic tools publicly, the major exception being the simplification tools. For now, I'm happy to keep this internal, and we can always make it public in future.

for the moment the "final point situation" is not dealt with: what if the latest point of the dashed line is invisible? We should explicitly put a dot here, shouldn't we?

Yep, we should deal with this. I'm not quite sure the best way to do this, so if you have something in mind, please go ahead!

Copy link
Contributor Author

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

Thank you @JaffaKetchup for your improvements!

lib/src/layer/polyline_layer/polyline.dart Outdated Show resolved Hide resolved
lib/src/layer/polyline_layer/pattern.dart Show resolved Hide resolved
lib/src/layer/polyline_layer/painter.dart Outdated Show resolved Hide resolved
lib/src/layer/polyline_layer/painter.dart Outdated Show resolved Hide resolved
@monsieurtanuki
Copy link
Contributor Author

we could reuse for the dotted style the algorithm implemented in the new method getDistanceOffset used for "dashed style" (something like: give me the offset of the point on this [A,B] segment distant from A by n pixels)

We generally try to avoid including these generic tools publicly, the major exception being the simplification tools. For now, I'm happy to keep this internal, and we can always make it public in future.

Oh it's already an internal method, and the point was to keep it that way.
What bothers me is having two similar algorithms to maintain in the same file.

for the moment the "final point situation" is not dealt with: what if the latest point of the dashed line is invisible? We should explicitly put a dot here, shouldn't we?

Yep, we should deal with this. I'm not quite sure the best way to do this, so if you have something in mind, please go ahead!

The idea would be to say:

  • "is the last point displayed or not?" - and we already know it as _paintDashedLine returns a relevant bool for that
  • if so, display a "dot" on that very point - and it is already somehow implemented in the "dotted" version

Now that I'm thinking, we could also have "smart dashes" polyline pattern, something like:

  • I want a dashed line
  • the input is
    • a double array, like [50, 15, 20, 10]
    • and the number of time the user wants to see this pattern displayed, like 4
  • we compute the total length L of the polyline
  • and we divide the values (50, ...) by a factor so that [50, 15, 20, 10, 50, 15, 20, 10, 50, 15, 20, 10, 50, 15, 20, 10, 50] is displayed completely in the polyline

Copy link
Contributor Author

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

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

@JaffaKetchup Looks good to me!

Still pending: what to do with the last point of a dashed line? I suggest a dot - would you like me to work on it? (I could start only this week-end).

And the "if solid / if dashed / if dotted" sequence is a bit clumsy but it's not very important - except that we have similar algorithms coded twice for dashed and dotted.

Not important suggestion: we could make a dot part of a dashed line, like Morse code (dash-space-dot-space-dash...)

lib/src/layer/polyline_layer/painter.dart Outdated Show resolved Hide resolved
@monsieurtanuki
Copy link
Contributor Author

@JaffaKetchup I've just fixed the side effect problem:

  /// The idea is that we need to be able to display the dash pattern completely
  /// n times (at least once), plus once the initial dash segment. That's the
  /// way we deal with the "ending" side-effect.
[500, 500, 300, 1000] [50, 50, 30, 100] [50, 20, 25, 20]
Screenshot_1711179486 Screenshot_1711179531 Screenshot_1711179596

JaffaKetchup
JaffaKetchup previously approved these changes Mar 24, 2024
Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Not entirely sure what you did in that last bit, but it seems to have worked and looks nice.

Any other maintainers want to have a review?

@JaffaKetchup JaffaKetchup changed the title feat: 1447 - dashed style for polylines feat!: added PolylinePattern with support for solid, dotted, dashed styles Mar 24, 2024
@monsieurtanuki
Copy link
Contributor Author

LGTM, thanks! Not entirely sure what you did in that last bit, but it seems to have worked and looks nice.

@JaffaKetchup As explained, there's a side-effect with dash pattern - as there is obviously with dotted pattern: if the dash pattern is 50+20 pixels, what do we do if the polyline length is 60 pixels? Just display the first 50 pixels and nothing else, so that the last point (presumably very important) is not displayed at all?
The suggestion implemented here is to always display "(dash pattern) * n + first dash segment" where n > 0. So we always display the first point and the last point.

@monsieurtanuki
Copy link
Contributor Author

Still playing with side effects, with dash segments [50, 20, 100, 100]:

don't see the final point (Nice) see Nice as a mere dot used a factor on segment values
Screenshot_1711356063 Screenshot_1711355991 Screenshot_1711356103
  1. if we don't handle side-effects, we may not see the final point
  2. handling the side-effect - display the last point as a dot if needed
  3. handling the side-effect - compute and use a factor so that we display an integer number of times the segments, plus once the first segment, so that the last point is always displayed

Actually I prefer solution 2, because solution 1 is problematic (no final point) and solution 3 is hard to explain anyway.

@JaffaKetchup

  • Would you like me to implement solution 2?
  • Would you like me to implement something similar for dotted style?
  • I think the current PR has been re-labeled as "breaking change" (feat!), which is not really, is it?

@JaffaKetchup
Copy link
Member

JaffaKetchup commented Mar 25, 2024

Hey, thanks for continuing to work on this.

Option one is unnacceptable (I agree), but I feel like option 2 and 3 are both valid. Additionally, rather than option 2, if there are enough dashes, we could do it so that it just dashes as normal, then truncates short the last dash (if it isn't a gap). Not sure how difficult this could be to implement. If you've got time, and it's not too complex, I guess allowing the user to pick between them all with some sort of PatternFit option would be good. But I don't want to exhaust you.

For dotted lines, I guess only option 3 makes sense (scaling the factor), because otherwise it will look a bit strange? Again, PatternFit could work.

The PR is breaking because it removes the isDotted option.

@monsieurtanuki
Copy link
Contributor Author

@JaffaKetchup I've just introduced the new PatternFit field, for both dotted and dashed styles.

x dashed [100, 40] dotted (10)
resize Screenshot_1711463836 Screenshot_1711463724
lastPoint Screenshot_1711463786 Screenshot_1711463714

Improved documentation
@JaffaKetchup
Copy link
Member

@monsieurtanuki I've run with those changes (thanks for those :)) with a couple more options, just so we can give users every option. It doesn't add too much complexity. Let me know what you think!

@monsieurtanuki
Copy link
Contributor Author

@monsieurtanuki I've run with those changes (thanks for those :)) with a couple more options, just so we can give users every option. It doesn't add too much complexity. Let me know what you think!

@JaffaKetchup Thank you for your rewritings! My comments...

I'm not convinced with PatternFit having "forbidden" values, like extendFinalDash not available for dotted polylines. I would have created separate DottedPatternFit and DashedPatternFit enums instead. But that's not very important.

I don't believe your extendFinalDash works - or I haven't understood the goal.
My understanding was that instead of displaying spaces for the very last invisible parts, you were displaying lines. But the way you coded it you display only the very last offset segment: from the latest Offset, but not following the route from the latest lineTo.

  • (--- --- --- ) as none
  • (--- --- -----) as extendFinalDash as I've understood it
  • (--- --- --- -) as extendFinalDash as it's currently coded, potentially

For extendFinalDash, I would expect a final zigzag, not a straight line.

none scale extendFinalDash
Screenshot_1711528964 Screenshot_1711528982 Screenshot_1711528996

Working on it...

@monsieurtanuki
Copy link
Contributor Author

@JaffaKetchup Latest push:

  • PatternFit.none
  • PatternFit.appendDot
  • PatternFit.extendFinalDash
  • PatternFit.scaleUp
  • PatternFit.scaleDown
dotted dashed
Screenshot_1711535174 Screenshot_1711534256

Copy link
Member

@JaffaKetchup JaffaKetchup left a comment

Choose a reason for hiding this comment

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

LGTM! Huge thanks for your efforts :)

I'm not going to wait for another review, I'm pretty confident it's all good.

(Yep, that was a good catch. I hadn't properly considered the extension fit.)

@JaffaKetchup JaffaKetchup merged commit c2806fd into fleaflet:master Mar 27, 2024
7 checks passed
@monsieurtanuki
Copy link
Contributor Author

Thank you @JaffaKetchup for your reviews and comments!
Just an additional comment, as there are breaking changes anyway: perhaps the "spacing" parameter of "dotted" could be a size in pixels rather than a factor to apply on top of paint size.

@JaffaKetchup JaffaKetchup linked an issue Mar 27, 2024 that may be closed by this pull request
3 tasks
@josxha josxha added this to the v7.0 milestone Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[FEATURE] Support dashed Polylines (in addition to dotted)
3 participants