Skip to content

Commit

Permalink
Merge pull request #1077 from hannobraun/sweep
Browse files Browse the repository at this point in the history
Expand sweep test suite
  • Loading branch information
hannobraun authored Sep 12, 2022
2 parents 5d556f5 + c42cb8f commit 436a0b0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 9 deletions.
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);
}
}

0 comments on commit 436a0b0

Please sign in to comment.