Skip to content

Commit

Permalink
Merge pull request #1537 from hannobraun/approx
Browse files Browse the repository at this point in the history
Add more debug information to approximation
hannobraun authored Jan 26, 2023
2 parents 04f69bb + e03daae commit 8dc0d50
Showing 3 changed files with 14 additions and 14 deletions.
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
@@ -5,15 +5,15 @@
//! approximations are usually used to build cycle approximations, and this way,
//! the caller doesn't have to call with duplicate vertices.
use crate::objects::HalfEdge;
use crate::{objects::HalfEdge, storage::Handle};

use super::{
curve::{CurveApprox, CurveCache},
path::RangeOnPath,
Approx, ApproxPoint, Tolerance,
};

impl Approx for &HalfEdge {
impl Approx for &Handle<HalfEdge> {
type Approximation = HalfEdgeApprox;
type Cache = CurveCache;

@@ -28,7 +28,8 @@ impl Approx for &HalfEdge {
let first = ApproxPoint::new(
self.start_vertex().position(),
self.start_vertex().global_form().position(),
);
)
.with_source((self.clone(), self.boundary()[0]));
let curve_approx =
(self.curve(), range).approx_with_cache(tolerance, cache);

15 changes: 5 additions & 10 deletions crates/fj-kernel/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
@@ -38,17 +38,12 @@ impl Approx for &FaceSet {
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();
for a in &approx.points() {
for b in &all_points {
let distance = (b.global_form - a.global_form).magnitude();

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

panic!(
"Invalid approximation: \
Distinct points are too close \
@@ -60,7 +55,7 @@ impl Approx for &FaceSet {
}
}

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

6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/approx/mod.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,10 @@ use std::{

use fj_math::Point;

use crate::{objects::Curve, storage::Handle};
use crate::{
objects::{Curve, HalfEdge},
storage::Handle,
};

pub use self::tolerance::{InvalidTolerance, Tolerance};

@@ -120,3 +123,4 @@ impl<const D: usize> PartialOrd for ApproxPoint<D> {
pub trait Source: Any + Debug {}

impl Source for (Handle<Curve>, Point<1>) {}
impl Source for (Handle<HalfEdge>, Point<1>) {}

0 comments on commit 8dc0d50

Please sign in to comment.