Skip to content

Commit

Permalink
Return coords from SurfaceBuilder method
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Dec 16, 2022
1 parent 9a2c168 commit bedf2fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl ShellBuilder for PartialShell {
});
let c = a + [Z, Z, edge_length];

let surface = PartialSurface::plane_from_points([a, b, c]);
let (surface, _) =
PartialSurface::plane_from_points([a, b, c]);
Partial::from_partial(surface)
})
.collect::<Vec<_>>();
Expand Down
27 changes: 20 additions & 7 deletions crates/fj-kernel/src/builder/surface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fj_math::{Point, Vector};
use fj_math::{Point, Scalar, Vector};

use crate::{
geometry::{path::GlobalPath, surface::SurfaceGeometry},
Expand All @@ -11,7 +11,9 @@ pub trait SurfaceBuilder: Sized {
fn from_axes(u: GlobalPath, v: impl Into<Vector<3>>) -> Self;

/// Construct a plane from 3 points
fn plane_from_points(points: [impl Into<Point<3>>; 3]) -> Self;
fn plane_from_points(
points: [impl Into<Point<3>>; 3],
) -> (Self, [Point<2>; 3]);
}

impl SurfaceBuilder for PartialSurface {
Expand All @@ -23,14 +25,25 @@ impl SurfaceBuilder for PartialSurface {
}
}

fn plane_from_points(points: [impl Into<Point<3>>; 3]) -> Self {
fn plane_from_points(
points: [impl Into<Point<3>>; 3],
) -> (Self, [Point<2>; 3]) {
let [a, b, c] = points.map(Into::into);

let (u, _) = GlobalPath::line_from_points([a, b]);
let (u, u_coords) = GlobalPath::line_from_points([a, b]);
let v = c - a;

Self {
geometry: Some(SurfaceGeometry { u, v }),
}
let coords = {
let [a, b] = u_coords.map(|point| point.t);
[[a, Scalar::ZERO], [b, Scalar::ZERO], [a, Scalar::ONE]]
.map(Point::from)
};

(
Self {
geometry: Some(SurfaceGeometry { u, v }),
},
coords,
)
}
}

0 comments on commit bedf2fd

Please sign in to comment.