mirror of
https://github.com/hannobraun/Fornjot
synced 2025-09-12 12:18:14 +00:00
Merge pull request #730 from hannobraun/shape
Remove unused parts of `Shape` API
This commit is contained in:
commit
d1792ea932
@ -4,7 +4,7 @@ use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex};
|
|||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
stores::{Store, Stores},
|
stores::{Store, Stores},
|
||||||
Handle, Iter, Mapping, Object, Update,
|
Handle, Iter, Object, Update,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The boundary representation of a shape
|
/// The boundary representation of a shape
|
||||||
@ -116,36 +116,32 @@ impl Shape {
|
|||||||
///
|
///
|
||||||
/// This is done recursively.
|
/// This is done recursively.
|
||||||
pub fn merge<T: Object>(&mut self, object: T) -> Handle<T> {
|
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
|
/// Merge the provided shape into this one
|
||||||
///
|
///
|
||||||
/// Returns a [`Mapping`] that maps each object from the merged shape to the
|
/// Returns a [`Mapping`] that maps each object from the merged shape to the
|
||||||
/// merged objects in this shape.
|
/// merged objects in this shape.
|
||||||
pub fn merge_shape(&mut self, other: &Shape) -> Mapping {
|
pub fn merge_shape(&mut self, other: &Shape) {
|
||||||
let mut mapping = Mapping::new();
|
|
||||||
|
|
||||||
for object in other.curves() {
|
for object in other.curves() {
|
||||||
object.get().merge_into(Some(object), self, &mut mapping);
|
object.get().merge_into(self);
|
||||||
}
|
}
|
||||||
for object in other.surfaces() {
|
for object in other.surfaces() {
|
||||||
object.get().merge_into(Some(object), self, &mut mapping);
|
object.get().merge_into(self);
|
||||||
}
|
}
|
||||||
for object in other.vertices() {
|
for object in other.vertices() {
|
||||||
object.get().merge_into(Some(object), self, &mut mapping);
|
object.get().merge_into(self);
|
||||||
}
|
}
|
||||||
for object in other.edges() {
|
for object in other.edges() {
|
||||||
object.get().merge_into(Some(object), self, &mut mapping);
|
object.get().merge_into(self);
|
||||||
}
|
}
|
||||||
for object in other.cycles() {
|
for object in other.cycles() {
|
||||||
object.get().merge_into(Some(object), self, &mut mapping);
|
object.get().merge_into(self);
|
||||||
}
|
}
|
||||||
for object in other.faces() {
|
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
|
/// Update objects in the shape
|
||||||
@ -156,42 +152,6 @@ impl Shape {
|
|||||||
Update::new(&mut self.stores)
|
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
|
/// Access an iterator over all curves
|
||||||
///
|
///
|
||||||
/// The caller must not make any assumptions about the order of curves.
|
/// The caller must not make any assumptions about the order of curves.
|
||||||
|
@ -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>>;
|
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
mod api;
|
mod api;
|
||||||
mod local;
|
mod local;
|
||||||
mod mapping;
|
|
||||||
mod object;
|
mod object;
|
||||||
mod stores;
|
mod stores;
|
||||||
mod update;
|
mod update;
|
||||||
@ -12,7 +11,6 @@ mod update;
|
|||||||
pub use self::{
|
pub use self::{
|
||||||
api::Shape,
|
api::Shape,
|
||||||
local::LocalForm,
|
local::LocalForm,
|
||||||
mapping::Mapping,
|
|
||||||
object::Object,
|
object::Object,
|
||||||
stores::{Handle, Iter},
|
stores::{Handle, Iter},
|
||||||
update::Update,
|
update::Update,
|
||||||
|
@ -2,19 +2,14 @@ use crate::objects::{
|
|||||||
Curve, Cycle, Edge, Face, Surface, Vertex, VerticesOfEdge,
|
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
|
/// Marker trait for geometric and topological objects
|
||||||
pub trait Object: 'static + Clone + PartialEq + private::Sealed {
|
pub trait Object: 'static + Clone + PartialEq + private::Sealed {
|
||||||
/// Internal function
|
/// Internal function
|
||||||
///
|
///
|
||||||
/// Please consider using [`Shape::merge`] instead.
|
/// Please consider using [`Shape::merge`] instead.
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self>;
|
||||||
self,
|
|
||||||
handle: Option<Handle<Self>>,
|
|
||||||
shape: &mut Shape,
|
|
||||||
mapping: &mut Mapping,
|
|
||||||
) -> Handle<Self>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl private::Sealed for Curve<3> {}
|
impl private::Sealed for Curve<3> {}
|
||||||
@ -26,145 +21,68 @@ impl private::Sealed for Cycle<3> {}
|
|||||||
impl private::Sealed for Face {}
|
impl private::Sealed for Face {}
|
||||||
|
|
||||||
impl Object for Curve<3> {
|
impl Object for Curve<3> {
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
|
||||||
self,
|
shape.get_handle_or_insert(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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Surface {
|
impl Object for Surface {
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
|
||||||
self,
|
shape.get_handle_or_insert(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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Vertex {
|
impl Object for Vertex {
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
|
||||||
self,
|
shape.get_handle_or_insert(Vertex { point: self.point })
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Edge<3> {
|
impl Object for Edge<3> {
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
|
||||||
self,
|
let curve = self.curve().merge_into(shape);
|
||||||
handle: Option<Handle<Self>>,
|
|
||||||
shape: &mut Shape,
|
|
||||||
mapping: &mut Mapping,
|
|
||||||
) -> Handle<Self> {
|
|
||||||
let curve = self.curve().merge_into(
|
|
||||||
Some(self.curve.canonical()),
|
|
||||||
shape,
|
|
||||||
mapping,
|
|
||||||
);
|
|
||||||
|
|
||||||
let vertices = self.vertices.convert(|vertex| {
|
let vertices = self.vertices.convert(|vertex| {
|
||||||
let canonical = vertex.canonical();
|
let canonical = vertex.canonical();
|
||||||
let canonical =
|
let canonical = canonical.get().merge_into(shape);
|
||||||
canonical.get().merge_into(Some(canonical), shape, mapping);
|
|
||||||
LocalForm::new(*vertex.local(), canonical)
|
LocalForm::new(*vertex.local(), canonical)
|
||||||
});
|
});
|
||||||
|
|
||||||
let merged = shape.get_handle_or_insert(Edge {
|
shape.get_handle_or_insert(Edge {
|
||||||
curve: LocalForm::canonical_only(curve),
|
curve: LocalForm::canonical_only(curve),
|
||||||
vertices: VerticesOfEdge::new(vertices),
|
vertices: VerticesOfEdge::new(vertices),
|
||||||
});
|
})
|
||||||
|
|
||||||
if let Some(handle) = handle {
|
|
||||||
mapping.edges.insert(handle, merged.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
merged
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Cycle<3> {
|
impl Object for Cycle<3> {
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
|
||||||
self,
|
|
||||||
handle: Option<Handle<Self>>,
|
|
||||||
shape: &mut Shape,
|
|
||||||
mapping: &mut Mapping,
|
|
||||||
) -> Handle<Self> {
|
|
||||||
let mut edges = Vec::new();
|
let mut edges = Vec::new();
|
||||||
for edge in self.edges {
|
for edge in self.edges {
|
||||||
let edge = edge.canonical();
|
let edge = edge.canonical();
|
||||||
let edge = edge.get().merge_into(Some(edge), shape, mapping);
|
let edge = edge.get().merge_into(shape);
|
||||||
edges.push(edge);
|
edges.push(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
let merged = shape.get_handle_or_insert(Cycle::new(edges));
|
shape.get_handle_or_insert(Cycle::new(edges))
|
||||||
|
|
||||||
if let Some(handle) = handle {
|
|
||||||
mapping.cycles.insert(handle, merged.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
merged
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Face {
|
impl Object for Face {
|
||||||
fn merge_into(
|
fn merge_into(self, shape: &mut Shape) -> Handle<Self> {
|
||||||
self,
|
match self {
|
||||||
handle: Option<Handle<Self>>,
|
|
||||||
shape: &mut Shape,
|
|
||||||
mapping: &mut Mapping,
|
|
||||||
) -> Handle<Self> {
|
|
||||||
let merged = match self {
|
|
||||||
Face::Face(face) => {
|
Face::Face(face) => {
|
||||||
let surface = face.surface.get().merge_into(
|
let surface = face.surface.get().merge_into(shape);
|
||||||
Some(face.surface),
|
|
||||||
shape,
|
|
||||||
mapping,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut exts = Vec::new();
|
let mut exts = Vec::new();
|
||||||
for cycle in face.exteriors.as_local_form() {
|
for cycle in face.exteriors.as_local_form() {
|
||||||
let merged = cycle.canonical().get().merge_into(
|
let merged = cycle.canonical().get().merge_into(shape);
|
||||||
Some(cycle.canonical()),
|
|
||||||
shape,
|
|
||||||
mapping,
|
|
||||||
);
|
|
||||||
exts.push(LocalForm::new(cycle.local().clone(), merged));
|
exts.push(LocalForm::new(cycle.local().clone(), merged));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ints = Vec::new();
|
let mut ints = Vec::new();
|
||||||
for cycle in face.interiors.as_local_form() {
|
for cycle in face.interiors.as_local_form() {
|
||||||
let merged = cycle.canonical().get().merge_into(
|
let merged = cycle.canonical().get().merge_into(shape);
|
||||||
Some(cycle.canonical()),
|
|
||||||
shape,
|
|
||||||
mapping,
|
|
||||||
);
|
|
||||||
ints.push(LocalForm::new(cycle.local().clone(), merged));
|
ints.push(LocalForm::new(cycle.local().clone(), merged));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,13 +91,7 @@ impl Object for Face {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
Face::Triangles(_) => shape.get_handle_or_insert(self),
|
Face::Triangles(_) => shape.get_handle_or_insert(self),
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(handle) = handle {
|
|
||||||
mapping.faces.insert(handle, merged.clone());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
merged
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user