Skip to content

Commit

Permalink
Add validation code to Faces approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 8, 2022
1 parent c1761b5 commit f28c7c0
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,55 @@ use std::collections::BTreeSet;

use fj_interop::mesh::Color;

use crate::objects::{Face, Faces};
use crate::{
algorithms::validate::ValidationConfig,
objects::{Face, Faces},
};

use super::{cycle::CycleApprox, Approx, ApproxPoint, Tolerance};

impl Approx for &Faces {
type Approximation = BTreeSet<FaceApprox>;

fn approx(self, tolerance: Tolerance) -> Self::Approximation {
self.into_iter()
let approx = self
.into_iter()
.map(|face| face.approx(tolerance))
.collect()
.collect();

let min_distance = ValidationConfig::default().distinct_min_distance;
let mut all_points: BTreeSet<ApproxPoint<2>> = BTreeSet::new();

for approx in &approx {
let approx: &FaceApprox = approx;

for point in &approx.points() {
for p in &all_points {
let distance =
(p.global_form - point.global_form).magnitude();

if p.global_form != point.global_form
&& distance < min_distance
{
let a = p;
let b = point;

panic!(
"Invalid approximation: \
Distinct points are too close \
(a: {:?}, b: {:?}, distance: {distance})\n\
source of `a`: {:#?}\n\
source of `b`: {:#?}\n",
a.global_form, b.global_form, a.source, b.source
);
}
}

all_points.insert(point.clone());
}
}

approx
}
}

Expand Down

0 comments on commit f28c7c0

Please sign in to comment.