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

Respect existing boundary when updating HalfEdge as line segment #1541

Merged
merged 4 commits into from
Jan 26, 2023
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
17 changes: 17 additions & 0 deletions crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ pub trait CurveBuilder {
&mut self,
points: [impl Into<Point<2>>; 2],
) -> SurfacePath;

/// Update partial curve to be a line, from provided points and line coords
///
/// Returns the updated path.
fn update_as_line_from_points_with_line_coords(
&mut self,
points: [(impl Into<Point<1>>, impl Into<Point<2>>); 2],
) -> SurfacePath;
}

impl CurveBuilder for PartialCurve {
Expand Down Expand Up @@ -82,4 +90,13 @@ impl CurveBuilder for PartialCurve {
self.path = Some(path.into());
path
}

fn update_as_line_from_points_with_line_coords(
&mut self,
points: [(impl Into<Point<1>>, impl Into<Point<2>>); 2],
) -> SurfacePath {
let path = SurfacePath::from_points_with_line_coords(points);
self.path = Some(path.into());
path
}
}
25 changes: 18 additions & 7 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
}

fn update_as_line_segment(&mut self) {
let boundary = self.vertices.each_ref_ext().map(|vertex| vertex.0);
let points_surface = self.vertices.each_ref_ext().map(|vertex| {
vertex
.1
Expand All @@ -158,13 +159,23 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.expect("Can't infer line segment without surface position")
});

self.curve
.write()
.update_as_line_from_points(points_surface);

for (vertex, position) in self.vertices.each_mut_ext().zip_ext([0., 1.])
{
vertex.0 = Some([position].into());
if let [Some(start), Some(end)] = boundary {
let boundary = [start, end];
self.curve
.write()
.update_as_line_from_points_with_line_coords(
boundary.zip_ext(points_surface),
);
} else {
self.curve
.write()
.update_as_line_from_points(points_surface);

for (vertex, position) in
self.vertices.each_mut_ext().zip_ext([0., 1.])
{
vertex.0 = Some([position].into());
}
}

self.infer_global_form();
Expand Down
7 changes: 7 additions & 0 deletions crates/fj-kernel/src/geometry/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ impl SurfacePath {
(Self::Line(line), coords)
}

/// Create a line from two points that include line coordinates
pub fn from_points_with_line_coords(
points: [(impl Into<Point<1>>, impl Into<Point<2>>); 2],
) -> Self {
Self::Line(Line::from_points_with_line_coords(points))
}

/// Convert a point on the path into surface coordinates
pub fn point_from_path_coords(
&self,
Expand Down
24 changes: 24 additions & 0 deletions crates/fj-math/src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,30 @@ mod tests {

use super::Line;

#[test]
fn from_points_with_line_coords() {
let line = Line::from_points_with_line_coords([
([0.], [0., 0.]),
([1.], [1., 0.]),
]);
assert_eq!(line.origin(), Point::from([0., 0.]));
assert_eq!(line.direction(), Vector::from([1., 0.]));

let line = Line::from_points_with_line_coords([
([1.], [0., 1.]),
([0.], [1., 1.]),
]);
assert_eq!(line.origin(), Point::from([1., 1.]));
assert_eq!(line.direction(), Vector::from([-1., 0.]));

let line = Line::from_points_with_line_coords([
([-1.], [0., 2.]),
([0.], [1., 2.]),
]);
assert_eq!(line.origin(), Point::from([1., 2.]));
assert_eq!(line.direction(), Vector::from([1., 0.]));
}

#[test]
fn is_coincident_with() {
let (line, _) = Line::from_points([[0., 0.], [1., 0.]]);
Expand Down