From 2a998fa41bd92ec57c146de3695574a09072ec19 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Sep 2022 14:00:56 +0200 Subject: [PATCH 1/5] Improve wording in comments --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index b9b8708a8..7c86ac501 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,7 +80,7 @@ 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); From 4a4d53f234a3fcbee60fd2fb7cb122607ee2248b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Sep 2022 14:01:05 +0200 Subject: [PATCH 2/5] Improve formatting --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 7c86ac501..386a98d58 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -83,7 +83,6 @@ impl Sweep for (Vertex, Surface) { // `Edge` is straight-forward. let curve = { let line = Line::from_points(points_surface); - Curve::new(surface, CurveKind::Line(line), *edge_global.curve()) }; From a14809c15ff16268d5fcca42a833574ee2a0940e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Sep 2022 14:07:05 +0200 Subject: [PATCH 3/5] Test `Sweep` implementation for `GlobalVertex` --- .../fj-kernel/src/algorithms/sweep/vertex.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 386a98d58..903a7a76a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -140,3 +140,23 @@ impl Sweep for GlobalVertex { GlobalEdge::new(curve, [a, b]) } } + +#[cfg(test)] +mod tests { + use crate::{ + algorithms::sweep::Sweep, + objects::{GlobalCurve, GlobalEdge, GlobalVertex}, + }; + + #[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); + } +} From 7184d77a22177e06d19b6d93653ac8d153be1145 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Sep 2022 16:22:26 +0200 Subject: [PATCH 4/5] Test `Sweep` impl for `(Vertex, Surface)` --- .../fj-kernel/src/algorithms/sweep/vertex.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 903a7a76a..02ac8d051 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -145,9 +145,25 @@ impl Sweep for GlobalVertex { mod tests { use crate::{ algorithms::sweep::Sweep, - objects::{GlobalCurve, GlobalEdge, GlobalVertex}, + 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 = From c42cb8f3cf65eeef3d75f3e6bc137eb15e2f207c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 12 Sep 2022 17:31:05 +0200 Subject: [PATCH 5/5] Test `Sweep` impl of `(HalfEdge, Color)` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) 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); + } +}