Skip to content

Commit

Permalink
Merge pull request #1456 from hannobraun/surface
Browse files Browse the repository at this point in the history
Return surface coordinates from `Surface::from_points`
  • Loading branch information
hannobraun authored Dec 16, 2022
2 parents 3f6cab7 + bedf2fd commit 6d5cf8f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Sweep for (Handle<Vertex>, Handle<Surface>) {
// Armed with those coordinates, creating the `Curve` of the output
// `Edge` is straight-forward.
let curve = {
let path = SurfacePath::line_from_points(points_surface);
let (path, _) = SurfacePath::line_from_points(points_surface);

Curve::new(surface.clone(), path, edge_global.curve().clone())
.insert(objects)
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl CurveBuilder for PartialCurve {
}

fn update_as_line_from_points(&mut self, points: [impl Into<Point<2>>; 2]) {
self.path = Some(SurfacePath::line_from_points(points));
let (path, _) = SurfacePath::line_from_points(points);
self.path = Some(path);
}
}
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
29 changes: 21 additions & 8 deletions crates/fj-kernel/src/builder/surface.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use fj_math::{Point, Vector};
use fj_math::{Point, Scalar, Vector};

use crate::{
geometry::{path::GlobalPath, surface::SurfaceGeometry},
partial::PartialSurface,
};

/// Builder API for [`PartialSurface`]
pub trait SurfaceBuilder {
pub trait SurfaceBuilder: Sized {
/// Build a surface from its two axes
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,
)
}
}
20 changes: 14 additions & 6 deletions crates/fj-kernel/src/geometry/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ impl SurfacePath {
}

/// Construct a line from two points
pub fn line_from_points(points: [impl Into<Point<2>>; 2]) -> Self {
let (line, _) = Line::from_points(points);
Self::Line(line)
///
/// Also returns the coordinates of the points on the path.
pub fn line_from_points(
points: [impl Into<Point<2>>; 2],
) -> (Self, [Point<1>; 2]) {
let (line, coords) = Line::from_points(points);
(Self::Line(line), coords)
}

/// Convert a point on the path into surface coordinates
Expand Down Expand Up @@ -103,9 +107,13 @@ impl GlobalPath {
}

/// Construct a line from two points
pub fn line_from_points(points: [impl Into<Point<3>>; 2]) -> Self {
let (line, _) = Line::from_points(points);
Self::Line(line)
///
/// Also returns the coordinates of the points on the path.
pub fn line_from_points(
points: [impl Into<Point<3>>; 2],
) -> (Self, [Point<1>; 2]) {
let (line, coords) = Line::from_points(points);
(Self::Line(line), coords)
}

/// Access the origin of the path's coordinate system
Expand Down

0 comments on commit 6d5cf8f

Please sign in to comment.