mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-06 10:58:28 +00:00
Merge pull request #2389 from hannobraun/validation
Make some cleanups in validation code
This commit is contained in:
commit
a38f8674c3
@ -3,12 +3,12 @@ use std::fmt;
|
|||||||
use fj_math::{Point, Scalar};
|
use fj_math::{Point, Scalar};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
geometry::{CurveBoundary, Geometry, SurfaceGeom},
|
geometry::{CurveBoundary, Geometry},
|
||||||
queries::{
|
queries::{
|
||||||
AllHalfEdgesWithSurface, BoundingVerticesOfHalfEdge, SiblingOfHalfEdge,
|
AllHalfEdgesWithSurface, BoundingVerticesOfHalfEdge, SiblingOfHalfEdge,
|
||||||
},
|
},
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
topology::{Curve, HalfEdge, Shell, Vertex},
|
topology::{Curve, HalfEdge, Shell, Surface, Vertex},
|
||||||
validation::ValidationCheck,
|
validation::ValidationCheck,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -128,9 +128,9 @@ impl ValidationCheck<Shell> for CoincidentHalfEdgesAreNotSiblings {
|
|||||||
// `distinct_min_distance`, that's a problem.
|
// `distinct_min_distance`, that's a problem.
|
||||||
if distances(
|
if distances(
|
||||||
half_edge_a.clone(),
|
half_edge_a.clone(),
|
||||||
geometry.of_surface(surface_a),
|
surface_a,
|
||||||
half_edge_b.clone(),
|
half_edge_b.clone(),
|
||||||
geometry.of_surface(surface_b),
|
surface_b,
|
||||||
geometry,
|
geometry,
|
||||||
)
|
)
|
||||||
.all(|d| d < config.distinct_min_distance)
|
.all(|d| d < config.distinct_min_distance)
|
||||||
@ -169,24 +169,25 @@ impl ValidationCheck<Shell> for CoincidentHalfEdgesAreNotSiblings {
|
|||||||
///
|
///
|
||||||
/// Returns an [`Iterator`] of the distance at each sample.
|
/// Returns an [`Iterator`] of the distance at each sample.
|
||||||
fn distances(
|
fn distances(
|
||||||
edge_a: Handle<HalfEdge>,
|
half_edge_a: Handle<HalfEdge>,
|
||||||
surface_a: &SurfaceGeom,
|
surface_a: &Handle<Surface>,
|
||||||
edge_b: Handle<HalfEdge>,
|
half_edge_b: Handle<HalfEdge>,
|
||||||
surface_b: &SurfaceGeom,
|
surface_b: &Handle<Surface>,
|
||||||
geometry: &Geometry,
|
geometry: &Geometry,
|
||||||
) -> impl Iterator<Item = Scalar> {
|
) -> impl Iterator<Item = Scalar> {
|
||||||
fn sample(
|
fn sample(
|
||||||
percent: f64,
|
percent: f64,
|
||||||
(edge, surface): (&Handle<HalfEdge>, &SurfaceGeom),
|
half_edge: &Handle<HalfEdge>,
|
||||||
|
surface: &Handle<Surface>,
|
||||||
geometry: &Geometry,
|
geometry: &Geometry,
|
||||||
) -> Point<3> {
|
) -> Point<3> {
|
||||||
let [start, end] = geometry.of_half_edge(edge).boundary.inner;
|
let [start, end] = geometry.of_half_edge(half_edge).boundary.inner;
|
||||||
let path_coords = start + (end - start) * percent;
|
let path_coords = start + (end - start) * percent;
|
||||||
let surface_coords = geometry
|
let path = geometry.of_half_edge(half_edge).path;
|
||||||
.of_half_edge(edge)
|
let surface_coords = path.point_from_path_coords(path_coords);
|
||||||
.path
|
geometry
|
||||||
.point_from_path_coords(path_coords);
|
.of_surface(surface)
|
||||||
surface.point_from_surface_coords(surface_coords)
|
.point_from_surface_coords(surface_coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Three samples (start, middle, end), are enough to detect weather lines
|
// Three samples (start, middle, end), are enough to detect weather lines
|
||||||
@ -198,8 +199,8 @@ fn distances(
|
|||||||
let mut distances = Vec::new();
|
let mut distances = Vec::new();
|
||||||
for i in 0..sample_count {
|
for i in 0..sample_count {
|
||||||
let percent = i as f64 * step;
|
let percent = i as f64 * step;
|
||||||
let sample1 = sample(percent, (&edge_a, surface_a), geometry);
|
let sample1 = sample(percent, &half_edge_a, surface_a, geometry);
|
||||||
let sample2 = sample(1.0 - percent, (&edge_b, surface_b), geometry);
|
let sample2 = sample(1.0 - percent, &half_edge_b, surface_b, geometry);
|
||||||
distances.push(sample1.distance_to(&sample2))
|
distances.push(sample1.distance_to(&sample2))
|
||||||
}
|
}
|
||||||
distances.into_iter()
|
distances.into_iter()
|
||||||
|
@ -179,7 +179,6 @@ impl<T, U> ReferenceCounter<T, U> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
assert_contains_err,
|
|
||||||
operations::{
|
operations::{
|
||||||
build::{BuildShell, BuildSketch, BuildSolid},
|
build::{BuildShell, BuildSketch, BuildSolid},
|
||||||
update::{
|
update::{
|
||||||
@ -188,11 +187,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
topology::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid},
|
topology::{Cycle, Face, HalfEdge, Region, Shell, Sketch, Solid},
|
||||||
validate::Validate,
|
validation::{checks::MultipleReferencesToObject, ValidationCheck},
|
||||||
validation::{
|
|
||||||
checks::MultipleReferencesToObject, ValidationCheck,
|
|
||||||
ValidationError,
|
|
||||||
},
|
|
||||||
Core,
|
Core,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -412,12 +407,6 @@ mod tests {
|
|||||||
&core.layers.geometry,
|
&core.layers.geometry,
|
||||||
).is_err());
|
).is_err());
|
||||||
|
|
||||||
assert_contains_err!(
|
|
||||||
core,
|
|
||||||
invalid,
|
|
||||||
ValidationError::MultipleReferencesToCycle(_)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ignore remaining validation errors.
|
// Ignore remaining validation errors.
|
||||||
let _ = core.layers.validation.take_errors();
|
let _ = core.layers.validation.take_errors();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user