Skip to content

fix: use tangents for smooth stroke composition#1775

Open
Kneemund wants to merge 2 commits into
flxzt:mainfrom
Kneemund:fix/stroke-composition
Open

fix: use tangents for smooth stroke composition#1775
Kneemund wants to merge 2 commits into
flxzt:mainfrom
Kneemund:fix/stroke-composition

Conversation

@Kneemund

@Kneemund Kneemund commented May 18, 2026

Copy link
Copy Markdown
Collaborator
  • Because of how stroke composition works so far, line segments with highly varying widths had noticeable "dents" in them.
  • This was often hidden fairly well by the large amount of path elements, but it becomes much more noticeable with feat: brush stroke simplification #1769.
Before After
grafik grafik
grafik grafik

Details

  • So far, line segments are constructed as trapezoids with semicircular caps:
    • The trapezoids are constructed to be exactly perpendicular to the stroke segment.
    • They are only continuous with the line caps if both ends have the same width.
  • This PR changes the approach, and it can be interpreted in the following way:
    • A circle with the start width is placed at the start of the line segment.
    • That circle is continuously deformed until it reaches the end width at the end of the line segment.
    • This makes the stroke continuous even at different widths. It is achieved by calculating the direction that is tangential to both circles, and connecting the circles along that direction.

Debug View Examples

grafik grafik

(The bottom image shows the degenerate case where one circle is contained in the other. It falls back to the previous behavior.)

///
/// The arc is centered at `center` and connects `start` to `end`.
/// Between the two possible sweeps, the arc whose midpoint direction best aligns with `direction` is selected.
fn append_arc_between_points(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have a feeling that we could simplify the "direction selection" somehow...

@Doublonmousse

Copy link
Copy Markdown
Collaborator

I wonder if we have a systematic pen up event with 0 pressure giving 0 width at the end here from gtk... Maybe we don't want to have this at the end of each stroke ?

@Kneemund

Copy link
Copy Markdown
Collaborator Author

Maybe... But this is a more general issue, it's just that rapid pressure changes most likely occur at the end of strokes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants