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

Remove PartialVertex #1527

Merged
merged 8 commits into from
Jan 20, 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
30 changes: 19 additions & 11 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Sweep for (Handle<HalfEdge>, Color) {

#[cfg(test)]
mod tests {
use fj_interop::mesh::Color;
use fj_interop::{ext::ArrayExt, mesh::Color};
use pretty_assertions::assert_eq;

use crate::{
Expand Down Expand Up @@ -222,11 +222,14 @@ mod tests {
side_up.curve.write().surface = surface.clone();

{
let [back, front] = &mut side_up.vertices;
let [back, front] = side_up
.vertices
.each_mut_ext()
.map(|(_, surface_vertex)| surface_vertex);

back.surface_form = bottom.vertices[1].surface_form.clone();
*back = bottom.vertices[1].1.clone();

let mut front = front.surface_form.write();
let mut front = front.write();
front.position = Some([1., 1.].into());
front.surface = surface.clone();
}
Expand All @@ -241,14 +244,16 @@ mod tests {
top.curve.write().surface = surface.clone();

{
let [back, front] = &mut top.vertices;
let [back, front] = top
.vertices
.each_mut_ext()
.map(|(_, surface_vertex)| surface_vertex);

let mut back = back.surface_form.write();
let mut back = back.write();
back.position = Some([0., 1.].into());
back.surface = surface.clone();

front.surface_form =
side_up.vertices[1].surface_form.clone();
*front = side_up.vertices[1].1.clone();
}

top.infer_global_form();
Expand All @@ -266,10 +271,13 @@ mod tests {
let mut side_down = PartialHalfEdge::default();
side_down.curve.write().surface = surface;

let [back, front] = &mut side_down.vertices;
let [back, front] = side_down
.vertices
.each_mut_ext()
.map(|(_, surface_vertex)| surface_vertex);

back.surface_form = bottom.vertices[0].surface_form.clone();
front.surface_form = top.vertices[1].surface_form.clone();
*back = bottom.vertices[0].1.clone();
*front = top.vertices[1].1.clone();

side_down.infer_global_form();
side_down.update_as_line_segment();
Expand Down
46 changes: 22 additions & 24 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,28 @@ impl CycleBuilder for PartialCycle {
};

{
let shared_surface_vertex =
new_half_edge.read().back().surface_form.clone();
let shared_surface_vertex = {
let [vertex, _] = &new_half_edge.read().vertices;
vertex.1.clone()
};

let mut last_half_edge = last_half_edge.write();

last_half_edge.front_mut().surface_form = shared_surface_vertex;
let [_, vertex] = &mut last_half_edge.vertices;
vertex.1 = shared_surface_vertex;
last_half_edge.infer_global_form();
}

{
let shared_surface_vertex =
first_half_edge.read().back().surface_form.clone();
let shared_surface_vertex = {
let [vertex, _] = &first_half_edge.read().vertices;
vertex.1.clone()
};

let mut new_half_edge = new_half_edge.write();

new_half_edge.front_mut().surface_form = shared_surface_vertex;
let [_, vertex] = &mut new_half_edge.vertices;
vertex.1 = shared_surface_vertex;
new_half_edge.replace_surface(self.surface.clone());
new_half_edge.infer_global_form();
}
Expand All @@ -128,8 +134,10 @@ impl CycleBuilder for PartialCycle {
) -> Partial<HalfEdge> {
let mut half_edge = self.add_half_edge();

half_edge.write().back_mut().surface_form.write().position =
Some(point.into());
{
let [vertex, _] = &mut half_edge.write().vertices;
vertex.1.write().position = Some(point.into());
}

half_edge
}
Expand All @@ -140,14 +148,10 @@ impl CycleBuilder for PartialCycle {
) -> Partial<HalfEdge> {
let mut half_edge = self.add_half_edge();

half_edge
.write()
.back_mut()
.surface_form
.write()
.global_form
.write()
.position = Some(point.into());
{
let [vertex, _] = &mut half_edge.write().vertices;
vertex.1.write().global_form.write().position = Some(point.into());
}

half_edge
}
Expand Down Expand Up @@ -187,14 +191,8 @@ impl CycleBuilder for PartialCycle {

for (mut half_edge, point) in half_edges.clone().zip_ext(points_global)
{
half_edge
.write()
.back_mut()
.surface_form
.write()
.global_form
.write()
.position = Some(point);
let [vertex, _] = &mut half_edge.write().vertices;
vertex.1.write().global_form.write().position = Some(point);
}

half_edges
Expand Down
28 changes: 14 additions & 14 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
partial::{MaybeSurfacePath, Partial, PartialGlobalEdge, PartialHalfEdge},
};

use super::{CurveBuilder, VertexBuilder};
use super::CurveBuilder;

/// Builder API for [`PartialHalfEdge`]
pub trait HalfEdgeBuilder {
Expand Down Expand Up @@ -61,7 +61,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
self.curve.write().surface = surface.clone();

for vertex in &mut self.vertices {
vertex.replace_surface(surface.clone());
vertex.1.write().surface = surface.clone();
}
}

Expand All @@ -73,7 +73,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {

let mut surface_vertex = {
let [vertex, _] = &mut self.vertices;
vertex.surface_form.clone()
vertex.1.clone()
};
surface_vertex.write().position =
Some(path.point_from_path_coords(a_curve));
Expand All @@ -82,8 +82,8 @@ impl HalfEdgeBuilder for PartialHalfEdge {
self.vertices.each_mut_ext().zip_ext([a_curve, b_curve])
{
let mut vertex = vertex;
vertex.position = Some(point_curve);
vertex.surface_form = surface_vertex.clone();
vertex.0 = Some(point_curve);
vertex.1 = surface_vertex.clone();
}

self.infer_global_form();
Expand All @@ -96,7 +96,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
}
let points_surface = self.vertices.each_ref_ext().map(|vertex| {
vertex
.surface_form
.1
.read()
.position
.expect("Can't infer arc without surface position")
Expand All @@ -123,8 +123,8 @@ impl HalfEdgeBuilder for PartialHalfEdge {
for (vertex, point_curve) in
self.vertices.each_mut_ext().zip_ext([a_curve, b_curve])
{
vertex.position = Some(point_curve);
vertex.surface_form.write().position =
vertex.0 = Some(point_curve);
vertex.1.write().position =
Some(path.point_from_path_coords(point_curve));
}

Expand All @@ -141,7 +141,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
self.curve.write().surface = surface.clone();

for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) {
let mut surface_form = vertex.surface_form.write();
let mut surface_form = vertex.1.write();
surface_form.position = Some(point.into());
surface_form.surface = surface.clone();
}
Expand All @@ -152,7 +152,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
fn update_as_line_segment(&mut self) {
let points_surface = self.vertices.each_ref_ext().map(|vertex| {
vertex
.surface_form
.1
.read()
.position
.expect("Can't infer line segment without surface position")
Expand All @@ -164,7 +164,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {

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

self.infer_global_form();
Expand All @@ -175,7 +175,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
self.global_form.write().vertices = self
.vertices
.each_ref_ext()
.map(|vertex| vertex.surface_form.read().global_form.clone());
.map(|vertex| vertex.1.read().global_form.clone());

self.global_form.clone()
}
Expand All @@ -198,8 +198,8 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.iter_mut()
.zip(other.read().vertices.iter().rev())
{
this.surface_form.write().global_form.write().position =
other.surface_form.read().global_form.read().position;
this.1.write().global_form.write().position =
other.1.read().global_form.read().position;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ impl FaceBuilder for PartialFace {

fn update_surface_as_plane(&mut self) -> Partial<Surface> {
let mut exterior = self.exterior.write();
let mut vertices = exterior
.half_edges
.iter()
.map(|half_edge| half_edge.read().back().surface_form.clone());
let mut vertices = exterior.half_edges.iter().map(|half_edge| {
let [vertex, _] = &half_edge.read().vertices;
vertex.1.clone()
});

let vertices = {
let array = [
Expand Down Expand Up @@ -165,7 +165,7 @@ impl FaceBuilder for PartialFace {
MaybeSurfacePath::UndefinedLine => {
let points_surface =
half_edge.vertices.each_ref_ext().map(|vertex| {
vertex.surface_form.read().position.expect(
vertex.1.read().position.expect(
"Can't infer curve without surface points",
)
});
Expand All @@ -178,7 +178,7 @@ impl FaceBuilder for PartialFace {
.each_mut_ext()
.zip_ext(points_curve)
{
vertex.position = Some(point);
vertex.0 = Some(point);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use self::{
sketch::SketchBuilder,
solid::SolidBuilder,
surface::SurfaceBuilder,
vertex::{GlobalVertexBuilder, SurfaceVertexBuilder, VertexBuilder},
vertex::{GlobalVertexBuilder, SurfaceVertexBuilder},
};

/// Pass objects to a builder method
Expand All @@ -44,7 +44,7 @@ pub trait ObjectArgument<T>: IntoIterator<Item = T> {
/// is generic.
type SameSize<R>;

/// A return value that has one more element thatn the argument
/// A return value that has one more element than the argument
type SizePlusOne<R>;

/// Return the number of objects
Expand Down
27 changes: 1 addition & 26 deletions crates/fj-kernel/src/builder/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
use fj_math::Point;

use crate::{
objects::Surface,
partial::{
Partial, PartialGlobalVertex, PartialSurfaceVertex, PartialVertex,
},
};

/// Builder API for [`PartialVertex`]
pub trait VertexBuilder {
/// Completely replace the surface in this vertex' object graph
///
/// Please note that this operation will write to every partial object that
/// the vertex references. If any of them were created from full objects,
/// this will break the connection to those, meaning that building the
/// partial objects won't result in those full objects again. This will be
/// the case, even if those full objects already referenced the provided
/// surface.
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>);
}

impl VertexBuilder for PartialVertex {
fn replace_surface(&mut self, surface: impl Into<Partial<Surface>>) {
let surface = surface.into();
self.surface_form.write().surface = surface;
}
}
use crate::partial::{PartialGlobalVertex, PartialSurfaceVertex};

/// Builder API for [`PartialSurfaceVertex`]
pub trait SurfaceVertexBuilder {
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/partial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use self::{
sketch::PartialSketch,
solid::PartialSolid,
surface::PartialSurface,
vertex::{PartialGlobalVertex, PartialSurfaceVertex, PartialVertex},
vertex::{PartialGlobalVertex, PartialSurfaceVertex},
},
traits::{HasPartial, PartialObject},
wrapper::{FullToPartialCache, Partial},
Expand Down
Loading