Replace Topology::add_cycle with Shape::insert

This commit is contained in:
Hanno Braun 2022-04-01 17:23:58 +02:00
parent 69409a6210
commit d657ecec4a
7 changed files with 12 additions and 40 deletions

View File

@ -176,7 +176,7 @@ mod tests {
let da = let da =
Edge::build(&mut shape).line_segment_from_vertices([v4, v1])?; Edge::build(&mut shape).line_segment_from_vertices([v4, v1])?;
let abcd = shape.topology().add_cycle(Cycle { let abcd = shape.insert(Cycle {
edges: vec![ab, bc, cd, da], edges: vec![ab, bc, cd, da],
})?; })?;

View File

@ -77,15 +77,11 @@ pub fn sweep_shape(
let edges_top = source_to_top.edges_for_cycle(&cycle_source); let edges_top = source_to_top.edges_for_cycle(&cycle_source);
let cycle_bottom = target let cycle_bottom = target
.topology() .insert(Cycle {
.add_cycle(Cycle {
edges: edges_bottom, edges: edges_bottom,
}) })
.unwrap(); .unwrap();
let cycle_top = target let cycle_top = target.insert(Cycle { edges: edges_top }).unwrap();
.topology()
.add_cycle(Cycle { edges: edges_top })
.unwrap();
source_to_bottom source_to_bottom
.cycles .cycles
@ -237,8 +233,7 @@ pub fn sweep_shape(
.unwrap(); .unwrap();
let cycle = target let cycle = target
.topology() .insert(Cycle {
.add_cycle(Cycle {
edges: vec![ edges: vec![
bottom_edge, bottom_edge,
top_edge, top_edge,
@ -406,7 +401,7 @@ mod tests {
let ca = Edge::build(&mut shape) let ca = Edge::build(&mut shape)
.line_segment_from_vertices([c.clone(), a.clone()])?; .line_segment_from_vertices([c.clone(), a.clone()])?;
let cycles = shape.topology().add_cycle(Cycle { let cycles = shape.insert(Cycle {
edges: vec![ab, bc, ca], edges: vec![ab, bc, ca],
})?; })?;

View File

@ -14,23 +14,6 @@ pub struct Topology<'r> {
} }
impl Topology<'_> { impl Topology<'_> {
/// Add a cycle to the shape
///
/// Validates that the cycle is structurally sound (i.e. the edges it refers
/// to are part of the shape). Returns an error, if that is not the case.
///
/// # Implementation note
///
/// The validation of the cycle should be extended to cover more cases:
/// - That those edges form a cycle.
/// - That the cycle is not self-overlapping.
/// - That there exists no duplicate cycle, with the same edges.
pub fn add_cycle(&mut self, cycle: Cycle) -> ValidationResult<Cycle> {
cycle.validate(self.min_distance, &self.stores)?;
let handle = self.stores.cycles.insert(cycle);
Ok(handle)
}
/// Add a face to the shape /// Add a face to the shape
/// ///
/// Validates that the face is structurally sound (i.e. the surface and /// Validates that the face is structurally sound (i.e. the surface and
@ -153,8 +136,7 @@ mod tests {
// Trying to refer to edge that is not from the same shape. Should fail. // Trying to refer to edge that is not from the same shape. Should fail.
let edge = other.add_edge()?; let edge = other.add_edge()?;
let err = shape let err = shape
.topology() .insert(Cycle {
.add_cycle(Cycle {
edges: vec![edge.clone()], edges: vec![edge.clone()],
}) })
.unwrap_err(); .unwrap_err();
@ -162,7 +144,7 @@ mod tests {
// Referring to edge that *is* from the same shape. Should work. // Referring to edge that *is* from the same shape. Should work.
let edge = shape.add_edge()?; let edge = shape.add_edge()?;
shape.topology().add_cycle(Cycle { edges: vec![edge] })?; shape.insert(Cycle { edges: vec![edge] })?;
Ok(()) Ok(())
} }
@ -239,8 +221,7 @@ mod tests {
fn add_cycle(&mut self) -> anyhow::Result<Handle<Cycle>> { fn add_cycle(&mut self) -> anyhow::Result<Handle<Cycle>> {
let edge = self.add_edge()?; let edge = self.add_edge()?;
let cycle = let cycle = self.insert(Cycle { edges: vec![edge] })?;
self.topology().add_cycle(Cycle { edges: vec![edge] })?;
Ok(cycle) Ok(cycle)
} }
} }

View File

@ -18,10 +18,7 @@ impl ToShape for fj::Circle {
let edge = Edge::build(&mut shape) let edge = Edge::build(&mut shape)
.circle(Scalar::from_f64(self.radius())) .circle(Scalar::from_f64(self.radius()))
.unwrap(); .unwrap();
shape shape.insert(Cycle { edges: vec![edge] }).unwrap();
.topology()
.add_cycle(Cycle { edges: vec![edge] })
.unwrap();
let cycles = shape.topology().cycles().collect(); let cycles = shape.topology().cycles().collect();
let surface = shape.insert(Surface::x_y_plane()).unwrap(); let surface = shape.insert(Surface::x_y_plane()).unwrap();

View File

@ -109,5 +109,5 @@ fn add_cycle(
edges.push(edge); edges.push(edge);
} }
shape.topology().add_cycle(Cycle { edges }).unwrap() shape.insert(Cycle { edges }).unwrap()
} }

View File

@ -73,8 +73,7 @@ fn copy_shape(mut orig: Shape, target: &mut Shape) {
} }
for cycle_orig in orig.topology().cycles() { for cycle_orig in orig.topology().cycles() {
let cycle = target let cycle = target
.topology() .insert(Cycle {
.add_cycle(Cycle {
edges: cycle_orig edges: cycle_orig
.get() .get()
.edges .edges

View File

@ -42,7 +42,7 @@ impl ToShape for fj::Sketch {
edges.push(edge); edges.push(edge);
} }
shape.topology().add_cycle(Cycle { edges }).unwrap(); shape.insert(Cycle { edges }).unwrap();
}; };
let surface = shape.insert(Surface::x_y_plane()).unwrap(); let surface = shape.insert(Surface::x_y_plane()).unwrap();