Skip to content

Conversation

LaurenzV
Copy link
Contributor

@LaurenzV LaurenzV commented May 7, 2025

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?

@LaurenzV LaurenzV requested a review from tomcur May 7, 2025 16:33
@raphlinus
Copy link
Contributor

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.

@LaurenzV
Copy link
Contributor Author

LaurenzV commented May 7, 2025

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.

@dominikh
Copy link
Contributor

dominikh commented Jun 1, 2025

Would it make sense to use the determinant here? That would consider both the scale's and the skew's effect on the area.

@LaurenzV
Copy link
Contributor Author

LaurenzV commented Jun 3, 2025

Perhaps, not an expert on this though. 😄

Copy link
Member

@tomcur tomcur left a 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);
Copy link
Member

@tomcur tomcur Aug 27, 2025

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?

Suggested change
// 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.

Copy link
Contributor Author

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!

Copy link
Member

@tomcur tomcur left a 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.

@LaurenzV LaurenzV changed the title Remove hack for tolerance of stroke expansion Adapt hack for tolerance of stroke expansion Aug 28, 2025
@LaurenzV LaurenzV added this pull request to the merge queue Aug 28, 2025
Merged via the queue into main with commit 74ff473 Aug 28, 2025
17 checks passed
@LaurenzV LaurenzV deleted the stroke_hack branch August 28, 2025 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants