Prepare to support curved surfaces

This commit is contained in:
Hanno Braun 2025-02-28 21:10:48 +01:00
parent e593aa9760
commit 4a108d7b0a
5 changed files with 35 additions and 7 deletions

View File

@ -1,9 +1,11 @@
mod sketch;
mod surface;
mod tri_mesh;
mod triangle;
pub use self::{
sketch::Sketch,
surface::SurfaceGeometry,
tri_mesh::{MeshTriangle, TriMesh},
triangle::Triangle,
};

View File

@ -0,0 +1,26 @@
use crate::math::{Plane, Point, Vector};
pub trait SurfaceGeometry {
fn point_from_local(&self, point: Point<2>) -> Point<3>;
fn project_point(&self, point: Point<3>) -> Point<2>;
fn flip(&self) -> Box<dyn SurfaceGeometry>;
fn translate(&self, offset: Vector<3>) -> Box<dyn SurfaceGeometry>;
}
impl SurfaceGeometry for Plane {
fn point_from_local(&self, point: Point<2>) -> Point<3> {
self.point_from_local(point)
}
fn project_point(&self, point: Point<3>) -> Point<2> {
self.project_point(point)
}
fn flip(&self) -> Box<dyn SurfaceGeometry> {
Box::new((*self).flip())
}
fn translate(&self, offset: Vector<3>) -> Box<dyn SurfaceGeometry> {
Box::new((*self).translate(offset))
}
}

View File

@ -27,13 +27,13 @@ pub fn model() -> HandleAny {
]);
let surface = Handle::new(Surface {
geometry: Plane {
geometry: Box::new(Plane {
origin: Point::from([0., 0., 1.]),
coords: Bivector {
a: Vector::from([1., 0., 0.]),
b: Vector::from([0., 1., 0.]),
},
},
}),
});
let face = sketch.to_face(surface);

View File

@ -53,9 +53,9 @@ impl ConnectExt for Handle<Face> {
};
let surface = Handle::new(Surface {
geometry: Plane::from_points(
geometry: Box::new(Plane::from_points(
[&q.start, r, s].map(|vertex| vertex.point),
),
)),
});
let face = Face::new(
surface,

View File

@ -1,15 +1,15 @@
use std::fmt;
use crate::math::Plane;
use crate::geometry::SurfaceGeometry;
pub struct Surface {
pub geometry: Plane,
pub geometry: Box<dyn SurfaceGeometry>,
}
impl fmt::Debug for Surface {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Surface")
.field("geometry", &self.geometry)
.field("geometry", &"Box<dyn SurfaceGeometry>")
.finish()
}
}