Skip to content

Commit

Permalink
Refactor multiple_references tests
Browse files Browse the repository at this point in the history
Use BuildRegion to create cycles with valid windings.
  • Loading branch information
emka authored and hannobraun committed Mar 13, 2024
1 parent c9fa417 commit 0aa266e
Showing 1 changed file with 21 additions and 32 deletions.
53 changes: 21 additions & 32 deletions crates/fj-core/src/validate/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ mod tests {
use crate::{
assert_contains_err,
objects::{Cycle, HalfEdge, Region, Sketch, Vertex},
operations::{build::BuildHalfEdge, insert::Insert},
operations::{
build::BuildHalfEdge, build::BuildRegion, insert::Insert,
},
validate::{
references::ReferenceCountError, SketchValidationError, Validate,
ValidationError,
Expand All @@ -66,15 +68,15 @@ mod tests {
fn should_find_cycle_multiple_references() -> anyhow::Result<()> {
let mut core = Core::new();

let shared_cycle = Cycle::new(vec![]).insert(&mut core);
let region = <Region as BuildRegion>::circle([0., 0.], 1., &mut core)
.insert(&mut core);
let valid_sketch = Sketch::new(vec![region.clone()]).insert(&mut core);
valid_sketch.validate_and_return_first_error()?;

let shared_cycle = region.exterior();
let invalid_sketch = Sketch::new(vec![
Region::new(
Cycle::new(vec![]).insert(&mut core),
vec![shared_cycle.clone()],
)
.insert(&mut core),
Region::new(shared_cycle, vec![]).insert(&mut core),
Region::new(shared_cycle.clone(), vec![]).insert(&mut core),
Region::new(shared_cycle.clone(), vec![]).insert(&mut core),
]);
assert_contains_err!(
invalid_sketch,
Expand All @@ -83,34 +85,25 @@ mod tests {
))
);

let valid_sketch = Sketch::new(vec![Region::new(
Cycle::new(vec![]).insert(&mut core),
vec![],
)
.insert(&mut core)]);
valid_sketch.validate_and_return_first_error()?;

Ok(())
}

#[test]
fn should_find_half_edge_multiple_references() -> anyhow::Result<()> {
let mut core = Core::new();

let half_edge =
HalfEdge::line_segment([[0., 0.], [1., 0.]], None, &mut core)
.insert(&mut core);
let sibling_edge =
HalfEdge::from_sibling(&half_edge, Vertex::new().insert(&mut core))
.insert(&mut core);

let exterior =
Cycle::new(vec![half_edge.clone(), sibling_edge.clone()])
.insert(&mut core);
let region = <Region as BuildRegion>::polygon(
[[0., 0.], [1., 1.], [0., 1.]],
&mut core,
)
.insert(&mut core);
let valid_sketch = Sketch::new(vec![region.clone()]).insert(&mut core);
valid_sketch.validate_and_return_first_error()?;

let interior =
Cycle::new(vec![half_edge.clone(), sibling_edge.clone()])
.insert(&mut core);
let exterior = region.exterior();
let cloned_edges: Vec<_> =
exterior.half_edges().iter().map(|e| e.clone()).collect();
let interior = Cycle::new(cloned_edges).insert(&mut core);

let invalid_sketch =
Sketch::new(vec![
Expand All @@ -123,10 +116,6 @@ mod tests {
))
);

let valid_sketch =
Sketch::new(vec![Region::new(exterior, vec![]).insert(&mut core)]);
valid_sketch.validate_and_return_first_error()?;

Ok(())
}
}

0 comments on commit 0aa266e

Please sign in to comment.