Merge pull request #735 from hannobraun/shape

Remove more unused parts of `Shape`
This commit is contained in:
Hanno Braun 2022-06-28 17:23:43 +02:00 committed by GitHub
commit 412bfe811c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 103 deletions

View File

@ -1,17 +1,13 @@
use fj_math::Scalar;
use crate::objects::{Curve, Cycle, Edge, Face, Surface, Vertex};
use super::{
stores::{Store, Stores},
Handle, Iter, Object, Update,
Handle, Iter, Object,
};
/// The boundary representation of a shape
#[derive(Clone, Debug)]
pub struct Shape {
distinct_min_distance: Scalar,
stores: Stores,
}
@ -19,11 +15,6 @@ impl Shape {
/// Construct a new shape
pub fn new() -> Self {
Self {
// This should really come from `Self::DEFAULT_MIN_DISTANCE`, or a
// similarly named constant. Unfortunately `Scalar::from_f64` can't
// be `const` yet.
distinct_min_distance: Scalar::from_f64(5e-7), // 0.5 µm
stores: Stores {
curves: Store::new(),
surfaces: Store::new(),
@ -55,17 +46,6 @@ impl Shape {
self
}
/// Override the minimum distance between distinct objects
///
/// Used for vertex validation, to determine whether vertices are unique.
pub fn with_distinct_min_distance(
mut self,
distinct_min_distance: impl Into<Scalar>,
) -> Self {
self.distinct_min_distance = distinct_min_distance.into();
self
}
/// Insert an object into the shape
///
/// Validates the object, and returns an error if it is not valid. See the
@ -119,39 +99,6 @@ impl Shape {
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) {
for object in other.curves() {
object.get().merge_into(self);
}
for object in other.surfaces() {
object.get().merge_into(self);
}
for object in other.vertices() {
object.get().merge_into(self);
}
for object in other.edges() {
object.get().merge_into(self);
}
for object in other.cycles() {
object.get().merge_into(self);
}
for object in other.faces() {
object.get().merge_into(self);
}
}
/// Update objects in the shape
///
/// Returns [`Update`], and API that can be used to update objects in the
/// shape.
pub fn update(&mut self) -> Update {
Update::new(&mut self.stores)
}
/// Access an iterator over all curves
///
/// The caller must not make any assumptions about the order of curves.

View File

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

View File

@ -81,15 +81,6 @@ impl<T: Object> Store<T> {
}
}
pub fn update<F>(&mut self, mut f: F)
where
F: FnMut(&mut T),
{
for (_, object) in self.objects.write().iter_mut() {
f(object);
}
}
fn ptr(&self) -> *const () {
Arc::as_ptr(&self.objects) as _
}

View File

@ -1,20 +0,0 @@
use super::{stores::Stores, Object};
/// API to update a `Shape`
///
/// See [`Shape::update`].
pub struct Update<'r> {
stores: &'r mut Stores,
}
impl<'r> Update<'r> {
pub(super) fn new(stores: &'r mut Stores) -> Self {
Self { stores }
}
/// Update all objects of a specific type
pub fn update_all<T: Object>(self, f: impl FnMut(&mut T)) -> Self {
self.stores.get::<T>().update(f);
self
}
}

View File

@ -232,28 +232,29 @@ mod tests {
#[test]
fn coherence_edge() {
let mut shape = Shape::new();
Edge::builder(&mut shape)
.build_line_segment_from_points([[0., 0., 0.], [1., 0., 0.]])
.get();
let mut tmp = Shape::new();
let a = Point::from([0., 0., 0.]);
let b = Point::from([1., 0., 0.]);
let curve = {
let curve = tmp.insert(Curve::line_from_points([a, b]));
LocalForm::canonical_only(curve)
};
let a = tmp.insert(Vertex { point: a });
let b = tmp.insert(Vertex { point: b });
let deviation = Scalar::from_f64(0.25);
shape.update().update_all(|edge: &mut Edge<3>| {
let original = edge.clone();
*edge = Edge {
vertices: original.vertices.map(|vertex| {
LocalForm::new(
*vertex.local() + [deviation],
vertex.canonical(),
)
}),
..original
}
});
let a = LocalForm::new(Point::from([Scalar::ZERO + deviation]), a);
let b = LocalForm::new(Point::from([Scalar::ONE]), b);
let vertices = VerticesOfEdge::from_vertices([a, b]);
let edge = Edge { curve, vertices };
let result = validate(
shape.clone(),
edge.clone(),
&ValidationConfig {
identical_max_distance: deviation * 2.,
..ValidationConfig::default()
@ -262,7 +263,7 @@ mod tests {
assert!(result.is_ok());
let result = validate(
shape,
edge,
&ValidationConfig {
identical_max_distance: deviation / 2.,
..ValidationConfig::default()