Merge pull request #730 from hannobraun/shape

Remove unused parts of `Shape` API
This commit is contained in:
Hanno Braun 2022-06-28 14:37:24 +02:00 committed by GitHub
commit d1792ea932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 262 deletions

View File

@ -4,7 +4,7 @@ use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex};
use super::{
stores::{Store, Stores},
Handle, Iter, Mapping, Object, Update,
Handle, Iter, Object, Update,
};
/// The boundary representation of a shape
@ -116,36 +116,32 @@ impl Shape {
///
/// This is done recursively.
pub fn merge<T: Object>(&mut self, object: T) -> Handle<T> {
object.merge_into(None, self, &mut Mapping::new())
object.merge_into(self)
}
/// Merge the provided shape into this one
///
/// Returns a [`Mapping`] that maps each object from the merged shape to the
/// merged objects in this shape.
pub fn merge_shape(&mut self, other: &Shape) -> Mapping {
let mut mapping = Mapping::new();
pub fn merge_shape(&mut self, other: &Shape) {
for object in other.curves() {
object.get().merge_into(Some(object), self, &mut mapping);
object.get().merge_into(self);
}
for object in other.surfaces() {
object.get().merge_into(Some(object), self, &mut mapping);
object.get().merge_into(self);
}
for object in other.vertices() {
object.get().merge_into(Some(object), self, &mut mapping);
object.get().merge_into(self);
}
for object in other.edges() {
object.get().merge_into(Some(object), self, &mut mapping);
object.get().merge_into(self);
}
for object in other.cycles() {
object.get().merge_into(Some(object), self, &mut mapping);
object.get().merge_into(self);
}
for object in other.faces() {
object.get().merge_into(Some(object), self, &mut mapping);
object.get().merge_into(self);
}
mapping
}
/// Update objects in the shape
@ -156,42 +152,6 @@ impl Shape {
Update::new(&mut self.stores)
}
/// Clone the shape
///
/// Returns a [`Mapping`] that maps each object from the original shape to
/// the respective object in the cloned shape.
pub fn clone_shape(&self) -> (Shape, Mapping) {
let mut target = Shape::new();
let mut mapping = Mapping::new();
for original in self.curves() {
let cloned = target.merge(original.get());
mapping.curves.insert(original, cloned);
}
for original in self.surfaces() {
let cloned = target.merge(original.get());
mapping.surfaces.insert(original, cloned);
}
for original in self.vertices() {
let cloned = target.merge(original.get());
mapping.vertices.insert(original, cloned);
}
for original in self.edges() {
let cloned = target.merge(original.get());
mapping.edges.insert(original, cloned);
}
for original in self.cycles() {
let cloned = target.merge(original.get());
mapping.cycles.insert(original, cloned);
}
for original in self.faces() {
let cloned = target.merge(original.get());
mapping.faces.insert(original, cloned);
}
(target, mapping)
}
/// Access an iterator over all curves
///
/// The caller must not make any assumptions about the order of curves.

View File

@ -1,102 +0,0 @@
use std::collections::HashMap;
use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex};
use super::Handle;
/// A mapping between objects in different shapes
pub struct Mapping {
pub(super) curves: OneMapping<Curve<3>>,
pub(super) surfaces: OneMapping<Surface>,
pub(super) vertices: OneMapping<Vertex>,
pub(super) edges: OneMapping<Edge<3>>,
pub(super) cycles: OneMapping<Cycle<3>>,
pub(super) faces: OneMapping<Face>,
}
impl Mapping {
pub(super) fn new() -> Self {
Self {
curves: OneMapping::new(),
surfaces: OneMapping::new(),
vertices: OneMapping::new(),
edges: OneMapping::new(),
cycles: OneMapping::new(),
faces: OneMapping::new(),
}
}
/// Access the curve mapped from the provided curve
///
/// # Panics
///
/// Panics, if `object` can not be found in the mapping.
pub fn curve(&self, object: &Handle<Curve<3>>) -> Handle<Curve<3>> {
self.curves
.get(object)
.expect("Could not find curve in mapping")
.clone()
}
/// Access the surface mapped from the provided surface
///
/// # Panics
///
/// Panics, if `object` can not be found in the mapping.
pub fn surface(&self, object: &Handle<Surface>) -> Handle<Surface> {
self.surfaces
.get(object)
.expect("Could not find surface in mapping")
.clone()
}
/// Access the vertex mapped from the provided vertex
///
/// # Panics
///
/// Panics, if `object` can not be found in the mapping.
pub fn vertex(&self, object: &Handle<Vertex>) -> Handle<Vertex> {
self.vertices
.get(object)
.expect("Could not find vertex in mapping")
.clone()
}
/// Access the edge mapped from the provided edge
///
/// # Panics
///
/// Panics, if `object` can not be found in the mapping.
pub fn edge(&self, object: &Handle<Edge<3>>) -> Handle<Edge<3>> {
self.edges
.get(object)
.expect("Could not find edge in mapping")
.clone()
}
/// Access the cycle mapped from the provided cycle
///
/// # Panics
///
/// Panics, if `object` can not be found in the mapping.
pub fn cycle(&self, object: &Handle<Cycle<3>>) -> Handle<Cycle<3>> {
self.cycles
.get(object)
.expect("Could not find vertex in mapping")
.clone()
}
/// Access the face mapped from the provided face
///
/// # Panics
///
/// Panics, if `object` can not be found in the mapping.
pub fn face(&self, object: &Handle<Face>) -> Handle<Face> {
self.faces
.get(object)
.expect("Could not find face in mapping")
.clone()
}
}
type OneMapping<T> = HashMap<Handle<T>, Handle<T>>;

View File

@ -4,7 +4,6 @@
mod api;
mod local;
mod mapping;
mod object;
mod stores;
mod update;
@ -12,7 +11,6 @@ mod update;
pub use self::{
api::Shape,
local::LocalForm,
mapping::Mapping,
object::Object,
stores::{Handle, Iter},
update::Update,

View File

@ -2,19 +2,14 @@ use crate::objects::{
Curve, Cycle, Edge, Face, Surface, Vertex, VerticesOfEdge,
};
use super::{Handle, LocalForm, Mapping, Shape};
use super::{Handle, LocalForm, Shape};
/// Marker trait for geometric and topological objects
pub trait Object: 'static + Clone + PartialEq + private::Sealed {
/// Internal function
///
/// Please consider using [`Shape::merge`] instead.
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self>;
fn merge_into(self, shape: &mut Shape) -> Handle<Self>;
}
impl private::Sealed for Curve<3> {}
@ -26,145 +21,68 @@ impl private::Sealed for Cycle<3> {}
impl private::Sealed for Face {}
impl Object for Curve<3> {
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self> {
let merged = shape.get_handle_or_insert(self);
if let Some(handle) = handle {
mapping.curves.insert(handle, merged.clone());
}
merged
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
shape.get_handle_or_insert(self)
}
}
impl Object for Surface {
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self> {
let merged = shape.get_handle_or_insert(self);
if let Some(handle) = handle {
mapping.surfaces.insert(handle, merged.clone());
}
merged
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
shape.get_handle_or_insert(self)
}
}
impl Object for Vertex {
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self> {
let merged = shape.get_handle_or_insert(Vertex { point: self.point });
if let Some(handle) = handle {
mapping.vertices.insert(handle, merged.clone());
}
merged
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
shape.get_handle_or_insert(Vertex { point: self.point })
}
}
impl Object for Edge<3> {
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self> {
let curve = self.curve().merge_into(
Some(self.curve.canonical()),
shape,
mapping,
);
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
let curve = self.curve().merge_into(shape);
let vertices = self.vertices.convert(|vertex| {
let canonical = vertex.canonical();
let canonical =
canonical.get().merge_into(Some(canonical), shape, mapping);
let canonical = canonical.get().merge_into(shape);
LocalForm::new(*vertex.local(), canonical)
});
let merged = shape.get_handle_or_insert(Edge {
shape.get_handle_or_insert(Edge {
curve: LocalForm::canonical_only(curve),
vertices: VerticesOfEdge::new(vertices),
});
if let Some(handle) = handle {
mapping.edges.insert(handle, merged.clone());
}
merged
})
}
}
impl Object for Cycle<3> {
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self> {
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
let mut edges = Vec::new();
for edge in self.edges {
let edge = edge.canonical();
let edge = edge.get().merge_into(Some(edge), shape, mapping);
let edge = edge.get().merge_into(shape);
edges.push(edge);
}
let merged = shape.get_handle_or_insert(Cycle::new(edges));
if let Some(handle) = handle {
mapping.cycles.insert(handle, merged.clone());
}
merged
shape.get_handle_or_insert(Cycle::new(edges))
}
}
impl Object for Face {
fn merge_into(
self,
handle: Option<Handle<Self>>,
shape: &mut Shape,
mapping: &mut Mapping,
) -> Handle<Self> {
let merged = match self {
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
match self {
Face::Face(face) => {
let surface = face.surface.get().merge_into(
Some(face.surface),
shape,
mapping,
);
let surface = face.surface.get().merge_into(shape);
let mut exts = Vec::new();
for cycle in face.exteriors.as_local_form() {
let merged = cycle.canonical().get().merge_into(
Some(cycle.canonical()),
shape,
mapping,
);
let merged = cycle.canonical().get().merge_into(shape);
exts.push(LocalForm::new(cycle.local().clone(), merged));
}
let mut ints = Vec::new();
for cycle in face.interiors.as_local_form() {
let merged = cycle.canonical().get().merge_into(
Some(cycle.canonical()),
shape,
mapping,
);
let merged = cycle.canonical().get().merge_into(shape);
ints.push(LocalForm::new(cycle.local().clone(), merged));
}
@ -173,13 +91,7 @@ impl Object for Face {
))
}
Face::Triangles(_) => shape.get_handle_or_insert(self),
};
if let Some(handle) = handle {
mapping.faces.insert(handle, merged.clone());
}
merged
}
}