diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index e24b99f66..26c062fc3 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -165,3 +165,42 @@ impl Sweep for (HalfEdge, Color) { Face::new(surface, cycle).with_color(color) } } + +#[cfg(test)] +mod tests { + use fj_interop::mesh::Color; + use pretty_assertions::assert_eq; + + use crate::{ + algorithms::{reverse::Reverse, sweep::Sweep}, + objects::{Cycle, Face, HalfEdge, Surface}, + }; + + #[test] + fn sweep() { + let half_edge = HalfEdge::build(Surface::xy_plane()) + .line_segment_from_points([[0., 0.], [1., 0.]]); + + let face = (half_edge, Color::default()).sweep([0., 0., 1.]); + + let expected_face = { + let surface = Surface::xz_plane(); + let builder = HalfEdge::build(surface); + + let bottom = builder.line_segment_from_points([[0., 0.], [1., 0.]]); + let top = builder + .line_segment_from_points([[0., 1.], [1., 1.]]) + .reverse(); + let left = builder + .line_segment_from_points([[0., 0.], [0., 1.]]) + .reverse(); + let right = builder.line_segment_from_points([[1., 0.], [1., 1.]]); + + let cycle = Cycle::new(surface, [bottom, right, top, left]); + + Face::new(surface, cycle) + }; + + assert_eq!(face, expected_face); + } +} diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index b9b8708a8..02ac8d051 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -22,15 +22,14 @@ impl Sweep for (Vertex, Surface) { // `Curve` is defined in a `Surface`, and we're going to need that to // create the `Curve`. Which is why this `Sweep` implementation is // for `(Vertex, Surface)`, and not just for `Vertex`. - // 2. Please note that, while the result `Edge` has two vertices, our + // 2. Please note that, while the output `Edge` has two vertices, our // input `Vertex` is not one of them! It can't be, unless the `Curve` - // of the resulting `Edge` happens to be the same `Curve` that the - // input `Vertex` is defined on. That would be an edge case that - // probably can't result in anything valid, and we're going to ignore - // it for now. + // of the output `Edge` happens to be the same `Curve` that the input + // `Vertex` is defined on. That would be an edge case that probably + // can't result in anything valid, and we're going to ignore it for + // now. // 3. This means, we have to compute everything that defines the - // resulting `Edge`: The `Curve`, the vertices, and the - // `GlobalCurve`. + // output `Edge`: The `Curve`, the vertices, and the `GlobalCurve`. // // Before we get to that though, let's make sure that whoever called // this didn't give us bad input. @@ -81,10 +80,9 @@ impl Sweep for (Vertex, Surface) { ]; // Armed with those coordinates, creating the `Curve` of the output - // `Edge` becomes straight-forward. + // `Edge` is straight-forward. let curve = { let line = Line::from_points(points_surface); - Curve::new(surface, CurveKind::Line(line), *edge_global.curve()) }; @@ -142,3 +140,39 @@ impl Sweep for GlobalVertex { GlobalEdge::new(curve, [a, b]) } } + +#[cfg(test)] +mod tests { + use crate::{ + algorithms::sweep::Sweep, + objects::{ + Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Surface, + Vertex, + }, + }; + + #[test] + fn vertex_surface() { + let surface = Surface::xz_plane(); + let curve = Curve::build(surface).u_axis(); + let vertex = Vertex::build(curve).from_point([0.]); + + let half_edge = (vertex, surface).sweep([0., 0., 1.]); + + let expected_half_edge = HalfEdge::build(surface) + .line_segment_from_points([[0., 0.], [0., 1.]]); + assert_eq!(half_edge, expected_half_edge); + } + + #[test] + fn global_vertex() { + let edge = + GlobalVertex::from_position([0., 0., 0.]).sweep([0., 0., 1.]); + + let expected_edge = GlobalEdge::new( + GlobalCurve::build().z_axis(), + [[0., 0., 0.], [0., 0., 1.]].map(GlobalVertex::from_position), + ); + assert_eq!(edge, expected_edge); + } +}