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

Expand sweep test suite #1077

Merged
merged 5 commits into from
Sep 12, 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
39 changes: 39 additions & 0 deletions crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
52 changes: 43 additions & 9 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
};

Expand Down Expand Up @@ -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);
}
}