-
Notifications
You must be signed in to change notification settings - Fork 143
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
Port recent GPU stroke expansion changes in flatten
to CPU version
#415
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e79c48
[encoding] Add a f16_to_f32 utility
armansito 1e30be1
[cpu_shaders][flatten] Incorporate stroke expansion changes
armansito 48521ba
[cpu_shaders][flatten] cargo fmt & clippy warnings
armansito 3b952c0
[encoding][math] Add more tests for f16 conversion
armansito 097006d
fix clippy lints
armansito fe75059
Address review comments; fix arc flattening logic
armansito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,12 @@ fn write_line( | |
bbox: &mut IntBbox, | ||
lines: &mut [LineSoup], | ||
) { | ||
assert!( | ||
!p0.is_nan() && !p1.is_nan(), | ||
"wrote line segment with NaN: p0: {:?}, p1: {:?}", | ||
p0, | ||
p1 | ||
); | ||
bbox.add_pt(p0); | ||
bbox.add_pt(p1); | ||
lines[line_ix] = LineSoup { | ||
|
@@ -322,22 +328,19 @@ fn flatten_arc( | |
lines: &mut [LineSoup], | ||
bbox: &mut IntBbox, | ||
) { | ||
const MIN_THETA: f32 = 0.0001; | ||
|
||
let mut p0 = transform.apply(begin); | ||
let mut r = begin - center; | ||
let tol: f32 = 0.5; | ||
let tol: f32 = 0.1; | ||
let radius = tol.max((p0 - transform.apply(center)).length()); | ||
let x = 1. - tol / radius; | ||
let theta = (2. * x * x - 1.).clamp(-1., 1.).acos(); | ||
const MAX_LINES: u32 = 1000; | ||
let n_lines = if theta <= ROBUST_EPSILON { | ||
MAX_LINES | ||
} else { | ||
MAX_LINES.min((std::f32::consts::TAU / theta).ceil() as u32) | ||
}; | ||
let theta = (2. * (1. - tol / radius).acos()).max(MIN_THETA); | ||
|
||
// Always output at least one line so that we always draw the chord. | ||
let n_lines = ((angle / theta).ceil() as u32).max(1); | ||
|
||
let th = angle / (n_lines as f32); | ||
let c = th.cos(); | ||
let s = th.sin(); | ||
let c = theta.cos(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can write |
||
let s = theta.sin(); | ||
let rot = Transform([c, -s, s, c, 0., 0.]); | ||
|
||
for _ in 0..(n_lines - 1) { | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can say
{p0:?}
here, as of Rust 1.58.