Merge CurveApprox into HalfEdgeApprox

This commit is contained in:
Hanno Braun 2023-02-22 12:14:49 +01:00
parent e25c3ee696
commit 9ac29b0613
2 changed files with 13 additions and 42 deletions

View File

@ -18,29 +18,6 @@ use crate::{
use super::{path::RangeOnPath, ApproxPoint}; use super::{path::RangeOnPath, ApproxPoint};
/// An approximation of a [`Curve`]
#[derive(Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct CurveApprox {
/// The points that approximate the curve
pub points: Vec<ApproxPoint<2>>,
}
impl CurveApprox {
/// Create an empty instance of `CurveApprox`
pub fn empty() -> Self {
Self { points: Vec::new() }
}
/// Add points to the approximation
pub fn with_points(
mut self,
points: impl IntoIterator<Item = ApproxPoint<2>>,
) -> Self {
self.points.extend(points);
self
}
}
/// A cache for results of an approximation /// A cache for results of an approximation
#[derive(Default)] #[derive(Default)]
pub struct CurveCache { pub struct CurveCache {

View File

@ -12,7 +12,7 @@ use crate::{
}; };
use super::{ use super::{
curve::{CurveApprox, CurveCache, GlobalCurveApprox}, curve::{CurveCache, GlobalCurveApprox},
path::RangeOnPath, path::RangeOnPath,
Approx, ApproxPoint, Tolerance, Approx, ApproxPoint, Tolerance,
}; };
@ -57,8 +57,10 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {
} }
}; };
CurveApprox::empty().with_points( global_curve_approx
global_curve_approx.points.into_iter().map(|point| { .points
.into_iter()
.map(|point| {
let point_surface = half_edge let point_surface = half_edge
.curve() .curve()
.path() .path()
@ -69,8 +71,8 @@ impl Approx for (&Handle<HalfEdge>, &Surface) {
half_edge.curve().clone(), half_edge.curve().clone(),
point.local_form, point.local_form,
)) ))
}), })
) .collect()
}; };
HalfEdgeApprox { HalfEdgeApprox {
@ -87,7 +89,7 @@ pub struct HalfEdgeApprox {
pub first: ApproxPoint<2>, pub first: ApproxPoint<2>,
/// The approximation of the edge's curve /// The approximation of the edge's curve
pub curve_approx: CurveApprox, pub curve_approx: Vec<ApproxPoint<2>>,
} }
impl HalfEdgeApprox { impl HalfEdgeApprox {
@ -96,7 +98,7 @@ impl HalfEdgeApprox {
let mut points = Vec::new(); let mut points = Vec::new();
points.push(self.first.clone()); points.push(self.first.clone());
points.extend(self.curve_approx.points.clone()); points.extend(self.curve_approx.clone());
points points
} }
@ -193,8 +195,6 @@ mod tests {
services::Services, services::Services,
}; };
use super::CurveApprox;
#[test] #[test]
fn approx_line_on_flat_surface() { fn approx_line_on_flat_surface() {
let mut services = Services::new(); let mut services = Services::new();
@ -214,7 +214,7 @@ mod tests {
let tolerance = 1.; let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance); let approx = (&half_edge, surface.deref()).approx(tolerance);
assert_eq!(approx.curve_approx, CurveApprox::empty()); assert_eq!(approx.curve_approx, Vec::new());
} }
#[test] #[test]
@ -241,7 +241,7 @@ mod tests {
let tolerance = 1.; let tolerance = 1.;
let approx = (&half_edge, surface.deref()).approx(tolerance); let approx = (&half_edge, surface.deref()).approx(tolerance);
assert_eq!(approx.curve_approx, CurveApprox::empty()); assert_eq!(approx.curve_approx, Vec::new());
} }
#[test] #[test]
@ -285,10 +285,7 @@ mod tests {
ApproxPoint::new(point_surface, point_global) ApproxPoint::new(point_surface, point_global)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!( assert_eq!(approx.curve_approx, expected_approx);
approx.curve_approx,
CurveApprox::empty().with_points(expected_approx)
);
} }
#[test] #[test]
@ -321,9 +318,6 @@ mod tests {
ApproxPoint::new(point_surface, point_global) ApproxPoint::new(point_surface, point_global)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!( assert_eq!(approx.curve_approx, expected_approx);
approx.curve_approx,
CurveApprox::empty().with_points(expected_approx)
);
} }
} }