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

Unify the implementation of builder for path and that for stroke and fill #70

Merged
merged 9 commits into from
Sep 28, 2024

Conversation

yutannihilation
Copy link
Owner

@yutannihilation yutannihilation commented Sep 28, 2024

Fix #69

The current implementation flatten curves in a different way for path:

  • In the cases of stroke and fill, flattening is done in tessellator via options provided by lyon (StrokeOptions and FillOptions).
  • In the case of path, path doesn't use tessellator. Instead, it constructs CubicBezierSegment or QuadraticBezierSegment on the fly and flatten it.

It seems the latter way produces different results than the first one (probably the order of scaling operations might matter...?). This pull request changes this by making flattening happen in the Builder. This requires a bit tricky setup.

  • stroke and fill: do not flatten in PathBuilder because the tesselator flattens later
  • path: flatten in PathBuilder

    p <- string2path("s", "Arial", tolerance = 3e-3)
    f <- string2fill("s", "Arial", tolerance = 3e-3)
    
    plot(NULL, xlim = c(0, 0.45), ylim = c(0, 0.45))
    for (tri in split(f, f$triangle_id)) {
      polygon(tri$x, tri$y, col = "#ff3344", border = "transparent")
    }
    lines(p$x, p$y, lwd = 10)

Before:

image

After:

image

@yutannihilation yutannihilation merged commit c8ff63c into main Sep 28, 2024
@yutannihilation yutannihilation deleted the tolerance branch September 28, 2024 06:54
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.

'tolerance' behaves differently in string2path() vs string2fill()
1 participant