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

Simplify use of MaybePartial #1253

Merged
merged 2 commits into from
Oct 21, 2022
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
9 changes: 4 additions & 5 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ mod tests {
objects::{Curve, Objects, Surface},
partial::HasPartial,
path::GlobalPath,
storage::Handle,
};

use super::CurveApprox;
Expand All @@ -212,7 +211,7 @@ mod tests {
let surface = objects
.surfaces
.insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]));
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [2., 1.]])
.build(&objects);
Expand All @@ -231,7 +230,7 @@ mod tests {
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
));
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [1., 2.]])
.build(&objects);
Expand All @@ -248,7 +247,7 @@ mod tests {

let path = GlobalPath::circle_from_radius(1.);
let surface = objects.surfaces.insert(Surface::new(path, [0., 0., 1.]));
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_line_from_points([[0., 1.], [1., 1.]])
.build(&objects);
Expand Down Expand Up @@ -279,7 +278,7 @@ mod tests {
let surface = objects
.surfaces
.insert(Surface::new(GlobalPath::x_axis(), [0., 0., 1.]));
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface))
.as_circle_from_radius(1.)
.build(&objects);
Expand Down
17 changes: 8 additions & 9 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ mod tests {
use crate::{
objects::{Curve, HalfEdge, Objects},
partial::HasPartial,
storage::Handle,
};

use super::CurveEdgeIntersection;
Expand All @@ -87,11 +86,11 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[1., -1.], [1., 1.]])
.build(&objects);
Expand All @@ -111,11 +110,11 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., -1.], [-1., 1.]])
.build(&objects);
Expand All @@ -135,11 +134,11 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., -1.], [1., -1.]])
.build(&objects);
Expand All @@ -154,11 +153,11 @@ mod tests {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., 0.], [1., 0.]])
.build(&objects);
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ mod tests {
use crate::{
objects::{Curve, Face, Objects},
partial::HasPartial,
storage::Handle,
};

use super::CurveFaceIntersection;
Expand All @@ -163,7 +162,7 @@ mod tests {

let surface = objects.surfaces.xy_plane();

let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_line_from_points([[-3., 0.], [-2., 0.]])
.build(&objects);
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ mod tests {
algorithms::intersect::CurveFaceIntersection,
objects::{Curve, Face, Objects},
partial::HasPartial,
storage::Handle,
};

use super::FaceFaceIntersection;
Expand Down Expand Up @@ -112,7 +111,7 @@ mod tests {
let intersection = FaceFaceIntersection::compute([&a, &b], &objects);

let expected_curves = surfaces.map(|surface| {
Handle::<Curve>::partial()
Curve::partial()
.with_surface(Some(surface))
.as_line_from_points([[0., 0.], [1., 0.]])
.build(&objects)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ mod tests {
algorithms::transform::TransformObject,
objects::{Curve, Objects},
partial::HasPartial,
storage::Handle,
};

use super::SurfaceSurfaceIntersection;
Expand All @@ -117,11 +116,11 @@ mod tests {
None,
);

let expected_xy = Handle::<Curve>::partial()
let expected_xy = Curve::partial()
.with_surface(Some(xy.clone()))
.as_u_axis()
.build(&objects);
let expected_xz = Handle::<Curve>::partial()
let expected_xz = Curve::partial()
.with_surface(Some(xz.clone()))
.as_u_axis()
.build(&objects);
Expand Down
65 changes: 27 additions & 38 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,13 @@ mod tests {
algorithms::{reverse::Reverse, sweep::Sweep},
objects::{Cycle, Face, HalfEdge, Objects, SurfaceVertex, Vertex},
partial::HasPartial,
storage::Handle,
};

#[test]
fn sweep() {
let objects = Objects::new();

let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build(&objects);
Expand All @@ -199,53 +198,43 @@ mod tests {
let expected_face = {
let surface = objects.surfaces.xz_plane();

let bottom = Handle::<HalfEdge>::partial()
let bottom = HalfEdge::partial()
.with_surface(Some(surface.clone()))
.as_line_segment_from_points([[0., 0.], [1., 0.]])
.build(&objects);
let side_up = Handle::<HalfEdge>::partial()
let side_up = HalfEdge::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
bottom.front().surface_form().clone(),
)),
))
.with_front_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
Handle::<SurfaceVertex>::partial()
.with_position(Some([1., 1.])),
)),
))
.with_back_vertex(Some(Vertex::partial().with_surface_form(
Some(bottom.front().surface_form().clone()),
)))
.with_front_vertex(Some(Vertex::partial().with_surface_form(
Some(
SurfaceVertex::partial().with_position(Some([1., 1.])),
),
)))
.as_line_segment()
.build(&objects);
let top = Handle::<HalfEdge>::partial()
let top = HalfEdge::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
Handle::<SurfaceVertex>::partial()
.with_position(Some([0., 1.])),
)),
))
.with_front_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
side_up.front().surface_form().clone(),
)),
))
.with_back_vertex(Some(Vertex::partial().with_surface_form(
Some(
SurfaceVertex::partial().with_position(Some([0., 1.])),
),
)))
.with_front_vertex(Some(Vertex::partial().with_surface_form(
Some(side_up.front().surface_form().clone()),
)))
.as_line_segment()
.build(&objects)
.reverse(&objects);
let side_down = Handle::<HalfEdge>::partial()
let side_down = HalfEdge::partial()
.with_surface(Some(surface.clone()))
.with_back_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
bottom.back().surface_form().clone(),
)),
))
.with_front_vertex(Some(
Handle::<Vertex>::partial().with_surface_form(Some(
top.front().surface_form().clone(),
)),
))
.with_back_vertex(Some(Vertex::partial().with_surface_form(
Some(bottom.back().surface_form().clone()),
)))
.with_front_vertex(Some(Vertex::partial().with_surface_form(
Some(top.front().surface_form().clone()),
)))
.as_line_segment()
.build(&objects)
.reverse(&objects);
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ mod tests {
algorithms::{reverse::Reverse, transform::TransformObject},
objects::{Face, HalfEdge, Objects, Sketch},
partial::HasPartial,
storage::Handle,
};

