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

Add winding validation for sketches #2256

Merged
merged 3 commits into from
Mar 13, 2024
Merged

Conversation

emka
Copy link
Contributor

@emka emka commented Mar 10, 2024

Tests use circles, arcs currently can not be tested (#2130). Adding sketch validation for #2158.

@emka emka requested a review from hannobraun as a code owner March 10, 2024 11:31
@emka emka changed the title Add winding validation for sketches (#2158) Add winding validation for sketches Mar 10, 2024
@emka
Copy link
Contributor Author

emka commented Mar 10, 2024

Test cases should_find_cycle_multiple_references and should_find_half_edge_multiple_references are currently failing because they contain cycles without valid winding. Do you have a preference how to handle this case?

Copy link
Owner

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Thank you, @emka, great work!

I left some comments with suggestions. But to be clear, none of those need to be addressed. Feel free to look into them, if you're up for it. But I'm happy to leave this as-is, as the code can always be cleaned up later, when making changes to it.

What needs to be addressed is the CI failure.

Test cases should_find_cycle_multiple_references and should_find_half_edge_multiple_references are currently failing because they contain cycles without valid winding. Do you have a preference how to handle this case?

My preferred approach to these tests is to build a valid object using high-level builder APIs, then create an invalid variant by doing a minimal update of the valid object. Just like I've suggested for the tests you added.

I'm not too picky, however. Looks like the failing tests can be fixed by just replacing Cycle::new with Cycle::circle, so feel free to just do that!

crates/fj-core/src/validate/sketch.rs Outdated Show resolved Hide resolved
crates/fj-core/src/validate/sketch.rs Outdated Show resolved Hide resolved
crates/fj-core/src/validate/sketch.rs Outdated Show resolved Hide resolved
Comment on lines 180 to 192
let valid_outer_circle =
HalfEdge::circle([0., 0.], 1., &mut core).insert(&mut core);
let valid_exterior =
Cycle::new(vec![valid_outer_circle.clone()]).insert(&mut core);
let valid_sketch =
Sketch::new(vec![
Region::new(valid_exterior.clone(), vec![]).insert(&mut core)
]);
Copy link
Owner

Choose a reason for hiding this comment

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

This can be shortened using BuildRegion, specifically, BuildRegion::circle.

There's also BuildSketch, but that's quite rudimentary. Would be nice to have some more methods there too, for cases like this, but that's not within the scope of this pull request.

Comment on lines +190 to +205
let invalid_outer_circle = HalfEdge::from_sibling(
&valid_outer_circle,
Vertex::new().insert(&mut core),
)
.insert(&mut core);
let invalid_exterior =
Cycle::new(vec![invalid_outer_circle.clone()]).insert(&mut core);
let invalid_sketch =
Sketch::new(vec![
Region::new(invalid_exterior.clone(), vec![]).insert(&mut core)
]);
Copy link
Owner

Choose a reason for hiding this comment

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

This can probably be shortened by updating the valid sketch. Something like this:

let invalid_sketch = valid_sketch.update_region(valid_sketch.regions().first(), |region|
    region.update_exterior(|cycle| cycle.reverse())
);

I didn't test this, so this might not work precisely like this. But something along those lines should be possible.

Comment on lines +215 to +237
let outer_circle =
HalfEdge::circle([0., 0.], 2., &mut core).insert(&mut core);
let inner_circle =
HalfEdge::circle([0., 0.], 1., &mut core).insert(&mut core);
let cw_inner_circle = HalfEdge::from_sibling(
&inner_circle,
Vertex::new().insert(&mut core),
)
.insert(&mut core);
let exterior = Cycle::new(vec![outer_circle.clone()]).insert(&mut core);

let valid_interior =
Cycle::new(vec![cw_inner_circle.clone()]).insert(&mut core);
let valid_sketch = Sketch::new(vec![Region::new(
exterior.clone(),
vec![valid_interior],
)
.insert(&mut core)]);
Copy link
Owner

Choose a reason for hiding this comment

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

Can probably be shortened by using available APIs. Maybe (attention, pseudo-code) Region::circle().add_interior(invalid_circle).

Comment on lines +235 to +246
let invalid_interior =
Cycle::new(vec![inner_circle.clone()]).insert(&mut core);
let invalid_sketch = Sketch::new(vec![Region::new(
exterior.clone(),
vec![invalid_interior],
)
.insert(&mut core)]);
Copy link
Owner

Choose a reason for hiding this comment

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

Can probably be shortened using Sketch::update_region and other operations, as suggested above in the other test.

@emka
Copy link
Contributor Author

emka commented Mar 11, 2024

Thank you for the feedback! I want to take care of the unresolved comments as well before merging.

@hannobraun
Copy link
Owner

Great, thank you! Let me know when this is ready for another look.

One additional note: It would be great, if the commits with changes to the existing tests came before the commit with new validation check, to make sure every single commit builds/tests correctly (this can be very useful when using git bisect). (In case you're not familiar, git rebase -i is probably the best tool to achieve this. If you're having problems, let me know. I can also do this on my side, if necessary.)

Copy link
Owner

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Hey @emka, I've decided to merge this pull request right away. I'm about to make some changes to the validation code that are not directly related to this pull request, but might touch some of the same code. Keeping this open will only lead to merge conflicts and frustration.

I'll do a rebase before merging, to get the commits in the order I requested.

I'd be happy to accept further improvements in follow-up pull requests!

emka added 3 commits March 13, 2024 12:56
Use BuildRegion to create cycles with valid windings.
Add info to help determine which cycles are wrong
@hannobraun hannobraun enabled auto-merge March 13, 2024 11:58
@hannobraun hannobraun merged commit da2cb41 into hannobraun:main Mar 13, 2024
4 checks passed
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