Skip to content

Commit

Permalink
Merge pull request #2336 from hannobraun/boundary
Browse files Browse the repository at this point in the history
Implement `Default` for `CurveBoundary<Point<1>>`
  • Loading branch information
hannobraun authored Apr 29, 2024
2 parents 0e66402 + 5c55815 commit 17180dc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
8 changes: 8 additions & 0 deletions crates/fj-core/src/geometry/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ impl<T: CurveBoundaryElement> CurveBoundary<T> {
}
}

impl Default for CurveBoundary<Point<1>> {
fn default() -> Self {
Self {
inner: [[0.], [1.]].map(Point::from),
}
}
}

impl<S, T: CurveBoundaryElement> From<[S; 2]> for CurveBoundary<T>
where
S: Into<T::Repr>,
Expand Down
14 changes: 5 additions & 9 deletions crates/fj-core/src/operations/build/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use fj_interop::ext::ArrayExt;
use fj_math::{Arc, Point, Scalar};

use crate::{
geometry::{HalfEdgeGeom, LocalCurveGeom, SurfacePath},
geometry::{CurveBoundary, HalfEdgeGeom, LocalCurveGeom, SurfacePath},
operations::{geometry::UpdateHalfEdgeGeometry, insert::Insert},
storage::Handle,
topology::{Curve, HalfEdge, Surface, Vertex},
Expand Down Expand Up @@ -111,14 +111,13 @@ pub trait BuildHalfEdge {
/// Create a line segment
fn line_segment(
points_surface: [impl Into<Point<2>>; 2],
boundary: Option<[Point<1>; 2]>,
boundary: Option<CurveBoundary<Point<1>>>,
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
let boundary =
boundary.unwrap_or_else(|| [[0.], [1.]].map(Point::from));
let boundary = boundary.unwrap_or_default();
let path = SurfacePath::line_from_points_with_coords(
boundary.zip_ext(points_surface),
boundary.inner.zip_ext(points_surface),
);

let half_edge = HalfEdge::unjoined(core).insert(core);
Expand All @@ -130,10 +129,7 @@ pub trait BuildHalfEdge {
);
core.layers.geometry.define_half_edge(
half_edge.clone(),
HalfEdgeGeom {
path,
boundary: boundary.into(),
},
HalfEdgeGeom { path, boundary },
);

half_edge
Expand Down
8 changes: 2 additions & 6 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ pub trait BuildShell {
.cloned()
.unwrap_or_else(|| {
let curve = Curve::new().insert(core);
let boundary =
CurveBoundary::<Point<1>>::from([
[0.],
[1.],
]);
let boundary = CurveBoundary::default();

curves.insert(
vertices,
Expand All @@ -94,7 +90,7 @@ pub trait BuildShell {
.map(|((vertex, positions), (curve, boundary))| {
let half_edge = HalfEdge::line_segment(
positions,
Some(boundary.reverse().inner),
Some(boundary.reverse()),
surface.clone(),
core,
);
Expand Down
3 changes: 2 additions & 1 deletion crates/fj-core/src/operations/sweep/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use fj_interop::{ext::ArrayExt, Color};
use fj_math::{Point, Scalar, Vector};

use crate::{
geometry::CurveBoundary,
operations::{
build::{BuildCycle, BuildHalfEdge},
geometry::UpdateHalfEdgeGeometry,
Expand Down Expand Up @@ -121,7 +122,7 @@ impl SweepHalfEdge for Handle<HalfEdge> {
let half_edge = {
let line_segment = HalfEdge::line_segment(
[start, end],
Some(boundary),
Some(CurveBoundary { inner: boundary }),
surface.clone(),
core,
);
Expand Down

0 comments on commit 17180dc

Please sign in to comment.