From 259054bc5b40730470bb373e70157e70aeef484a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 26 Jan 2023 10:53:56 +0100 Subject: [PATCH 1/5] Refactor --- crates/fj-kernel/src/algorithms/approx/face.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/face.rs b/crates/fj-kernel/src/algorithms/approx/face.rs index 7a5d71ee4..52e4f9898 100644 --- a/crates/fj-kernel/src/algorithms/approx/face.rs +++ b/crates/fj-kernel/src/algorithms/approx/face.rs @@ -46,8 +46,8 @@ impl Approx for &FaceSet { if p.global_form != point.global_form && distance < min_distance { - let a = p; - let b = point; + let a = point; + let b = p; panic!( "Invalid approximation: \ From d74eb3dab5f4c3d5ef312ed313f1ac8b5c512a04 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 26 Jan 2023 10:54:16 +0100 Subject: [PATCH 2/5] Update variable name --- crates/fj-kernel/src/algorithms/approx/face.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/face.rs b/crates/fj-kernel/src/algorithms/approx/face.rs index 52e4f9898..8a8c8f2ab 100644 --- a/crates/fj-kernel/src/algorithms/approx/face.rs +++ b/crates/fj-kernel/src/algorithms/approx/face.rs @@ -39,15 +39,14 @@ impl Approx for &FaceSet { let approx: &FaceApprox = approx; for point in &approx.points() { - for p in &all_points { + for b in &all_points { let distance = - (p.global_form - point.global_form).magnitude(); + (b.global_form - point.global_form).magnitude(); - if p.global_form != point.global_form + if b.global_form != point.global_form && distance < min_distance { let a = point; - let b = p; panic!( "Invalid approximation: \ From e4d075bd3ce3eae58b988ebcfb8f03e7839d2121 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 26 Jan 2023 10:54:47 +0100 Subject: [PATCH 3/5] Update variable name --- crates/fj-kernel/src/algorithms/approx/face.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/face.rs b/crates/fj-kernel/src/algorithms/approx/face.rs index 8a8c8f2ab..6ee5c7080 100644 --- a/crates/fj-kernel/src/algorithms/approx/face.rs +++ b/crates/fj-kernel/src/algorithms/approx/face.rs @@ -38,16 +38,12 @@ impl Approx for &FaceSet { for approx in &approx { let approx: &FaceApprox = approx; - for point in &approx.points() { + for a in &approx.points() { for b in &all_points { - let distance = - (b.global_form - point.global_form).magnitude(); + let distance = (b.global_form - a.global_form).magnitude(); - if b.global_form != point.global_form - && distance < min_distance + if b.global_form != a.global_form && distance < min_distance { - let a = point; - panic!( "Invalid approximation: \ Distinct points are too close \ @@ -59,7 +55,7 @@ impl Approx for &FaceSet { } } - all_points.insert(point.clone()); + all_points.insert(a.clone()); } } From 827e3759e959aa91f89bb2733b4cf942454ce4ae Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 26 Jan 2023 11:02:35 +0100 Subject: [PATCH 4/5] Implement `Approx` for `&Handle` Instead of for `&HalfEdge`. This makes the object ID available within the implementation, where it can be used to set a source for the generated `ApproxPoint`. --- crates/fj-kernel/src/algorithms/approx/edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 58f6204a2..779992b38 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -5,7 +5,7 @@ //! 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}, @@ -13,7 +13,7 @@ use super::{ Approx, ApproxPoint, Tolerance, }; -impl Approx for &HalfEdge { +impl Approx for &Handle { type Approximation = HalfEdgeApprox; type Cache = CurveCache; From e03daae695d6b1b0ba718279a07f362210eb033c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 26 Jan 2023 11:04:24 +0100 Subject: [PATCH 5/5] Add more debug information to approximation Record the source of approximation points that come from the start vertex of a `HalfEdge`. --- crates/fj-kernel/src/algorithms/approx/edge.rs | 3 ++- crates/fj-kernel/src/algorithms/approx/mod.rs | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 779992b38..41376dac7 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -28,7 +28,8 @@ impl Approx for &Handle { 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); diff --git a/crates/fj-kernel/src/algorithms/approx/mod.rs b/crates/fj-kernel/src/algorithms/approx/mod.rs index acedb5665..85dcb1d0a 100644 --- a/crates/fj-kernel/src/algorithms/approx/mod.rs +++ b/crates/fj-kernel/src/algorithms/approx/mod.rs @@ -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 PartialOrd for ApproxPoint { pub trait Source: Any + Debug {} impl Source for (Handle, Point<1>) {} +impl Source for (Handle, Point<1>) {}