use super::Sweep;
Expand Down Expand Up @@ -116,7 +115,7 @@ mod tests {

let triangle = TRIANGLE.as_slice();
let mut side_faces = triangle.array_windows_ext().map(|&[a, b]| {
let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([a, b])
.build(&objects);
Expand Down Expand Up @@ -149,7 +148,7 @@ mod tests {

let triangle = TRIANGLE.as_slice();
let mut side_faces = triangle.array_windows_ext().map(|&[a, b]| {
let half_edge = Handle::<HalfEdge>::partial()
let half_edge = HalfEdge::partial()
.with_surface(Some(objects.surfaces.xy_plane()))
.as_line_segment_from_points([a, b])
.build(&objects)
Expand Down
7 changes: 3 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,25 @@ mod tests {
algorithms::sweep::Sweep,
objects::{Curve, HalfEdge, Objects, Vertex},
partial::HasPartial,
storage::Handle,
};

#[test]
fn vertex_surface() {
let objects = Objects::new();

let surface = objects.surfaces.xz_plane();
let curve = Handle::<Curve>::partial()
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
let vertex = Handle::<Vertex>::partial()
let vertex = Vertex::partial()
.with_position(Some([0.]))
.with_curve(Some(curve))
.build(&objects);

let half_edge = (vertex, surface.clone()).sweep([0., 0., 1.], &objects);

let expected_half_edge = Handle::<HalfEdge>::partial()
let expected_half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[0., 0.], [0., 1.]])
.build(&objects);
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/transform/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use fj_math::Transform;
use crate::{
objects::{Curve, Objects},
partial::{MaybePartial, PartialGlobalEdge, PartialHalfEdge},
storage::Handle,
};

use super::TransformObject;
Expand Down Expand Up @@ -34,7 +33,7 @@ impl TransformObject for PartialHalfEdge {
.into_partial()
.transform(transform, objects)
.with_curve(curve.as_ref().and_then(
|curve: &MaybePartial<Handle<Curve>>| curve.global_form(),
|curve: &MaybePartial<Curve>| curve.global_form(),
))
.into()
});
Expand Down
6 changes: 4 additions & 2 deletions crates/fj-kernel/src/algorithms/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use fj_math::{Transform, Vector};
use crate::{
objects::Objects,
partial::{HasPartial, MaybePartial, Partial},
storage::Handle,
};

/// Transform an object
Expand Down Expand Up @@ -57,7 +58,7 @@ pub trait TransformObject: Sized {
}
}

impl<T> TransformObject for T
impl<T> TransformObject for Handle<T>
where
T: HasPartial,
T::Partial: TransformObject,
Expand All @@ -71,7 +72,8 @@ where

impl<T> TransformObject for MaybePartial<T>
where
T: HasPartial + TransformObject,
T: HasPartial,
Handle<T>: TransformObject,
T::Partial: TransformObject,
{
fn transform(self, transform: &Transform, objects: &Objects) -> Self {
Expand Down
3 changes: 1 addition & 2 deletions crates/fj-kernel/src/algorithms/validate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ mod tests {
},
partial::HasPartial,
path::SurfacePath,
storage::Handle,
};

#[test]
Expand Down Expand Up @@ -221,7 +220,7 @@ mod tests {
);
let vertices = [a, b];

let global_edge = Handle::<GlobalEdge>::partial()
let global_edge = GlobalEdge::partial()
.from_curve_and_vertices(&curve, &vertices)
.build(&objects);
let half_edge = HalfEdge::new(vertices, global_edge, &objects);
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 @@ -33,7 +33,7 @@ impl<'a> FaceBuilder<'a> {
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
self.exterior = Some(
Handle::<Cycle>::partial()
Cycle::partial()
.with_surface(Some(self.surface.clone()))
.with_poly_chain_from_points(points)
.close_with_line_segment()
Expand All @@ -48,7 +48,7 @@ impl<'a> FaceBuilder<'a> {
points: impl IntoIterator<Item = impl Into<Point<2>>>,
) -> Self {
self.interiors.push(
Handle::<Cycle>::partial()
Cycle::partial()
.with_surface(Some(self.surface.clone()))
.with_poly_chain_from_points(points)
.close_with_line_segment()
Expand Down
Loading