-
Notifications
You must be signed in to change notification settings - Fork 180
Adapt hack for tolerance of stroke expansion #977
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
Conversation
Cubic-to-cubic stroke expansion is still technically dependent on the scale factor, but the sensitivity is greatly less than when lowering to lines. Thus, it should be possible to retain stroke-expanded paths over a fairly wide range of scale factors. I don't have my head completely around whether it's a good idea to merge this. |
The main reason I wanted to remove it is because it's causing trouble with transforms where the scaling factor is close to 0 and the skewing factor is instead pretty large. But maybe we need to come up with a more principled approach here. |
Would it make sense to use the determinant here? That would consider both the scale's and the skew's effect on the area. |
Perhaps, not an expert on this though. 😄 |
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.
I've opened #1180 for consideration, though the current PR can absolutely land if it solves some immediate problems.
Would it make sense to use the determinant here? That would consider both the scale's and the skew's effect on the area.
I believe as a conservative metric we could use the Frobenius norm, ignoring translation, as sqrt(a^2 + b^2 + c^2 + d^2)
.
let tolerance = TOL / affine.as_coeffs()[0].abs().max(affine.as_coeffs()[3].abs()); | ||
|
||
let expanded = kurbo::stroke(path.iter(), style, &StrokeOpts::default(), tolerance); | ||
let expanded = kurbo::stroke(path.iter(), style, &StrokeOpts::default(), TOL); |
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.
The main reason I wanted to remove it is because it's causing trouble with transforms where the scaling factor is close to 0 and the skewing factor is instead pretty large. But maybe we need to come up with a more principled approach here.
@LaurenzV Would the issues still be fixed calculating the following?
// TODO: Temporary hack to ensure that strokes are scaled properly by the transform. | |
let tolerance = TOL / affine.as_coeffs()[0].abs().max(affine.as_coeffs()[3].abs()); | |
let expanded = kurbo::stroke(path.iter(), style, &StrokeOpts::default(), tolerance); | |
let expanded = kurbo::stroke(path.iter(), style, &StrokeOpts::default(), TOL); | |
let tolerance = TOL / affine.as_coeffs()[0].abs().max(affine.as_coeffs()[3].abs()).max(1.); | |
let expanded = kurbo::stroke(path.iter(), style, &StrokeOpts::default(), tolerance); |
This doubles down on the current hack, ensuring the tolerance is always at most TOL
, only allowing to become less tolerant for scaled-up geometry.
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.
As far as I can tell that does seem to work as well, so will adopt, thanks!
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.
As discussed in the renderer office hours just now, we're happy for this to land (also as-is), and revisit with something more principled.
This was needed in the initial prototype for
vello_cpu
where we were using the stroke expansion implementation of the GPU stroke expansion paper, which approximates the stroke by line segments. We had to adjust the tolerance here, because if you draw a small stroke which is then scaled up, you can very clearly notice the line approximation.However, the current (and future) kurbo stroke do cubic-to-cubic stroke expansion, so I don't think this should be necessary here?