-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e05ebcb
commit 340ad25
Showing
5 changed files
with
90 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#import "/src/styles.typ" | ||
#import "/src/path-util.typ" | ||
#import "/src/bezier.typ" as bezier_ | ||
|
||
#let linearize-default-style = (linearize: ( | ||
samples: 3, | ||
)) | ||
|
||
/// Path modifier that linearizes bezier segments | ||
/// by sampling n points along the curve. | ||
#let linearize(ctx, style, segments) = { | ||
let style = styles.resolve(ctx.style, merge: style, | ||
base: linearize-default-style).linearize | ||
let samples = calc.max(2, int(style.samples)) | ||
|
||
let new = () | ||
for s in segments { | ||
let kind = s.first() | ||
if kind == "cubic" { | ||
let pts = s.slice(1) | ||
new.push(path-util.line-segment(range(0, samples).map(i => { | ||
let t = calc.min(1, 1 / (samples - 1) * i) | ||
bezier_.cubic-point(..pts, t) | ||
}))) | ||
} else { | ||
new.push(s) | ||
} | ||
} | ||
return new | ||
} |
This file contains 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