Replace Topology::add_face with Shape::insert

This commit is contained in:
Hanno Braun 2022-04-01 17:26:19 +02:00
parent d657ecec4a
commit 92df8ef749
7 changed files with 13 additions and 38 deletions

View File

@ -104,8 +104,7 @@ pub fn sweep_shape(
let interiors_top = source_to_top.interiors_for_face(&face_source);
target
.topology()
.add_face(Face::Face {
.insert(Face::Face {
surface: surface_bottom,
exteriors: exteriors_bottom,
interiors: interiors_bottom,
@ -113,8 +112,7 @@ pub fn sweep_shape(
})
.unwrap();
target
.topology()
.add_face(Face::Face {
.insert(Face::Face {
surface: surface_top,
exteriors: exteriors_top,
interiors: interiors_top,
@ -165,10 +163,7 @@ pub fn sweep_shape(
s.set_color(color);
}
target
.topology()
.add_face(Face::Triangles(side_face))
.unwrap();
target.insert(Face::Triangles(side_face)).unwrap();
} else {
// If there's no continuous edge, we can create the non-
// continuous faces using boundary representation.
@ -244,8 +239,7 @@ pub fn sweep_shape(
.unwrap();
target
.topology()
.add_face(Face::Face {
.insert(Face::Face {
surface,
exteriors: vec![cycle],
interiors: Vec::new(),
@ -417,7 +411,7 @@ mod tests {
color: [255, 0, 0, 255],
};
let face = shape.topology().add_face(abc)?;
let face = shape.insert(abc)?;
Ok(Self { shape, face })
}

View File

@ -82,7 +82,6 @@ impl Shape {
/// Access the shape's topology
pub fn topology(&mut self) -> Topology {
Topology {
min_distance: self.min_distance,
stores: self.stores.clone(),
_lifetime: PhantomData,
}

View File

@ -1,30 +1,16 @@
use std::marker::PhantomData;
use fj_math::Scalar;
use crate::topology::{Cycle, Edge, Face, Vertex};
use super::{stores::Stores, validate::Validate as _, Iter, ValidationResult};
use super::{stores::Stores, Iter};
/// The vertices of a shape
pub struct Topology<'r> {
pub(super) min_distance: Scalar,
pub(super) stores: Stores,
pub(super) _lifetime: PhantomData<&'r ()>,
}
impl Topology<'_> {
/// Add a face to the shape
///
/// Validates that the face is structurally sound (i.e. the surface and
/// cycles it refers to are part of the shape). Returns an error, if that is
/// not the case.
pub fn add_face(&mut self, face: Face) -> ValidationResult<Face> {
face.validate(self.min_distance, &self.stores)?;
let handle = self.stores.faces.insert(face);
Ok(handle)
}
/// Access iterator over all vertices
///
/// The caller must not make any assumptions about the order of vertices.
@ -159,8 +145,7 @@ mod tests {
// Nothing has been added to `shape`. Should fail.
let err = shape
.topology()
.add_face(Face::Face {
.insert(Face::Face {
surface: surface.clone(),
exteriors: vec![cycle.clone()],
interiors: Vec::new(),
@ -174,7 +159,7 @@ mod tests {
let cycle = shape.add_cycle()?;
// Everything has been added to `shape` now. Should work!
shape.topology().add_face(Face::Face {
shape.insert(Face::Face {
surface,
exteriors: vec![cycle],
interiors: Vec::new(),

View File

@ -23,8 +23,7 @@ impl ToShape for fj::Circle {
let cycles = shape.topology().cycles().collect();
let surface = shape.insert(Surface::x_y_plane()).unwrap();
shape
.topology()
.add_face(Face::Face {
.insert(Face::Face {
exteriors: cycles,
interiors: Vec::new(),
surface,

View File

@ -64,8 +64,7 @@ impl ToShape for fj::Difference2d {
let surface = shape.insert(face_a.surface()).unwrap();
shape
.topology()
.add_face(Face::Face {
.insert(Face::Face {
surface,
exteriors,
interiors,

View File

@ -94,8 +94,7 @@ fn copy_shape(mut orig: Shape, target: &mut Shape) {
color,
} => {
target
.topology()
.add_face(Face::Face {
.insert(Face::Face {
surface: surfaces[&surface].clone(),
exteriors: exteriors
.iter()
@ -110,7 +109,7 @@ fn copy_shape(mut orig: Shape, target: &mut Shape) {
.unwrap();
}
face @ Face::Triangles(_) => {
target.topology().add_face(face.clone()).unwrap();
target.insert(face.clone()).unwrap();
}
}
}

View File

@ -52,7 +52,7 @@ impl ToShape for fj::Sketch {
surface,
color: self.color(),
};
shape.topology().add_face(face).unwrap();
shape.insert(face).unwrap();
shape
}