Skip to content

Commit

Permalink
[glyphs] Rework corner erasure to delete in-place
Browse files Browse the repository at this point in the history
My initial implementation of corner erasure had a significant problem:
in an attempt to be clever I was not erasing corners as they were found,
but instead collecting 'deletion operations' that could be applied all
at once at the end.

The problem with this, in hindsight, is obvious: In a closed path, it is
possible for a single segment to have an open corner at both ends, and
correctly handling this requires applying the deletion of the first
corner before trying to calculate the position of the second.

This new approach solves this by modifying the path in place, as corners
are found. To do this efficiently it uses a copy-on-write type so that
we only ever allocate if we actually are going to erase a corner, which
is not the common case.

Doing it this was makes the logic tricky, because of how `BezPath` and
`PathEl` work. In particular, the presence of `ClosePath` elements
(which are significant in postscript but are essentially metadata for
our purposes) makes indexing tricky; similarly in a closed path the
first `MoveTo` element is redundant, and we need to account for that as
well.

In hindsight, if I were tasked with writing this again tomorrow, I would
probably not do it this way; instead I would try work with `PathSeg`s, which are
easier to reason about, and I would just figure out some way of writing
it so that we still only allocated as needed.
  • Loading branch information
cmyr committed Jan 15, 2025
1 parent 1476b7c commit 0d8502f
Show file tree
Hide file tree
Showing 2 changed files with 368 additions and 176 deletions.
Loading

0 comments on commit 0d8502f

Please sign in to comment.