Prepare to support other curves beside lines

This commit is contained in:
Hanno Braun 2025-04-07 13:07:51 +02:00
parent 2cb597c31e
commit 313d9713f0
2 changed files with 15 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use fj_math::Vector;
use fj_math::{Line, Transform, Vector};
pub trait CurveGeometry {
fn translate(&self, offset: Vector<3>) -> Box<dyn CurveGeometry>;
@ -9,3 +9,10 @@ impl CurveGeometry for () {
Box::new(())
}
}
impl CurveGeometry for Line<3> {
fn translate(&self, offset: Vector<3>) -> Box<dyn CurveGeometry> {
let translated = self.transform(&Transform::translation(offset));
Box::new(translated)
}
}

View File

@ -1,3 +1,5 @@
use fj_math::Line;
use crate::geometry::CurveGeometry;
use super::vertex::Vertex;
@ -7,9 +9,12 @@ pub struct Curve {
}
impl Curve {
pub fn line_from_vertices(_: [&Vertex; 2]) -> Self {
pub fn line_from_vertices(vertices: [&Vertex; 2]) -> Self {
let points = vertices.map(|vertex| vertex.point);
let (line, _) = Line::from_points(points);
Self {
geometry: Box::new(()),
geometry: Box::new(line),
}
}
}