mirror of
https://github.com/hannobraun/Fornjot
synced 2025-07-22 18:06:05 +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};
|
use fj_math::{Line, Point, Transform, Vector};
|
||||||
|
|
||||||
pub trait CurveGeometry {
|
pub trait CurveGeometry {
|
||||||
|
fn clone_curve_geometry(&self) -> Box<dyn CurveGeometry>;
|
||||||
fn point_from_local(&self, point: Point<1>) -> Point<3>;
|
fn point_from_local(&self, point: Point<1>) -> Point<3>;
|
||||||
fn project_point(&self, point: Point<3>) -> Point<1>;
|
fn project_point(&self, point: Point<3>) -> Point<1>;
|
||||||
fn translate(&self, offset: Vector<3>) -> Box<dyn CurveGeometry>;
|
fn translate(&self, offset: Vector<3>) -> Box<dyn CurveGeometry>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CurveGeometry for Line<3> {
|
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> {
|
fn point_from_local(&self, point: Point<1>) -> Point<3> {
|
||||||
self.point_from_line_coords(point)
|
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;
|
use super::CurveGeometry;
|
||||||
|
|
||||||
pub struct SweptCurve {
|
pub struct SweptCurve {
|
||||||
pub curve: Line<3>,
|
pub curve: Box<dyn CurveGeometry>,
|
||||||
pub path: Vector<3>,
|
pub path: Vector<3>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SweptCurve {
|
impl SweptCurve {
|
||||||
pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self {
|
pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self {
|
||||||
let (curve, _) = Line::from_points([a, b]);
|
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> {
|
pub fn v(&self) -> Vector<3> {
|
||||||
@ -37,14 +40,14 @@ impl SweptCurve {
|
|||||||
|
|
||||||
pub fn flip(&self) -> Self {
|
pub fn flip(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
curve: self.curve,
|
curve: self.curve.clone_curve_geometry(),
|
||||||
path: -self.path,
|
path: -self.path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn translate(&self, offset: impl Into<Vector<3>>) -> Self {
|
pub fn translate(&self, offset: impl Into<Vector<3>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
curve: self.curve.transform(&Transform::translation(offset)),
|
curve: self.curve.translate(offset.into()),
|
||||||
path: self.path,
|
path: self.path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +62,10 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn project_point() {
|
fn project_point() {
|
||||||
let plane = SweptCurve {
|
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.]),
|
path: Vector::from([0., 1., 0.]),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,10 +32,10 @@ pub fn model(viewer: &Viewer) -> TriMesh {
|
|||||||
|
|
||||||
let surface = Handle::new(Surface {
|
let surface = Handle::new(Surface {
|
||||||
geometry: Box::new(SweptCurve {
|
geometry: Box::new(SweptCurve {
|
||||||
curve: Line::from_origin_and_direction(
|
curve: Box::new(Line::from_origin_and_direction(
|
||||||
[0., 0., 1.],
|
[0., 0., 1.],
|
||||||
[1., 0., 0.],
|
[1., 0., 0.],
|
||||||
),
|
)),
|
||||||
path: Vector::from([0., 1., 0.]),
|
path: Vector::from([0., 1., 0.]),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user