Skip to content
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

[encoding] Inflate estimates for offset curves #522

Merged
merged 3 commits into from
Mar 16, 2024
Merged

Conversation

armansito
Copy link
Collaborator

Added a highly crude scale to segment and line counts in the presence of a non-zero offset (i.e. stroked curves). This is done to account for the inflated flattening of an offset curve around high-curvature zones. I believe this could get refined but that requires some work to find the best way to analyze the complexity of the curve with few CPU cycles.

Fixed a bug in join calculation that was wrongfully incrementing the line count instead of segments.

This makes the estimate robust for tricky strokes but also increases the margin of the estimate over the true bump counts. I expect some of this will improve when the estimation moves to resolve time, such that the crude bloating of the counts due to any scale applied to a scene fragment will no longer be necessary.

Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. I agree we can take another pass to refine the math later, but if this does a good job estimating the current state, it's a good advance.

const MIN_THETA: f32 = 1e-4;
const TOL: f32 = 0.1;
const MIN_THETA: f32 = 1e-6;
const TOL: f32 = 0.25;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. We may want to make this a tunable parameter, perhaps at runtime, though I think the constant value is good enough for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A config uniform for tolerances might be a good idea. It may also make sense to have a common set of constant declarations that are shared by cpu_shaders and the estimate code (though they live in different crates).

@@ -288,22 +293,22 @@ fn transform_scale(t: Option<&Transform>) -> f32 {
}
}

fn approx_arc_length_cubic(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2) -> f64 {
fn approx_arc_length_cubic(p0: Vec2, p1: Vec2, p2: Vec2, p3: Vec2) -> f32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut feeling would be to keep these f64 to emphasize that they're CPU-side computations and to have as much accuracy as possible, but I don't think it makes a difference in practice. The later ones where we defer quantization are a good idea for sure though.

@armansito armansito deleted the branch main March 15, 2024 22:18
@armansito armansito closed this Mar 15, 2024
@armansito armansito reopened this Mar 15, 2024
@armansito armansito changed the base branch from bump-estimate-segments to main March 15, 2024 22:32
- Added a highly crude scale to segment and line counts in the presence
  of a non-zero offset (i.e. stroked curves). This is done to account
  for the inflated flattening of an offset curve around high-curvature
  zones. I believe this could get refined but that requires some work
  to find the best way to analyze the complexity of the curve with few
  CPU cycles.

- Fixed a bug in join calculation that was wrongfully incrementing the
  line count instead of segments.

This makes the estimate robust for tricky strokes but also increases
the margin of the estimate over the true bump counts. I expect some of
this will improve when the estimation moves to resolve time, such that
the crude bloating of the counts due to any scale applied to a scene
fragment will no longer be necessary.
@armansito armansito force-pushed the bump-estimate-offset branch from 79382b4 to ea47eae Compare March 15, 2024 22:33
@armansito armansito enabled auto-merge March 16, 2024 05:15
@armansito armansito added this pull request to the merge queue Mar 16, 2024
Merged via the queue into main with commit b8b0e29 Mar 16, 2024
11 checks passed
@armansito armansito deleted the bump-estimate-offset branch March 16, 2024 21:08
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.

2 participants