Skip to content

Commit

Permalink
Merge pull request #1214 from hannobraun/storage
Browse files Browse the repository at this point in the history
Integrate `SurfaceVertex` into centralized object storage
  • Loading branch information
hannobraun authored Oct 12, 2022
2 parents e7c007a + 415e4f9 commit 2dcd433
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 26 deletions.
2 changes: 2 additions & 0 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Sweep for (HalfEdge, Color) {
point_surface,
surface.clone(),
vertex.global_form().clone(),
objects,
);

Vertex::new(
Expand Down Expand Up @@ -141,6 +142,7 @@ impl Sweep for (HalfEdge, Color) {
point_surface,
surface.clone(),
global_form,
objects,
);
Vertex::new(vertex.position(), curve.clone(), surface_form)
})
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl Sweep for (Vertex, Handle<Surface>) {
point_surface,
surface.clone(),
vertex_global,
objects,
)
},
);
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ mod tests {
point_surface,
surface.clone(),
vertex_global,
&objects,
)
},
)
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a> ShellBuilder<'a> {
let [_, from] = bottom.vertices();

let from = from.surface_form().clone();
let to = SurfaceVertex::partial()
let to = Handle::<SurfaceVertex>::partial()
.with_position(Some(from.position() + [Z, edge_length]))
.with_surface(Some(surface.clone()));

