mirror of
https://github.com/hannobraun/Fornjot
synced 2025-07-14 05:56:07 +00:00
Prepare to fully support swept curves
As far as `SweptCurve` is concerned, this is already the full extent of support that is required. However, triangulation doesn't fully support them yet. It would need to also approximate curves, in addition to approximating surfaces.
This commit is contained in:
parent
931f22f8ea
commit
d3a6685428
@ -1,12 +1,17 @@
|
||||
use fj_math::{Line, Point, Transform, Vector};
|
||||
|
||||
pub trait CurveGeometry {
|
||||
fn clone_curve_geometry(&self) -> Box<dyn CurveGeometry>;
|
||||
fn point_from_local(&self, point: Point<1>) -> Point<3>;
|
||||
fn project_point(&self, point: Point<3>) -> Point<1>;
|
||||
fn translate(&self, offset: Vector<3>) -> Box<dyn CurveGeometry>;
|
||||
}
|
||||
|
||||
impl CurveGeometry for Line<3> {
|
||||
fn clone_curve_geometry(&self) -> Box<dyn CurveGeometry> {
|
||||
Box::new(*self)
|
||||
}
|
||||
|
||||
fn point_from_local(&self, point: Point<1>) -> Point<3> {
|
||||
self.point_from_line_coords(point)
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
use fj_math::{Line, Point, Transform, Vector};
|
||||
use fj_math::{Line, Point, Vector};
|
||||
|
||||
use super::CurveGeometry;
|
||||
|
||||
pub struct SweptCurve {
|
||||
pub curve: Line<3>,
|
||||
pub curve: Box<dyn CurveGeometry>,
|
||||
pub path: Vector<3>,
|
||||
}
|
||||
|
||||
impl SweptCurve {
|
||||
pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self {
|
||||
let (curve, _) = Line::from_points([a, b]);
|
||||
Self { curve, path: c - a }
|
||||
Self {
|
||||
curve: Box::new(curve),
|
||||
path: c - a,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn v(&self) -> Vector<3> {
|
||||
@ -37,14 +40,14 @@ impl SweptCurve {
|
||||
|
||||
pub fn flip(&self) -> Self {
|
||||
Self {
|
||||
curve: self.curve,
|
||||
curve: self.curve.clone_curve_geometry(),
|
||||
path: -self.path,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate(&self, offset: impl Into<Vector<3>>) -> Self {
|
||||
Self {
|
||||
curve: self.curve.transform(&Transform::translation(offset)),
|
||||
curve: self.curve.translate(offset.into()),
|
||||
path: self.path,
|
||||
}
|
||||
}
|
||||
@ -59,7 +62,10 @@ mod tests {
|
||||
#[test]
|
||||
fn project_point() {
|
||||
let plane = SweptCurve {
|
||||
curve: Line::from_origin_and_direction([1., 1., 1.], [1., 0., 0.]),
|
||||
curve: Box::new(Line::from_origin_and_direction(
|
||||
[1., 1., 1.],
|
||||
[1., 0., 0.],
|
||||
)),
|
||||
path: Vector::from([0., 1., 0.]),
|
||||
};
|
||||
|
||||
|
@ -32,10 +32,10 @@ pub fn model(viewer: &Viewer) -> TriMesh {
|
||||
|
||||
let surface = Handle::new(Surface {
|
||||
geometry: Box::new(SweptCurve {
|
||||
curve: Line::from_origin_and_direction(
|
||||
curve: Box::new(Line::from_origin_and_direction(
|
||||
[0., 0., 1.],
|
||||
[1., 0., 0.],
|
||||
),
|
||||
)),
|
||||
path: Vector::from([0., 1., 0.]),
|
||||
}),
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user