Skip to content

Commit

Permalink
[flatten] Fix infinite arc subdivision case
Browse files Browse the repository at this point in the history
If the segment angle falls below epsilon, return MAX_LINES instead
of 1u for the line segment count. Total number of lines per arc is now
capped at 1000.
  • Loading branch information
armansito committed Nov 17, 2023
1 parent 4be1799 commit 8dc91f5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion shader/flatten.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ fn flatten_arc(
let radius = max(tol, length(p0 - transform_apply(transform, center)));
let x = 1. - tol / radius;
let theta = acos(clamp(2. * x * x - 1., -1., 1.));
let n_lines = select(u32(ceil(6.2831853 / theta)), 1u, theta <= EPS);
let MAX_LINES = 1000u;
let n_lines = select(min(MAX_LINES, u32(ceil(6.2831853 / theta))), MAX_LINES, theta <= EPS);

let th = angle / f32(n_lines);
let c = cos(th);
Expand Down

0 comments on commit 8dc91f5

Please sign in to comment.