Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return surface coordinates from Surface::from_points #1456

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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