From af589bde5e5050ad089e3082f0ed3e4c372f9092 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 5 May 2025 12:01:33 +0200 Subject: [PATCH] Add `FloatingCurve::new` --- experiments/2025-03-18/src/geometry/curve.rs | 11 ++++++++--- experiments/2025-03-18/src/geometry/swept_curve.rs | 2 +- experiments/2025-03-18/src/model.rs | 8 +++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/experiments/2025-03-18/src/geometry/curve.rs b/experiments/2025-03-18/src/geometry/curve.rs index 7a5f030f6..8273c8c20 100644 --- a/experiments/2025-03-18/src/geometry/curve.rs +++ b/experiments/2025-03-18/src/geometry/curve.rs @@ -29,9 +29,7 @@ impl AnchoredCurve { ) -> Self { Self { origin, - floating: FloatingCurve { - inner: Box::new(curve), - }, + floating: FloatingCurve::new(curve), } } @@ -91,6 +89,13 @@ impl Clone for AnchoredCurve { pub struct FloatingCurve { pub inner: Box, } +impl FloatingCurve { + pub fn new(curve: impl CurveGeometry + 'static) -> Self { + Self { + inner: Box::new(curve), + } + } +} pub trait CurveGeometry { fn clone_curve_geometry(&self) -> Box; diff --git a/experiments/2025-03-18/src/geometry/swept_curve.rs b/experiments/2025-03-18/src/geometry/swept_curve.rs index c032344fa..c73908506 100644 --- a/experiments/2025-03-18/src/geometry/swept_curve.rs +++ b/experiments/2025-03-18/src/geometry/swept_curve.rs @@ -17,7 +17,7 @@ impl SweptCurve { Self { u: AnchoredCurve::from_origin_and_curve(origin, u), - v: FloatingCurve { inner: Box::new(v) }, + v: FloatingCurve::new(v), } } diff --git a/experiments/2025-03-18/src/model.rs b/experiments/2025-03-18/src/model.rs index dd6368e4a..eae71054f 100644 --- a/experiments/2025-03-18/src/model.rs +++ b/experiments/2025-03-18/src/model.rs @@ -45,11 +45,9 @@ pub fn model(viewer: &Viewer) -> TriMesh { viewer.display(top.to_tri_mesh(tolerance)); let solid = top.sweep( - FloatingCurve { - inner: Box::new(Line { - direction: Vector::from([0., 0., -2.]), - }), - }, + FloatingCurve::new(Line { + direction: Vector::from([0., 0., -2.]), + }), [1.], ); viewer.display(solid.to_tri_mesh(tolerance));