Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more debug information to approximation #1537

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions crates/fj-kernel/src/algorithms/approx/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
15 changes: 5 additions & 10 deletions crates/fj-kernel/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -60,7 +55,7 @@ impl Approx for &FaceSet {
}
}

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

Expand Down
6 changes: 5 additions & 1 deletion crates/fj-kernel/src/algorithms/approx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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>) {}