Expand Down Expand Up @@ -113,7 +113,7 @@ impl<'a> ShellBuilder<'a> {
let [to, _] = bottom.vertices();

let to = to.surface_form().clone();
let from = SurfaceVertex::partial()
let from = Handle::<SurfaceVertex>::partial()
.with_position(Some(
to.position() + [Z, edge_length],
))
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'a> ShellBuilder<'a> {
let [to, _] = side_down.vertices();

let from = from.surface_form().clone();
let to = SurfaceVertex::partial()
let to = Handle::<SurfaceVertex>::partial()
.with_position(Some(
from.position() + [-edge_length, Z],
))
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'a> ShellBuilder<'a> {
let [vertex_a, vertex_b] = edge.vertices().clone();
let vertices = [(point_a, vertex_a), (point_b, vertex_b)].map(
|(point, vertex)| {
let surface_form = SurfaceVertex::partial()
let surface_form = Handle::<SurfaceVertex>::partial()
.with_position(Some(point))
.with_surface(Some(surface.clone()))
.with_global_form(Some(
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ mod tests {
.build(&objects);
let global_vertex = GlobalVertex::from_position([0., 0., 0.], &objects);
let surface_vertex =
SurfaceVertex::new([0., 0.], surface, global_vertex);
SurfaceVertex::new([0., 0.], surface, global_vertex, &objects);
let object = Vertex::new([0.], curve, surface_vertex);

assert_eq!(1, object.curve_iter().count());
Expand Down
3 changes: 3 additions & 0 deletions crates/fj-kernel/src/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pub struct Objects {
/// Store for global vertices
pub global_vertices: Store<GlobalVertex>,

/// Store for surface vertices
pub surface_vertices: Store<SurfaceVertex>,

/// Store for surfaces
pub surfaces: Surfaces,
}
Expand Down
13 changes: 7 additions & 6 deletions crates/fj-kernel/src/objects/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{Curve, Objects, Surface};
pub struct Vertex {
position: Point<1>,
curve: Handle<Curve>,
surface_form: SurfaceVertex,
surface_form: Handle<SurfaceVertex>,
}

impl Vertex {
Expand All @@ -25,7 +25,7 @@ impl Vertex {
pub fn new(
position: impl Into<Point<1>>,
curve: Handle<Curve>,
surface_form: SurfaceVertex,
surface_form: Handle<SurfaceVertex>,
) -> Self {
let position = position.into();

Expand Down Expand Up @@ -53,7 +53,7 @@ impl Vertex {
}

/// Access the surface form of this vertex
pub fn surface_form(&self) -> &SurfaceVertex {
pub fn surface_form(&self) -> &Handle<SurfaceVertex> {
&self.surface_form
}

Expand All @@ -77,13 +77,14 @@ impl SurfaceVertex {
position: impl Into<Point<2>>,
surface: Handle<Surface>,
global_form: Handle<GlobalVertex>,
) -> Self {
objects: &Objects,
) -> Handle<Self> {
let position = position.into();
Self {
objects.surface_vertices.insert(Self {
position,
surface,
global_form,
}
})
}

/// Access the position of the vertex on the surface
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl MaybePartial<HalfEdge> {
}
}

impl MaybePartial<SurfaceVertex> {
impl MaybePartial<Handle<SurfaceVertex>> {
/// Access the position
pub fn position(&self) -> Option<Point<2>> {
match self {
Expand All @@ -136,7 +136,7 @@ impl MaybePartial<SurfaceVertex> {

impl MaybePartial<Vertex> {
/// Access the surface form
pub fn surface_form(&self) -> Option<MaybePartial<SurfaceVertex>> {
pub fn surface_form(&self) -> Option<MaybePartial<Handle<SurfaceVertex>>> {
match self {
Self::Full(full) => Some(full.surface_form().clone().into()),
Self::Partial(partial) => partial.surface_form.clone(),
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/partial/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl PartialCycle {
/// Update the partial cycle with a polygonal chain from the provided points
pub fn with_poly_chain(
mut self,
vertices: impl IntoIterator<Item = MaybePartial<SurfaceVertex>>,
vertices: impl IntoIterator<Item = MaybePartial<Handle<SurfaceVertex>>>,
) -> Self {
let iter = self
.half_edges
Expand All @@ -57,7 +57,7 @@ impl PartialCycle {
.into_iter()
.chain(vertices);

let mut previous: Option<MaybePartial<SurfaceVertex>> = None;
let mut previous: Option<MaybePartial<Handle<SurfaceVertex>>> = None;

for vertex_next in iter {
if let Some(vertex_prev) = previous {
Expand Down Expand Up @@ -116,7 +116,7 @@ impl PartialCycle {
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
self.with_poly_chain(points.into_iter().map(|position| {
SurfaceVertex::partial()
Handle::<SurfaceVertex>::partial()
.with_position(Some(position))
.into()
}))
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/partial/objects/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl PartialHalfEdge {
.from_curve_and_position(curve.clone(), a_curve);

let path = curve.path.expect("Expected path that was just created");
let surface_form = SurfaceVertex::partial()
let surface_form = Handle::<SurfaceVertex>::partial()
.with_position(Some(path.point_from_path_coords(a_curve)))
.with_global_form(Some(global_form));

Expand All @@ -148,7 +148,7 @@ impl PartialHalfEdge {
) -> Self {
let surface = self.surface.clone();
let vertices = points.map(|point| {
let surface_form = SurfaceVertex::partial()
let surface_form = Handle::<SurfaceVertex>::partial()
.with_surface(surface.clone())
.with_position(Some(point));
Vertex::partial().with_surface_form(Some(surface_form))
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/partial/objects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ impl_traits!(
GlobalEdge, PartialGlobalEdge;
Handle<GlobalVertex>, PartialGlobalVertex;
HalfEdge, PartialHalfEdge;
SurfaceVertex, PartialSurfaceVertex;
Handle<SurfaceVertex>, PartialSurfaceVertex;
Vertex, PartialVertex;
);
14 changes: 7 additions & 7 deletions crates/fj-kernel/src/partial/objects/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct PartialVertex {
///
/// Can be provided, if already available, or computed from the position on
/// the [`Curve`].
pub surface_form: Option<MaybePartial<SurfaceVertex>>,
pub surface_form: Option<MaybePartial<Handle<SurfaceVertex>>>,

/// The global form of the [`Vertex`]
///
Expand Down Expand Up @@ -60,7 +60,7 @@ impl PartialVertex {
/// Provide a surface form for the partial vertex
pub fn with_surface_form(
mut self,
surface_form: Option<impl Into<MaybePartial<SurfaceVertex>>>,
surface_form: Option<impl Into<MaybePartial<Handle<SurfaceVertex>>>>,
) -> Self {
if let Some(surface_form) = surface_form {
self.surface_form = Some(surface_form.into());
Expand Down Expand Up @@ -97,7 +97,7 @@ impl PartialVertex {

let surface_form = self
.surface_form
.unwrap_or_else(|| SurfaceVertex::partial().into())
.unwrap_or_else(|| Handle::<SurfaceVertex>::partial().into())
.update_partial(|partial| {
let position = partial.position.unwrap_or_else(|| {
curve.path().point_from_path_coords(position)
Expand Down Expand Up @@ -185,7 +185,7 @@ impl PartialSurfaceVertex {
/// Panics, if no position has been provided.
///
/// Panics, if no surface has been provided.
pub fn build(self, objects: &Objects) -> SurfaceVertex {
pub fn build(self, objects: &Objects) -> Handle<SurfaceVertex> {
let position = self
.position
.expect("Can't build `SurfaceVertex` without position");
Expand All @@ -202,12 +202,12 @@ impl PartialSurfaceVertex {
})
.into_full(objects);

SurfaceVertex::new(position, surface, global_form)
SurfaceVertex::new(position, surface, global_form, objects)
}
}

impl From<&SurfaceVertex> for PartialSurfaceVertex {
fn from(surface_vertex: &SurfaceVertex) -> Self {
impl From<&Handle<SurfaceVertex>> for PartialSurfaceVertex {
fn from(surface_vertex: &Handle<SurfaceVertex>) -> Self {
Self {
position: Some(surface_vertex.position()),
surface: Some(surface_vertex.surface().clone()),
Expand Down

0 comments on commit 2dcd433

Please sign in to comment.