Skip to content

Commit

Permalink
Merge pull request #1541 from hannobraun/builder
Browse files Browse the repository at this point in the history
Respect existing boundary when updating `HalfEdge` as line segment
  • Loading branch information
hannobraun authored Jan 26, 2023
2 parents b217664 + 88821a6 commit 691e90b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
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

0 comments on commit 691e90b

Please sign in to comment.