Skip to content

Commit

Permalink
Merge pull request #1339 from hannobraun/partial
Browse files Browse the repository at this point in the history
Clean up partial vertex types
  • Loading branch information
hannobraun authored Nov 11, 2022
2 parents d6cde48 + 6f158e1 commit f172d3a
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 361 deletions.
130 changes: 71 additions & 59 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ mod tests {
algorithms::{reverse::Reverse, sweep::Sweep},
builder::HalfEdgeBuilder,
insert::Insert,
objects::{Cycle, Face, HalfEdge, Objects, SurfaceVertex, Vertex},
partial::HasPartial,
objects::{Cycle, Face, HalfEdge, Objects},
partial::{HasPartial, PartialSurfaceVertex, PartialVertex},
};

#[test]
Expand All @@ -218,63 +218,75 @@ mod tests {
let face =
(half_edge, Color::default()).sweep([0., 0., 1.], &objects)?;

let expected_face =
{
let surface = objects.surfaces.xz_plane();

let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
[[0., 0.], [1., 0.]],
)
.build(&objects)?
.insert(&objects)?;
let side_up = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form(
bottom.front().surface_form().clone(),
))
.with_front_vertex(Vertex::partial().with_surface_form(
SurfaceVertex::partial().with_position(Some([1., 1.])),
))
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?;
let top = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(Vertex::partial().with_surface_form(
SurfaceVertex::partial().with_position(Some([0., 1.])),
))
.with_front_vertex(Vertex::partial().with_surface_form(
side_up.front().surface_form().clone(),
))
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;
let side_down =
HalfEdge::partial()
.with_surface(surface)
.with_back_vertex(Vertex::partial().with_surface_form(
bottom.back().surface_form().clone(),
))
.with_front_vertex(Vertex::partial().with_surface_form(
top.front().surface_form().clone(),
))
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;

let cycle = objects
.cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?;

Face::partial()
.with_exterior(cycle)
.build(&objects)?
.insert(&objects)?
};
let expected_face = {
let surface = objects.surfaces.xz_plane();

let bottom = HalfEdge::partial()
.update_as_line_segment_from_points(
surface.clone(),
[[0., 0.], [1., 0.]],
)
.build(&objects)?
.insert(&objects)?;
let side_up = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(PartialVertex {
surface_form: bottom.front().surface_form().clone().into(),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([1., 1.].into()),
..Default::default()
}
.into(),
..Default::default()
})
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?;
let top = HalfEdge::partial()
.with_surface(surface.clone())
.with_back_vertex(PartialVertex {
surface_form: PartialSurfaceVertex {
position: Some([0., 1.].into()),
..Default::default()
}
.into(),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: side_up.front().surface_form().clone().into(),
..Default::default()
})
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;
let side_down = HalfEdge::partial()
.with_surface(surface)
.with_back_vertex(PartialVertex {
surface_form: bottom.back().surface_form().clone().into(),
..Default::default()
})
.with_front_vertex(PartialVertex {
surface_form: top.front().surface_form().clone().into(),
..Default::default()
})
.update_as_line_segment()
.build(&objects)?
.insert(&objects)?
.reverse(&objects)?;

let cycle = objects
.cycles
.insert(Cycle::new([bottom, side_up, top, side_down]))?;

Face::partial()
.with_exterior(cycle)
.build(&objects)?
.insert(&objects)?
};

assert_eq!(face, expected_face);
Ok(())
Expand Down
16 changes: 9 additions & 7 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ mod tests {
algorithms::sweep::Sweep,
builder::{CurveBuilder, HalfEdgeBuilder},
insert::Insert,
objects::{HalfEdge, Objects, Vertex},
partial::{HasPartial, PartialCurve},
objects::{HalfEdge, Objects},
partial::{HasPartial, PartialCurve, PartialVertex},
};

#[test]
Expand All @@ -185,11 +185,13 @@ mod tests {
};
curve.update_as_u_axis();
let curve = curve.build(&objects)?.insert(&objects)?;
let vertex = Vertex::partial()
.with_position(Some([0.]))
.with_curve(curve)
.build(&objects)?
.insert(&objects)?;
let vertex = PartialVertex {
position: Some([0.].into()),
curve: curve.into(),
..Default::default()
}
.build(&objects)?
.insert(&objects)?;

let half_edge =
(vertex, surface.clone()).sweep([0., 0., 1.], &objects)?;
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ impl TransformObject for PartialHalfEdge {
.into();
let vertices = self.vertices().try_map_ext(
|vertex| -> Result<_, ValidationError> {
Ok(vertex
.into_partial()
.transform(transform, objects)?
.with_curve(curve.clone()))
let mut vertex =
vertex.into_partial().transform(transform, objects)?;
vertex.curve = curve.clone();
Ok(vertex)
},
)?;
let global_form = self
Expand Down
31 changes: 17 additions & 14 deletions crates/fj-kernel/src/algorithms/transform/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ impl TransformObject for PartialVertex {
transform: &Transform,
objects: &Objects,
) -> Result<Self, ValidationError> {
let curve = self.curve().transform(transform, objects)?;
let curve = self.curve.transform(transform, objects)?;
let surface_form = self
.surface_form()
.surface_form
.into_partial()
.transform(transform, objects)?;

// Don't need to transform `self.position`, as that is in curve
// coordinates and thus transforming the curve takes care of it.
Ok(Self::default()
.with_position(self.position())
.with_curve(curve)
.with_surface_form(surface_form))
Ok(Self {
position: self.position,
curve,
surface_form: surface_form.into(),
})
}
}

Expand All @@ -36,17 +37,19 @@ impl TransformObject for PartialSurfaceVertex {
objects: &Objects,
) -> Result<Self, ValidationError> {
let surface = self
.surface()
.surface
.clone()
.map(|surface| surface.transform(transform, objects))
.transpose()?;
let global_form = self.global_form().transform(transform, objects)?;
let global_form = self.global_form.transform(transform, objects)?;

// Don't need to transform `self.position`, as that is in surface
// coordinates and thus transforming the surface takes care of it.
Ok(Self::default()
.with_position(self.position())
.with_surface(surface)
.with_global_form(Some(global_form)))
Ok(Self {
position: self.position,
surface,
global_form,
})
}
}

Expand All @@ -57,9 +60,9 @@ impl TransformObject for PartialGlobalVertex {
_: &Objects,
) -> Result<Self, ValidationError> {
let position = self
.position()
.position
.map(|position| transform.transform_point(&position));

Ok(Self::default().with_position(position))
Ok(Self { position })
}
}
24 changes: 14 additions & 10 deletions crates/fj-kernel/src/builder/cycle.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use fj_math::Point;

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

Expand Down Expand Up @@ -72,11 +75,10 @@ impl CycleBuilder for PartialCycle {
.update_as_line_from_points([position_prev, position_next]);

let vertices = [(0., vertex_prev), (1., vertex_next)].map(
|(position, surface_form)| {
Vertex::partial()
.with_curve(curve.clone())
.with_position(Some([position]))
.with_surface_form(surface_form)
|(position, surface_form)| PartialVertex {
position: Some([position].into()),
curve: curve.clone().into(),
surface_form,
},
);

Expand All @@ -101,9 +103,11 @@ impl CycleBuilder for PartialCycle {
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
self.with_poly_chain(points.into_iter().map(|position| {
SurfaceVertex::partial()
.with_surface(Some(surface.clone()))
.with_position(Some(position))
PartialSurfaceVertex {
position: Some(position.into()),
surface: Some(surface.clone()),
..Default::default()
}
}))
}

Expand Down
Loading

0 comments on commit f172d3a

Please sign in to comment.