mirror of
https://github.com/hannobraun/Fornjot
synced 2025-01-15 21:00:20 +00:00
Merge pull request #1214 from hannobraun/storage
Integrate `SurfaceVertex` into centralized object storage
This commit is contained in:
commit
2dcd433ee1
@ -68,6 +68,7 @@ impl Sweep for (HalfEdge, Color) {
|
||||
point_surface,
|
||||
surface.clone(),
|
||||
vertex.global_form().clone(),
|
||||
objects,
|
||||
);
|
||||
|
||||
Vertex::new(
|
||||
@ -141,6 +142,7 @@ impl Sweep for (HalfEdge, Color) {
|
||||
point_surface,
|
||||
surface.clone(),
|
||||
global_form,
|
||||
objects,
|
||||
);
|
||||
Vertex::new(vertex.position(), curve.clone(), surface_form)
|
||||
})
|
||||
|
@ -105,6 +105,7 @@ impl Sweep for (Vertex, Handle<Surface>) {
|
||||
point_surface,
|
||||
surface.clone(),
|
||||
vertex_global,
|
||||
objects,
|
||||
)
|
||||
},
|
||||
);
|
||||
|
@ -202,6 +202,7 @@ mod tests {
|
||||
point_surface,
|
||||
surface.clone(),
|
||||
vertex_global,
|
||||
&objects,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
@ -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()));
|
||||
|
||||
@ -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],
|
||||
))
|
||||
@ -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],
|
||||
))
|
||||
@ -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(
|
||||
|
@ -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());
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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();
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
@ -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 {
|
||||
@ -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(),
|
||||
|
@ -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
|
||||
@ -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 {
|
||||
@ -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()
|
||||
}))
|
||||
|
@ -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));
|
||||
|
||||
@ -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))
|
||||
|
@ -47,6 +47,6 @@ impl_traits!(
|
||||
GlobalEdge, PartialGlobalEdge;
|
||||
Handle<GlobalVertex>, PartialGlobalVertex;
|
||||
HalfEdge, PartialHalfEdge;
|
||||
SurfaceVertex, PartialSurfaceVertex;
|
||||
Handle<SurfaceVertex>, PartialSurfaceVertex;
|
||||
Vertex, PartialVertex;
|
||||
);
|
||||
|
@ -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`]
|
||||
///
|
||||
@ -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());
|
||||
@ -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)
|
||||
@ -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");
|
||||
@ -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()),
|
||||
|
Loading…
Reference in New Issue
Block a user