-
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
Fix error in clip reduction #659
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ export_scenes!( | |
brush_transform(brush_transform: animated), | ||
blend_grid(blend_grid), | ||
deep_blend(deep_blend), | ||
many_clips(many_clips), | ||
conflation_artifacts(conflation_artifacts), | ||
labyrinth(labyrinth), | ||
robust_paths(robust_paths), | ||
|
@@ -82,7 +83,11 @@ export_scenes!( | |
/// Implementations for the test scenes. | ||
/// In a module because the exported [`ExampleScene`](crate::ExampleScene) creation functions use the same names. | ||
mod impls { | ||
use std::f64::consts::PI; | ||
|
||
use crate::SceneParams; | ||
use rand::Rng; | ||
use rand::{rngs::StdRng, SeedableRng}; | ||
use vello::kurbo::{ | ||
Affine, BezPath, Cap, Circle, Ellipse, Join, PathEl, Point, Rect, Shape, Stroke, Vec2, | ||
}; | ||
|
@@ -1094,6 +1099,32 @@ mod impls { | |
} | ||
} | ||
|
||
pub(super) fn many_clips(scene: &mut Scene, params: &mut SceneParams) { | ||
params.resolution = Some(Vec2::new(1000., 1000.)); | ||
let mut rng = StdRng::seed_from_u64(42); | ||
let mut base_tri = BezPath::new(); | ||
base_tri.move_to((-50.0, 0.0)); | ||
base_tri.line_to((25.0, -43.3)); | ||
base_tri.line_to((25.0, 43.3)); | ||
for y in 0..10 { | ||
for x in 0..10 { | ||
let translate = | ||
Affine::translate((100. * (x as f64 + 0.5), 100. * (y as f64 + 0.5))); | ||
const CLIPS_PER_FILL: usize = 3; | ||
for _ in 0..CLIPS_PER_FILL { | ||
let rot = Affine::rotate(rng.gen_range(0.0..PI)); | ||
scene.push_layer(Mix::Clip, 1.0, translate * rot, &base_tri); | ||
} | ||
let rot = Affine::rotate(rng.gen_range(0.0..PI)); | ||
let color = Color::rgb(rng.gen(), rng.gen(), rng.gen()); | ||
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. This produces remarkably pleasing colours considering that it's completely random - it's probably a good technique to use in other examples. |
||
scene.fill(Fill::NonZero, translate * rot, color, None, &base_tri); | ||
for _ in 0..CLIPS_PER_FILL { | ||
scene.pop_layer(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Support functions | ||
|
||
pub(super) fn render_cardioid(scene: &mut Scene) { | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
I believe that the root path is rotationally symmetric every$$\frac{2\pi}{3}$$ radians, but this is doing a rotation every $$\pi$$ radians.
I think that means there's a bias towards the range which is equivalent to$$[0, \frac{\pi}{3})$$ .
Practically, I don't think this matters here, but I'm wondering if this is an intentional choice.
(And of course, my maths understanding could be very wrong :P)
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.
Heh, you're right, there is a bias. Not thinking it through carefully, I assumed the symmetry would make it still uniform, and I wanted to make the code concise. I think I'll leave it, in the sprit of kintsugi.
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.
We could use$$\tau$$ (
TAU
) here to still be fairly concise.But practically, this is great, and the bias isn't an issue!