Skip to content

Commit

Permalink
Merge pull request #1774 from hannobraun/validate
Browse files Browse the repository at this point in the history
Clean up `Solid` validation code
  • Loading branch information
hannobraun authored Apr 20, 2023
2 parents 2108a91 + 8947cc9 commit 74d611d
Showing 1 changed file with 62 additions and 33 deletions.
95 changes: 62 additions & 33 deletions crates/fj-kernel/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,42 @@ pub enum SolidValidationError {
/// [`Solid`] contains vertices that are coincident, but not identical
#[error(
"Solid contains Vertices that are coincident but not identical\n
Vertex 1: {:#?} {:#?}
Vertex 2: {:#?} {:#?}
", .0[0].0, .0[0].1,.0[1].0,.0[1].1
Vertex 1: {vertex_a:#?} ({position_a:?})
Vertex 2: {vertex_b:#?} ({position_b:?})"
)]
DistinctVerticesCoincide([(Handle<Vertex>, Point<3>); 2]),
DistinctVerticesCoincide {
/// The first vertex
vertex_a: Handle<Vertex>,

/// The second vertex
vertex_b: Handle<Vertex>,

/// Position of first vertex
position_a: Point<3>,

/// Position of second vertex
position_b: Point<3>,
},

/// [`Solid`] contains vertices that are identical, but do not coincide
#[error(
"Solid contains Vertices that are identical but do not coincide\n
Vertex 1: {:#?} {:#?}
Vertex 2: {:#?} {:#?}
", .0[0].0, .0[0].1,.0[1].0,.0[1].1
Vertex 1: {vertex_a:#?} ({position_a:?})
Vertex 2: {vertex_b:#?} ({position_b:?})"
)]
IdenticalVerticesNotCoincident([(Handle<Vertex>, Point<3>); 2]),
IdenticalVerticesNotCoincident {
/// The first vertex
vertex_a: Handle<Vertex>,

/// The second vertex
vertex_b: Handle<Vertex>,

/// Position of first vertex
position_a: Point<3>,

/// Position of second vertex
position_b: Point<3>,
},
}

impl SolidValidationError {
Expand Down Expand Up @@ -65,33 +87,40 @@ impl SolidValidationError {
// This is O(N^2) which isn't great, but we can't use a HashMap since we
// need to deal with float inaccuracies. Maybe we could use some smarter
// data-structure like an octree.
for a in &vertices {
for b in &vertices {
match a.1.id() == b.1.id() {
true => {
if a.0.distance_to(&b.0) > config.identical_max_distance
{
errors.push(
Self::IdenticalVerticesNotCoincident([
(a.1.clone(), a.0),
(b.1.clone(), b.0),
])
.into(),
)
for (position_a, vertex_a) in &vertices {
for (position_b, vertex_b) in &vertices {
let vertices_are_identical = vertex_a.id() == vertex_b.id();
let vertices_are_not_identical = !vertices_are_identical;

let too_far_to_be_identical = position_a
.distance_to(position_b)
> config.identical_max_distance;
let too_close_to_be_distinct = position_a
.distance_to(position_b)
< config.distinct_min_distance;

if vertices_are_identical && too_far_to_be_identical {
errors.push(
Self::IdenticalVerticesNotCoincident {
vertex_a: vertex_a.clone(),
vertex_b: vertex_b.clone(),
position_a: *position_a,
position_b: *position_b,
}
}
false => {
if a.0.distance_to(&b.0) < config.distinct_min_distance
{
errors.push(
Self::DistinctVerticesCoincide([
(a.1.clone(), a.0),
(b.1.clone(), b.0),
])
.into(),
)
.into(),
)
}

if vertices_are_not_identical && too_close_to_be_distinct {
errors.push(
Self::DistinctVerticesCoincide {
vertex_a: vertex_a.clone(),
vertex_b: vertex_b.clone(),
position_a: *position_a,
position_b: *position_b,
}
}
.into(),
)
}
}
}
Expand Down

0 comments on commit 74d611d

Please sign in to comment.