Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more unused parts of Shape #735

Merged
merged 5 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 1 addition & 54 deletions crates/fj-kernel/src/shape/api.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
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,
}

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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions crates/fj-kernel/src/shape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
9 changes: 0 additions & 9 deletions crates/fj-kernel/src/shape/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
}
Expand Down
20 changes: 0 additions & 20 deletions crates/fj-kernel/src/shape/update.rs

This file was deleted.

37 changes: 19 additions & 18 deletions crates/fj-kernel/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -262,7 +263,7 @@ mod tests {
assert!(result.is_ok());

let result = validate(
shape,
edge,
&ValidationConfig {
identical_max_distance: deviation / 2.,
..ValidationConfig::default()
Expand Down