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

View File

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

View File

@ -1,30 +1,16 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use fj_math::Scalar;
use crate::topology::{Cycle, Edge, Face, Vertex}; 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 /// The vertices of a shape
pub struct Topology<'r> { pub struct Topology<'r> {
pub(super) min_distance: Scalar,
pub(super) stores: Stores, pub(super) stores: Stores,
pub(super) _lifetime: PhantomData<&'r ()>, pub(super) _lifetime: PhantomData<&'r ()>,
} }
impl Topology<'_> { 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 /// Access iterator over all vertices
/// ///
/// The caller must not make any assumptions about the order of 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. // Nothing has been added to `shape`. Should fail.
let err = shape let err = shape
.topology() .insert(Face::Face {
.add_face(Face::Face {
surface: surface.clone(), surface: surface.clone(),
exteriors: vec![cycle.clone()], exteriors: vec![cycle.clone()],
interiors: Vec::new(), interiors: Vec::new(),
@ -174,7 +159,7 @@ mod tests {
let cycle = shape.add_cycle()?; let cycle = shape.add_cycle()?;
// Everything has been added to `shape` now. Should work! // Everything has been added to `shape` now. Should work!
shape.topology().add_face(Face::Face { shape.insert(Face::Face {
surface, surface,
exteriors: vec![cycle], exteriors: vec![cycle],
interiors: Vec::new(), interiors: Vec::new(),

View File

@ -23,8 +23,7 @@ impl ToShape for fj::Circle {
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();
shape shape
.topology() .insert(Face::Face {
.add_face(Face::Face {
exteriors: cycles, exteriors: cycles,
interiors: Vec::new(), interiors: Vec::new(),
surface, surface,

View File

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

View File

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