Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[glyphs] Rework corner erasure to delete in-place
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