Skip to content

Commit

Permalink
Merge pull request #2401 from hannobraun/geom
Browse files Browse the repository at this point in the history
Define vertex geometry in various places
  • Loading branch information
hannobraun authored Jun 26, 2024
2 parents 6050019 + c173891 commit 7b06a98
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 55 deletions.
4 changes: 0 additions & 4 deletions crates/fj-core/src/geometry/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ pub struct CurveGeom {

impl CurveGeom {
/// # Return the local definition on the provided surface
///
/// ## Panics
///
/// Panics, if the curve has not been defined on that surface.
pub fn local_on(
&self,
surface: &Handle<Surface>,
Expand Down
7 changes: 7 additions & 0 deletions crates/fj-core/src/geometry/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ pub struct VertexGeom {
pub definitions: BTreeMap<Handle<Curve>, LocalVertexGeom>,
}

impl VertexGeom {
/// # Return the local definition on the provided curve
pub fn local_on(&self, curve: &Handle<Curve>) -> Option<&LocalVertexGeom> {
self.definitions.get(curve)
}
}

/// The geometric definition of a vertex, in 1D curve coordinates
#[derive(Clone, Debug)]
pub struct LocalVertexGeom {
Expand Down
23 changes: 22 additions & 1 deletion crates/fj-core/src/operations/build/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use fj_math::{Point, Scalar, Vector};
use itertools::Itertools;

use crate::{
geometry::LocalVertexGeom,
operations::build::BuildHalfEdge,
storage::Handle,
topology::{Cycle, HalfEdge, Surface},
Expand Down Expand Up @@ -75,12 +76,32 @@ pub trait BuildCycle {
Ps: IntoIterator<Item = P>,
Ps::IntoIter: Clone + ExactSizeIterator,
{
let half_edges = points
let half_edges_and_boundaries = points
.into_iter()
.map(Into::into)
.circular_tuple_windows()
.map(|(start, end)| {
HalfEdge::line_segment([start, end], surface.clone(), core)
})
.collect::<Vec<_>>();
let half_edges = half_edges_and_boundaries
.into_iter()
.circular_tuple_windows()
.map(|((half_edge, boundary), (next_half_edge, _))| {
let [start, end] = boundary.inner;

core.layers.geometry.define_vertex(
half_edge.start_vertex().clone(),
half_edge.curve().clone(),
LocalVertexGeom { position: start },
);
core.layers.geometry.define_vertex(
next_half_edge.start_vertex().clone(),
half_edge.curve().clone(),
LocalVertexGeom { position: end },
);

half_edge
});

Cycle::new(half_edges)
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-core/src/operations/build/half_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait BuildHalfEdge {
points_surface: [impl Into<Point<2>>; 2],
surface: Handle<Surface>,
core: &mut Core,
) -> Handle<HalfEdge> {
) -> (Handle<HalfEdge>, CurveBoundary<Point<1>>) {
let boundary = CurveBoundary::default();

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

half_edge
(half_edge, boundary)
}
}

Expand Down
61 changes: 42 additions & 19 deletions crates/fj-core/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_interop::ext::ArrayExt;
use fj_math::Point;

use crate::{
geometry::{CurveBoundary, HalfEdgeGeom},
geometry::{CurveBoundary, HalfEdgeGeom, LocalVertexGeom},
operations::{
build::{BuildFace, BuildHalfEdge, BuildSurface, Polygon},
geometry::{UpdateCurveGeometry, UpdateHalfEdgeGeometry},
Expand Down Expand Up @@ -82,30 +82,53 @@ pub trait BuildShell {
});

let half_edges = {
let vertices = [a, b, c].map(Clone::clone);
let vertices = [[a, b], [b, c], [c, a]];
let [a, b, c] = [[0., 0.], [1., 0.], [0., 1.]];
vertices
.zip_ext([[a, b], [b, c], [c, a]])
.zip_ext(curves_and_boundaries)
.map(|((vertex, positions), (curve, boundary))| {
let boundary = boundary.reverse();
.map(
|(
([vertex, vertex_next], positions),
(curve, boundary),
)| {
let boundary = boundary.reverse();

let curve = curve.make_line_on_surface(
positions,
boundary,
surface.clone(),
&mut core.layers.geometry,
);

HalfEdge::unjoined(core)
.update_start_vertex(|_, _| vertex, core)
.update_curve(|_, _| curve.clone(), core)
.insert(core)
.set_geometry(
HalfEdgeGeom { boundary },
let curve = curve.make_line_on_surface(
positions,
boundary,
surface.clone(),
&mut core.layers.geometry,
)
})
);

core.layers.geometry.define_vertex(
vertex.clone(),
curve.clone(),
LocalVertexGeom {
position: boundary.inner[0],
},
);
core.layers.geometry.define_vertex(
vertex_next.clone(),
curve.clone(),
LocalVertexGeom {
position: boundary.inner[1],
},
);

HalfEdge::unjoined(core)
.update_start_vertex(
|_, _| vertex.clone(),
core,
)
.update_curve(|_, _| curve.clone(), core)
.insert(core)
.set_geometry(
HalfEdgeGeom { boundary },
&mut core.layers.geometry,
)
},
)
};

Face::unbound(surface, core).update_region(
Expand Down
19 changes: 18 additions & 1 deletion crates/fj-core/src/operations/split/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use fj_math::Point;
use itertools::Itertools;

use crate::{
geometry::LocalVertexGeom,
operations::{
build::{BuildCycle, BuildHalfEdge},
derive::DeriveFrom,
Expand Down Expand Up @@ -103,7 +104,7 @@ impl SplitFace for Shell {

// Build the edge that's going to divide the new faces.
let dividing_half_edge_a_to_d = {
let half_edge = HalfEdge::line_segment(
let (half_edge, boundary) = HalfEdge::line_segment(
[
core.layers.geometry.of_half_edge(&b).start_position(
&core
Expand All @@ -129,6 +130,22 @@ impl SplitFace for Shell {
face.surface().clone(),
core,
);

core.layers.geometry.define_vertex(
b.start_vertex().clone(),
half_edge.curve().clone(),
LocalVertexGeom {
position: boundary.inner[0],
},
);
core.layers.geometry.define_vertex(
d.start_vertex().clone(),
half_edge.curve().clone(),
LocalVertexGeom {
position: boundary.inner[1],
},
);

half_edge
.update_start_vertex(|_, _| b.start_vertex().clone(), core)
.insert(core)
Expand Down
7 changes: 7 additions & 0 deletions crates/fj-core/src/operations/split/half_edge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use fj_math::Point;

use crate::{
geometry::LocalVertexGeom,
operations::{
derive::DeriveFrom, geometry::UpdateHalfEdgeGeometry, insert::Insert,
},
Expand Down Expand Up @@ -61,6 +62,12 @@ impl SplitHalfEdge for Handle<HalfEdge> {
&mut core.layers.geometry,
);

core.layers.geometry.define_vertex(
b.start_vertex().clone(),
b.curve().clone(),
LocalVertexGeom { position: point },
);

[a, b]
}
}
29 changes: 29 additions & 0 deletions crates/fj-core/src/operations/sweep/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use fj_interop::Color;
use fj_math::Vector;
use itertools::Itertools;

use crate::{
geometry::LocalVertexGeom,
operations::{
build::BuildCycle, join::JoinCycle, sweep::half_edge::SweepHalfEdge,
},
Expand Down Expand Up @@ -79,6 +81,7 @@ impl SweepCycle for Cycle {

top_half_edges.push((
swept_half_edge.top_half_edge,
swept_half_edge.top_boundary,
*core.layers.geometry.of_half_edge(bottom_half_edge),
core.layers
.geometry
Expand All @@ -90,6 +93,32 @@ impl SweepCycle for Cycle {
));
}

let top_half_edges = top_half_edges
.into_iter()
.circular_tuple_windows()
.map(
|(
(half_edge, boundary, half_edge_geom, curve_geom),
(next_half_edge, _, _, _),
)| {
let [start, end] = boundary.inner;

for (point, vertex) in [
(start, half_edge.start_vertex()),
(end, next_half_edge.start_vertex()),
] {
core.layers.geometry.define_vertex(
vertex.clone(),
half_edge.curve().clone(),
LocalVertexGeom { position: point },
);
}

(half_edge, half_edge_geom, curve_geom)
},
)
.collect::<Vec<_>>();

let top_cycle =
Cycle::empty().add_joined_edges(top_half_edges, top_surface, core);

Expand Down
Loading

0 comments on commit 7b06a98

Please sign in to comment.