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

Change with_* methods of partial objects to accept Option #1171

Merged
merged 20 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ mod tests {
.surfaces
.insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]));
let curve = Curve::partial()
.with_surface(surface)
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [2., 1.]])
.build(&stores);
let range = RangeOnPath::from([[0.], [1.]]);
Expand All @@ -232,7 +232,7 @@ mod tests {
[0., 0., 1.],
));
let curve = Curve::partial()
.with_surface(surface)
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [1., 2.]])
.build(&stores);
let range = RangeOnPath::from([[0.], [1.]]);
Expand All @@ -249,7 +249,7 @@ mod tests {
let path = GlobalPath::circle_from_radius(1.);
let surface = stores.surfaces.insert(Surface::new(path, [0., 0., 1.]));
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_line_from_points([[0., 1.], [1., 1.]])
.build(&stores);

Expand Down Expand Up @@ -280,7 +280,7 @@ mod tests {
.surfaces
.insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]));
let curve = Curve::partial()
.with_surface(surface)
.with_surface(Some(surface))
.as_circle_from_radius(1.)
.build(&stores);

Expand Down
8 changes: 4 additions & 4 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::partial()
Expand All @@ -111,7 +111,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::partial()
Expand All @@ -134,7 +134,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::partial()
Expand All @@ -152,7 +152,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
let half_edge = HalfEdge::partial()
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ mod tests {
let surface = stores.surfaces.insert(Surface::xy_plane());

let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_line_from_points([[-3., 0.], [-2., 0.]])
.build(&stores);

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mod tests {

let expected_curves = surfaces.map(|surface| {
Curve::partial()
.with_surface(surface)
.with_surface(Some(surface))
.as_line_from_points([[0., 0.], [1., 0.]])
.build(&stores)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ mod tests {
);

let expected_xy = Curve::partial()
.with_surface(xy.clone())
.with_surface(Some(xy.clone()))
.as_u_axis()
.build(&stores);
let expected_xz = Curve::partial()
.with_surface(xz.clone())
.with_surface(Some(xz.clone()))
.as_u_axis()
.build(&stores);

Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xz_plane());
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
let vertex = Vertex::partial()
.with_position([0.])
.with_curve(curve)
.with_position(Some([0.]))
.with_curve(Some(curve))
.build(&stores);

let half_edge = (vertex, surface.clone()).sweep([0., 0., 1.], &stores);
Expand Down
28 changes: 12 additions & 16 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,21 @@ impl TransformObject for PartialHalfEdge {
.map(|curve| curve.transform(transform, stores));
let vertices = self.vertices.clone().map(|vertices| {
vertices.map(|vertex| {
let vertex = vertex.into_partial().transform(transform, stores);
let vertex = match &curve {
Some(curve) => vertex.with_curve(curve.clone()),
None => vertex,
};
vertex.into()
vertex
.into_partial()
.transform(transform, stores)
.with_curve(curve.clone())
.into()
})
});
let global_form = self.global_form.map(|global_form| {
let global_form =
global_form.into_partial().transform(transform, stores);

let curve = curve.as_ref().and_then(|curve| curve.global_form());
let global_form = match curve {
Some(curve) => global_form.with_curve(curve),
None => global_form,
};

global_form.into()
global_form
.into_partial()
.transform(transform, stores)
.with_curve(
curve.as_ref().and_then(|curve| curve.global_form()),
)
.into()
});

Self {
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/algorithms/transform/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ impl TransformObject for Face {
.exterior()
.to_partial()
.transform(transform, stores)
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.build(stores);
let interiors = self.interiors().map(|cycle| {
cycle
.to_partial()
.transform(transform, stores)
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.build(stores)
});

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> FaceBuilder<'a> {
) -> Self {
self.exterior = Some(
Cycle::partial()
.with_surface(self.surface.clone())
.with_surface(Some(self.surface.clone()))
.with_poly_chain_from_points(points)
.close_with_line_segment()
.build(self.stores),
Expand All @@ -49,7 +49,7 @@ impl<'a> FaceBuilder<'a> {
) -> Self {
self.interiors.push(
Cycle::partial()
.with_surface(self.surface.clone())
.with_surface(Some(self.surface.clone()))
.with_poly_chain_from_points(points)
.close_with_line_segment()
.build(self.stores),
Expand Down
66 changes: 35 additions & 31 deletions crates/fj-kernel/src/builder/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> ShellBuilder<'a> {
.zip(&surfaces)
.map(|(half_edge, surface)| {
HalfEdge::partial()
.with_global_form(half_edge.global_form().clone())
.with_global_form(Some(half_edge.global_form().clone()))
.as_line_segment_from_points(
surface.clone(),
[[Z, Z], [edge_length, Z]],
Expand All @@ -87,14 +87,14 @@ impl<'a> ShellBuilder<'a> {

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

HalfEdge::partial()
.with_vertices([
Vertex::partial().with_surface_form(from),
Vertex::partial().with_surface_form(to),
])
.with_vertices(Some([
Vertex::partial().with_surface_form(Some(from)),
Vertex::partial().with_surface_form(Some(to)),
]))
.as_line_segment()
.build(self.stores)
})
Expand All @@ -115,20 +115,22 @@ impl<'a> ShellBuilder<'a> {

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

let curve = Curve::partial().with_global_form(
let curve = Curve::partial().with_global_form(Some(
side_up_prev.curve().global_form().clone(),
);
));

HalfEdge::partial()
.with_curve(curve)
.with_vertices([
Vertex::partial().with_surface_form(from),
Vertex::partial().with_surface_form(to),
])
.with_curve(Some(curve))
.with_vertices(Some([
Vertex::partial().with_surface_form(Some(from)),
Vertex::partial().with_surface_form(Some(to)),
]))
.as_line_segment()
.build(self.stores)
})
Expand All @@ -146,15 +148,17 @@ impl<'a> ShellBuilder<'a> {

let from = from.surface_form().clone();
let to = SurfaceVertex::partial()
.with_position(from.position() + [-edge_length, Z])
.with_surface(surface.clone())
.with_global_form(*to.global_form());
.with_position(Some(
from.position() + [-edge_length, Z],
))
.with_surface(Some(surface.clone()))
.with_global_form(Some(*to.global_form()));

let from = Vertex::partial().with_surface_form(from);
let to = Vertex::partial().with_surface_form(to);
let from = Vertex::partial().with_surface_form(Some(from));
let to = Vertex::partial().with_surface_form(Some(to));

HalfEdge::partial()
.with_vertices([from, to])
.with_vertices(Some([from, to]))
.as_line_segment()
.build(self.stores)
})
Expand All @@ -168,7 +172,7 @@ impl<'a> ShellBuilder<'a> {
.zip(surfaces)
.map(|((((bottom, side_up), top), side_down), surface)| {
let cycle = Cycle::partial()
.with_surface(surface)
.with_surface(Some(surface))
.with_half_edges([bottom, side_up, top, side_down])
.build(self.stores);

Expand Down Expand Up @@ -203,20 +207,20 @@ impl<'a> ShellBuilder<'a> {
let vertices = [(point_a, vertex_a), (point_b, vertex_b)].map(
|(point, vertex)| {
let surface_form = SurfaceVertex::partial()
.with_position(point)
.with_surface(surface.clone())
.with_global_form(*vertex.global_form())
.with_position(Some(point))
.with_surface(Some(surface.clone()))
.with_global_form(Some(*vertex.global_form()))
.build(self.stores);
Vertex::partial()
.with_position(vertex.position())
.with_surface_form(surface_form)
.with_position(Some(vertex.position()))
.with_surface_form(Some(surface_form))
},
);

edges.push(
HalfEdge::partial()
.with_vertices(vertices)
.with_global_form(edge.global_form().clone())
.with_vertices(Some(vertices))
.with_global_form(Some(edge.global_form().clone()))
.as_line_segment()
.build(self.stores),
);
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let object = Curve::partial()
.with_surface(surface)
.with_surface(Some(surface))
.as_u_axis()
.build(&stores);

Expand All @@ -399,7 +399,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let object = Cycle::partial()
.with_surface(surface)
.with_surface(Some(surface))
.with_poly_chain_from_points([[0., 0.], [1., 0.], [0., 1.]])
.close_with_line_segment()
.build(&stores);
Expand Down Expand Up @@ -585,7 +585,7 @@ mod tests {

let surface = stores.surfaces.insert(Surface::xy_plane());
let curve = Curve::partial()
.with_surface(surface.clone())
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&stores);
let global_vertex = GlobalVertex::from_position([0., 0., 0.]);
Expand Down
22 changes: 14 additions & 8 deletions crates/fj-kernel/src/partial/objects/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,29 @@ pub struct PartialCurve {

impl PartialCurve {
/// Provide a path for the partial curve
pub fn with_path(mut self, path: SurfacePath) -> Self {
self.path = Some(path);
pub fn with_path(mut self, path: Option<SurfacePath>) -> Self {
if let Some(path) = path {
self.path = Some(path);
}
self
}

/// Provide a surface for the partial curve
pub fn with_surface(mut self, surface: Handle<Surface>) -> Self {
self.surface = Some(surface);
pub fn with_surface(mut self, surface: Option<Handle<Surface>>) -> Self {
if let Some(surface) = surface {
self.surface = Some(surface);
}
self
}

/// Provide a global form for the partial curve
pub fn with_global_form(
mut self,
global_form: impl Into<HandleWrapper<GlobalCurve>>,
global_form: Option<impl Into<HandleWrapper<GlobalCurve>>>,
) -> Self {
self.global_form = Some(global_form.into());
if let Some(global_form) = global_form {
self.global_form = Some(global_form.into());
}
self
}

Expand All @@ -68,12 +74,12 @@ impl PartialCurve {

/// Update partial curve as a circle, from the provided radius
pub fn as_circle_from_radius(self, radius: impl Into<Scalar>) -> Self {
self.with_path(SurfacePath::circle_from_radius(radius))
self.with_path(Some(SurfacePath::circle_from_radius(radius)))
}

/// Update partial curve as a line, from the provided points
pub fn as_line_from_points(self, points: [impl Into<Point<2>>; 2]) -> Self {
self.with_path(SurfacePath::line_from_points(points))
self.with_path(Some(SurfacePath::line_from_points(points)))
}

/// Build a full [`Curve`] from the partial curve
Expand Down
Loading