Implement path clipping with exact Bézier curves - #1131
Open
hooyuser wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on top of the path boolean work from #1091 and is the next step toward addressing #618.
It adds a new
clipfunction to clip path drawables against a closed clipping region:Depending on
mode("inside"or"outside"), it keeps only the geometry inside or outside theclipping-region. Thebodyparameter takes the objects you want to clip, and each path drawable inside it is clipped independently againstclipping-region. Note that unlike paths inclipping-region, paths inbodymay contain both open and closed subpaths.Take
mode: "inside"as an example. Under the hood, thestrokeandfillof each path drawable inbodyare handled separately:strokeis notnone: subpaths (open or closed) are trimmed to keep only the portions inside the clipping region.fillis notnone:body-fill-rule. A boolean intersection between that area and theclipping-regionproduces a newly generated, fill-only path.mode: "outside"follows the same split: it retains the outside portions of stroked paths and uses a boolean difference for filled areas.To avoid repeating logic from #1091, I also reorganized the relevant Typst and Rust code into shared Typst/Rust modules. This is purely an internal cleanup and doesn't change the behavior of the existing
booleanfunction.Example: string diagram of snake equation
Someone on Discord asked how to draw a string diagram and came up with a solution using boolean operations (discussion link). With
clip, we now have a more straightforward way to achieve this kind of effect.