mirror of
https://github.com/hannobraun/Fornjot
synced 2025-09-20 16:18:08 +00:00
Convert FloatingCurve
into struct
This commit is contained in:
parent
343221d30e
commit
2e5106fe12
@ -29,7 +29,9 @@ impl AnchoredCurve {
|
||||
) -> Self {
|
||||
Self {
|
||||
origin,
|
||||
floating: Box::new(curve),
|
||||
floating: FloatingCurve {
|
||||
inner: Box::new(curve),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,17 +52,19 @@ impl AnchoredCurve {
|
||||
}
|
||||
|
||||
pub fn point_from_local(&self, point: impl Into<Point<1>>) -> Point<3> {
|
||||
self.origin + self.floating.vector_from_local_point(point.into())
|
||||
self.origin + self.floating.inner.vector_from_local_point(point.into())
|
||||
}
|
||||
|
||||
pub fn project_point(&self, point: Point<3>) -> Point<1> {
|
||||
self.floating.project_vector(point - self.origin)
|
||||
self.floating.inner.project_vector(point - self.origin)
|
||||
}
|
||||
|
||||
pub fn translate(&self, offset: impl Into<Vector<3>>) -> Self {
|
||||
Self {
|
||||
origin: self.origin + offset,
|
||||
floating: self.floating.clone_curve_geometry(),
|
||||
floating: FloatingCurve {
|
||||
inner: self.floating.inner.clone_curve_geometry(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +73,7 @@ impl AnchoredCurve {
|
||||
boundary: [Point<1>; 2],
|
||||
tolerance: Tolerance,
|
||||
) -> Vec<Point<1>> {
|
||||
self.floating.approximate(boundary, tolerance)
|
||||
self.floating.inner.approximate(boundary, tolerance)
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,12 +81,16 @@ impl Clone for AnchoredCurve {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
origin: self.origin,
|
||||
floating: self.floating.clone_curve_geometry(),
|
||||
floating: FloatingCurve {
|
||||
inner: self.floating.inner.clone_curve_geometry(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type FloatingCurve = Box<dyn CurveGeometry>;
|
||||
pub struct FloatingCurve {
|
||||
pub inner: Box<dyn CurveGeometry>,
|
||||
}
|
||||
|
||||
pub trait CurveGeometry {
|
||||
fn clone_curve_geometry(&self) -> Box<dyn CurveGeometry>;
|
||||
|
@ -17,7 +17,7 @@ impl SweptCurve {
|
||||
|
||||
Self {
|
||||
u: AnchoredCurve::from_origin_and_curve(origin, u),
|
||||
v: Box::new(v),
|
||||
v: FloatingCurve { inner: Box::new(v) },
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ impl SweptCurve {
|
||||
pub fn point_from_local(&self, point: impl Into<Point<2>>) -> Point<3> {
|
||||
let [u, v] = point.into().coords.components;
|
||||
self.u.point_from_local([u])
|
||||
+ self.v.vector_from_local_point(Point::from([v]))
|
||||
+ self.v.inner.vector_from_local_point(Point::from([v]))
|
||||
}
|
||||
|
||||
pub fn project_point(&self, point: impl Into<Point<3>>) -> Point<2> {
|
||||
@ -39,7 +39,9 @@ impl SweptCurve {
|
||||
let v = {
|
||||
let v = AnchoredCurve {
|
||||
origin: self.u.point_from_local(u),
|
||||
floating: self.v.clone_curve_geometry(),
|
||||
floating: FloatingCurve {
|
||||
inner: self.v.inner.clone_curve_geometry(),
|
||||
},
|
||||
};
|
||||
|
||||
v.project_point(point)
|
||||
@ -51,14 +53,18 @@ impl SweptCurve {
|
||||
pub fn flip(&self) -> Self {
|
||||
Self {
|
||||
u: self.u.clone(),
|
||||
v: self.v.flip(),
|
||||
v: FloatingCurve {
|
||||
inner: self.v.inner.flip(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate(&self, offset: impl Into<Vector<3>>) -> Self {
|
||||
Self {
|
||||
u: self.u.translate(offset),
|
||||
v: self.v.clone_curve_geometry(),
|
||||
v: FloatingCurve {
|
||||
inner: self.v.inner.clone_curve_geometry(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use fj_math::Vector;
|
||||
use fj_viewer::Viewer;
|
||||
|
||||
use crate::{
|
||||
geometry::{Line, Sketch, SweptCurve, ToTriMesh},
|
||||
geometry::{FloatingCurve, Line, Sketch, SweptCurve, ToTriMesh},
|
||||
handle::Handle,
|
||||
operations::sweep::SweepExt,
|
||||
topology::surface::Surface,
|
||||
@ -45,9 +45,11 @@ pub fn model(viewer: &Viewer) -> TriMesh {
|
||||
viewer.display(top.to_tri_mesh(tolerance));
|
||||
|
||||
let solid = top.sweep(
|
||||
Box::new(Line {
|
||||
direction: Vector::from([0., 0., -2.]),
|
||||
}),
|
||||
FloatingCurve {
|
||||
inner: Box::new(Line {
|
||||
direction: Vector::from([0., 0., -2.]),
|
||||
}),
|
||||
},
|
||||
[1.],
|
||||
);
|
||||
viewer.display(solid.to_tri_mesh(tolerance));
|
||||
|
@ -88,7 +88,9 @@ fn build_connecting_faces(
|
||||
let curve = Curve {
|
||||
geometry: AnchoredCurve {
|
||||
origin: a.point,
|
||||
floating: connecting_curve.clone_curve_geometry(),
|
||||
floating: FloatingCurve {
|
||||
inner: connecting_curve.inner.clone_curve_geometry(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ pub trait SweepExt {
|
||||
impl SweepExt for Handle<Face> {
|
||||
fn sweep(self, along: FloatingCurve, to: impl Into<Point<1>>) -> Solid {
|
||||
let [from, to] = [Point::from([0.]), to.into()]
|
||||
.map(|point| along.vector_from_local_point(point));
|
||||
.map(|point| along.inner.vector_from_local_point(point));
|
||||
|
||||
let bottom = self;
|
||||
let top = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user