Skip to content

Commit

Permalink
Replace PartialSurfaceVertex
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Dec 7, 2022
1 parent a65423c commit 764a71f
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 310 deletions.
46 changes: 23 additions & 23 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ mod tests {
builder::HalfEdgeBuilder,
insert::Insert,
objects::{Cycle, Face, HalfEdge},
partial::{HasPartial, PartialSurfaceVertex, PartialVertex},
partial2::{Partial, PartialCurve},
partial::{HasPartial, PartialVertex},
partial2::{Partial, PartialCurve, PartialSurfaceVertex},
services::Services,
};

Expand Down Expand Up @@ -236,20 +236,19 @@ mod tests {
),
..Default::default()
}),
surface_form: bottom
.front()
.surface_form()
.clone()
.into(),
surface_form: Partial::from_full_entry_point(
bottom.front().surface_form().clone(),
),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([1., 1.].into()),
surface: surface.clone(),
..Default::default()
}
.into(),
surface_form: Partial::from_partial(
PartialSurfaceVertex {
position: Some([1., 1.].into()),
surface: surface.clone(),
..Default::default()
},
),
..Default::default()
})
.update_as_line_segment()
Expand All @@ -265,16 +264,17 @@ mod tests {
),
..Default::default()
}),
surface_form: PartialSurfaceVertex {
surface_form: Partial::from_partial(PartialSurfaceVertex {
position: Some([0., 1.].into()),
surface,
..Default::default()
}
.into(),
}),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: side_up.front().surface_form().clone().into(),
surface_form: Partial::from_full_entry_point(
side_up.front().surface_form().clone(),
),
..Default::default()
})
.update_as_line_segment()
Expand All @@ -292,15 +292,15 @@ mod tests {
),
..Default::default()
}),
surface_form: bottom
.back()
.surface_form()
.clone()
.into(),
surface_form: Partial::from_full_entry_point(
bottom.back().surface_form().clone(),
),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: top.front().surface_form().clone().into(),
surface_form: Partial::from_full_entry_point(
top.front().surface_form().clone(),
),
..Default::default()
})
.update_as_line_segment()
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ mod tests {
builder::{CurveBuilder, HalfEdgeBuilder},
insert::Insert,
objects::HalfEdge,
partial::{
HasPartial, MaybePartial, PartialSurfaceVertex, PartialVertex,
partial::{HasPartial, PartialVertex},
partial2::{
Partial, PartialCurve, PartialObject, PartialSurfaceVertex,
},
partial2::{Partial, PartialCurve, PartialObject},
services::Services,
};

Expand All @@ -187,7 +187,7 @@ mod tests {
let vertex = PartialVertex {
position: Some([0.].into()),
curve: Partial::from_full_entry_point(curve),
surface_form: MaybePartial::from(PartialSurfaceVertex {
surface_form: Partial::from_partial(PartialSurfaceVertex {
surface: Partial::from_full_entry_point(surface.clone()),
..Default::default()
}),
Expand Down
43 changes: 25 additions & 18 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use fj_math::Point;

use crate::{
objects::{Curve, HalfEdge, Surface, SurfaceVertex},
partial::{
HasPartial, MaybePartial, PartialCycle, PartialHalfEdge,
PartialSurfaceVertex, PartialVertex,
},
partial2::{Partial, PartialCurve},
objects::{Curve, Surface, SurfaceVertex},
partial::{PartialCycle, PartialHalfEdge, PartialVertex},
partial2::{Partial, PartialCurve, PartialSurfaceVertex},
storage::Handle,
};

Expand Down Expand Up @@ -38,23 +35,26 @@ impl CycleBuilder for PartialCycle {
self,
vertices: impl IntoIterator<Item = PartialSurfaceVertex>,
) -> Self {
let vertices = vertices.into_iter().map(Into::into);
let vertices = vertices.into_iter();

let mut previous: Option<MaybePartial<SurfaceVertex>> =
let mut previous: Option<Partial<SurfaceVertex>> =
self.half_edges().last().map(|half_edge| {
let [_, last] = half_edge.vertices();
last.surface_form()
});

let mut half_edges = Vec::new();
for vertex_next in vertices {
let vertex_next = Partial::from_partial(vertex_next);

if let Some(vertex_prev) = previous {
let surface = vertex_prev.surface();
let surface = vertex_prev.read().surface.clone();

let [position_prev, position_next] =
[&vertex_prev, &vertex_next].map(|vertex| {
vertex
.position()
.read()
.position
.expect("Need surface position to extend cycle")
});

Expand Down Expand Up @@ -116,17 +116,24 @@ impl CycleBuilder for PartialCycle {
return self;
};

let vertices = [last, first].map(|vertex| {
vertex
.surface_form()
.position()
.expect("Need surface position to close cycle")
});
let surface = self.surface().expect("Need surface to close cycle");

self.with_half_edges(Some(
HalfEdge::partial()
.update_as_line_segment_from_points(surface, vertices),
PartialHalfEdge {
vertices: [last, first].map(|vertex| {
PartialVertex {
curve: Partial::from_partial(PartialCurve {
surface: surface.clone(),
..Default::default()
}),
surface_form: vertex.surface_form(),
..Default::default()
}
.into()
}),
..Default::default()
}
.update_as_line_segment(),
))
}
}
66 changes: 12 additions & 54 deletions crates/fj-kernel/src/builder/edge.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use fj_interop::ext::ArrayExt;
use fj_math::{Point, Scalar};
use iter_fixed::IntoIteratorFixed;

use crate::{
insert::Insert,
objects::{Curve, Objects, Surface, Vertex, VerticesInNormalizedOrder},
objects::{Curve, Objects, Surface, Vertex},
partial::{
MaybePartial, MergeWith, PartialGlobalEdge, PartialHalfEdge,
PartialSurfaceVertex, PartialVertex,
MaybePartial, PartialGlobalEdge, PartialHalfEdge, PartialVertex,
},
partial2::{Partial, PartialCurve},
services::{Service, Services},
partial2::{Partial, PartialCurve, PartialObject, PartialSurfaceVertex},
services::Service,
storage::Handle,
};

Expand Down Expand Up @@ -100,7 +98,9 @@ impl HalfEdgeBuilder for PartialHalfEdge {
[a_curve, b_curve].map(|point_curve| PartialVertex {
position: Some(point_curve),
curve: curve.clone(),
surface_form: surface_vertex.clone().into(),
surface_form: Partial::from_full_entry_point(
surface_vertex.clone(),
),
});

self.vertices = [back, front].map(Into::into);
Expand All @@ -123,7 +123,7 @@ impl HalfEdgeBuilder for PartialHalfEdge {
..curve
})
};
vertex.surface_form = MaybePartial::from(PartialSurfaceVertex {
vertex.surface_form = Partial::from_partial(PartialSurfaceVertex {
position: Some(point.into()),
surface: surface.clone(),
..Default::default()
Expand All @@ -143,7 +143,8 @@ impl HalfEdgeBuilder for PartialHalfEdge {
let surface = self.curve().read().surface.clone();
let points = [&from_surface, &to_surface].map(|vertex| {
vertex
.position()
.read()
.position
.expect("Can't infer line segment without surface position")
});

Expand All @@ -152,56 +153,13 @@ impl HalfEdgeBuilder for PartialHalfEdge {
curve.write().update_as_line_from_points(points);

let [back, front] = {
let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| {
[(from, 0.), (to, 1.)].map(|(vertex, position)| {
vertex.update_partial(|mut vertex| {
vertex.position = Some([position].into());
vertex.curve = self.curve();
vertex
})
});

// The global vertices we extracted are in normalized order, which
// means we might need to switch their order here. This is a bit of
// a hack, but I can't think of something better.
let global_forms = {
let must_switch_order = {
let mut services = Services::new();
let vertices = vertices.clone().map(|vertex| {
vertex
.into_full(&mut services.objects)
.global_form()
.clone()
});

let (_, must_switch_order) =
VerticesInNormalizedOrder::new(vertices);

must_switch_order
};

let [a, b] = self.global_form.vertices();
if must_switch_order {
[b, a]
} else {
[a, b]
}
};

vertices
.into_iter_fixed()
.zip(global_forms)
.collect::<[_; 2]>()
.map(|(vertex, global_form)| {
vertex.update_partial(|mut vertex| {
vertex.surface_form = vertex.surface_form.merge_with(
PartialSurfaceVertex {
global_form,
..Default::default()
},
);
vertex
})
})
})
};

self.vertices = [back, front];
Expand Down
28 changes: 18 additions & 10 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ use crate::{
objects::{Cycle, Face, FaceSet, Objects, Shell},
partial::{
HasPartial, MaybePartial, PartialGlobalEdge, PartialHalfEdge,
PartialSurfaceVertex, PartialVertex,
PartialVertex,
},
partial2::{
Partial, PartialCurve, PartialObject, PartialSurface,
PartialSurfaceVertex,
},
partial2::{Partial, PartialCurve, PartialObject, PartialSurface},
services::Service,
storage::Handle,
};
Expand Down Expand Up @@ -101,7 +104,7 @@ impl ShellBuilder {
..Default::default()
},
),
surface_form: MaybePartial::from(
surface_form: Partial::from_partial(
PartialSurfaceVertex {
global_form: global_vertex,
..Default::default()
Expand Down Expand Up @@ -151,15 +154,17 @@ impl ShellBuilder {
),
..Default::default()
}),
surface_form: from.into(),
surface_form: Partial::from_full_entry_point(
from,
),
..Default::default()
},
PartialVertex {
curve: Partial::from_partial(PartialCurve {
surface: to.surface.clone(),
..Default::default()
}),
surface_form: to.into(),
surface_form: Partial::from_partial(to),
..Default::default()
},
]
Expand Down Expand Up @@ -212,7 +217,7 @@ impl ShellBuilder {
..curve.clone()
},
),
surface_form: from.into(),
surface_form: Partial::from_partial(from),
..Default::default()
},
PartialVertex {
Expand All @@ -225,7 +230,8 @@ impl ShellBuilder {
..curve
},
),
surface_form: to.into(),
surface_form:
Partial::from_full_entry_point(to),
..Default::default()
},
]
Expand Down Expand Up @@ -257,7 +263,7 @@ impl ShellBuilder {
),
..Default::default()
}),
surface_form: from.into(),
surface_form: Partial::from_full_entry_point(from),
..Default::default()
};
let to = PartialVertex {
Expand All @@ -267,7 +273,7 @@ impl ShellBuilder {
),
..Default::default()
}),
surface_form: to.into(),
surface_form: Partial::from_full_entry_point(to),
..Default::default()
};

Expand Down Expand Up @@ -366,7 +372,9 @@ impl ShellBuilder {
),
..Default::default()
}),
surface_form: surface_form.into(),
surface_form: Partial::from_full_entry_point(
surface_form,
),
});

edges.push(
Expand Down
Loading

0 comments on commit 764a71f

Please sign in to comment.