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

Add new validation infrastructure #1279

Merged
merged 6 commits into from
Oct 26, 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
23 changes: 14 additions & 9 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod tests {
use super::CurveApprox;

#[test]
fn approx_line_on_flat_surface() {
fn approx_line_on_flat_surface() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects
Expand All @@ -214,16 +214,18 @@ mod tests {
let curve = Curve::partial()
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [2., 1.]])
.build(&objects);
.build(&objects)?;
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);

assert_eq!(approx, CurveApprox::empty())
assert_eq!(approx, CurveApprox::empty());
Ok(())
}

#[test]
fn approx_line_on_curved_surface_but_not_along_curve() {
fn approx_line_on_curved_surface_but_not_along_curve() -> anyhow::Result<()>
{
let objects = Objects::new();

let surface = objects.surfaces.insert(Surface::new(
Expand All @@ -233,24 +235,25 @@ mod tests {
let curve = Curve::partial()
.with_surface(Some(surface))
.as_line_from_points([[1., 1.], [1., 2.]])
.build(&objects);
.build(&objects)?;
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);

assert_eq!(approx, CurveApprox::empty());
Ok(())
}

#[test]
fn approx_line_on_curved_surface_along_curve() {
fn approx_line_on_curved_surface_along_curve() -> anyhow::Result<()> {
let objects = Objects::new();

let path = GlobalPath::circle_from_radius(1.);
let surface = objects.surfaces.insert(Surface::new(path, [0., 0., 1.]));
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_line_from_points([[0., 1.], [1., 1.]])
.build(&objects);
.build(&objects)?;

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand All @@ -269,10 +272,11 @@ mod tests {
})
.collect::<Vec<_>>();
assert_eq!(approx.points, expected_approx);
Ok(())
}

#[test]
fn approx_circle_on_flat_surface() {
fn approx_circle_on_flat_surface() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects
Expand All @@ -281,7 +285,7 @@ mod tests {
let curve = Curve::partial()
.with_surface(Some(surface))
.as_circle_from_radius(1.)
.build(&objects);
.build(&objects)?;

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand All @@ -297,5 +301,6 @@ mod tests {
})
.collect::<Vec<_>>();
assert_eq!(approx.points, expected_approx);
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/approx/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::collections::BTreeSet;
use fj_interop::mesh::Color;

use crate::{
algorithms::validate::ValidationConfig,
objects::{Face, Faces, Handedness},
validate::ValidationConfig,
};

use super::{
Expand Down
28 changes: 16 additions & 12 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ mod tests {
use super::CurveEdgeIntersection;

#[test]
fn compute_edge_in_front_of_curve_origin() {
fn compute_edge_in_front_of_curve_origin() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
.build(&objects)?;
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[1., -1.], [1., 1.]])
.build(&objects);
.build(&objects)?;

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -103,21 +103,22 @@ mod tests {
point_on_curve: Point::from([1.])
})
);
Ok(())
}

#[test]
fn compute_edge_behind_curve_origin() {
fn compute_edge_behind_curve_origin() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
.build(&objects)?;
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., -1.], [-1., 1.]])
.build(&objects);
.build(&objects)?;

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -127,40 +128,42 @@ mod tests {
point_on_curve: Point::from([-1.])
})
);
Ok(())
}

#[test]
fn compute_edge_parallel_to_curve() {
fn compute_edge_parallel_to_curve() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
.build(&objects)?;
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., -1.], [1., -1.]])
.build(&objects);
.build(&objects)?;

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

assert!(intersection.is_none());
Ok(())
}

#[test]
fn compute_edge_on_curve() {
fn compute_edge_on_curve() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();
let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_u_axis()
.build(&objects);
.build(&objects)?;
let half_edge = HalfEdge::partial()
.with_surface(Some(surface))
.as_line_segment_from_points([[-1., 0.], [1., 0.]])
.build(&objects);
.build(&objects)?;

let intersection = CurveEdgeIntersection::compute(&curve, &half_edge);

Expand All @@ -170,5 +173,6 @@ mod tests {
points_on_curve: [Point::from([-1.]), Point::from([1.]),]
})
);
Ok(())
}
}
5 changes: 3 additions & 2 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ mod tests {
use super::CurveFaceIntersection;

#[test]
fn compute() {
fn compute() -> anyhow::Result<()> {
let objects = Objects::new();

let surface = objects.surfaces.xy_plane();

let curve = Curve::partial()
.with_surface(Some(surface.clone()))
.as_line_from_points([[-3., 0.], [-2., 0.]])
.build(&objects);
.build(&objects)?;

#[rustfmt::skip]
let exterior = [
Expand All @@ -191,6 +191,7 @@ mod tests {
let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
assert_eq!(CurveFaceIntersection::compute(&curve, &face), expected);
Ok(())
}

#[test]
Expand Down
8 changes: 5 additions & 3 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl FaceFaceIntersection {

#[cfg(test)]
mod tests {
use fj_interop::ext::ArrayExt;
use pretty_assertions::assert_eq;

use crate::{
Expand Down Expand Up @@ -91,7 +92,7 @@ mod tests {
}

#[test]
fn compute_one_intersection() {
fn compute_one_intersection() -> anyhow::Result<()> {
let objects = Objects::new();

#[rustfmt::skip]
Expand All @@ -112,12 +113,12 @@ mod tests {

let intersection = FaceFaceIntersection::compute([&a, &b], &objects);

let expected_curves = surfaces.map(|surface| {
let expected_curves = surfaces.try_map_ext(|surface| {
Curve::partial()
.with_surface(Some(surface))
.as_line_from_points([[0., 0.], [1., 0.]])
.build(&objects)
});
})?;
let expected_intervals =
CurveFaceIntersection::from_intervals([[[-1.], [1.]]]);
assert_eq!(
Expand All @@ -127,5 +128,6 @@ mod tests {
intersection_intervals: expected_intervals
})
);
Ok(())
}
}
32 changes: 19 additions & 13 deletions crates/fj-kernel/src/algorithms/intersect/ray_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod tests {
};

#[test]
fn ray_misses_whole_surface() {
fn ray_misses_whole_surface() -> anyhow::Result<()> {
let objects = Objects::new();

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);
Expand All @@ -172,13 +172,14 @@ mod tests {
[-1., 1.],
])
.build()
.translate([-1., 0., 0.], &objects);
.translate([-1., 0., 0.], &objects)?;

assert_eq!((&ray, &face).intersect(), None);
Ok(())
}

#[test]
fn ray_hits_face() {
fn ray_hits_face() -> anyhow::Result<()> {
let objects = Objects::new();

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);
Expand All @@ -193,16 +194,17 @@ mod tests {
[-1., 1.],
])
.build()
.translate([1., 0., 0.], &objects);
.translate([1., 0., 0.], &objects)?;

assert_eq!(
(&ray, &face).intersect(),
Some(RayFaceIntersection::RayHitsFace)
);
Ok(())
}

#[test]
fn ray_hits_surface_but_misses_face() {
fn ray_hits_surface_but_misses_face() -> anyhow::Result<()> {
let objects = Objects::new();

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);
Expand All @@ -217,13 +219,14 @@ mod tests {
[-1., 1.],
])
.build()
.translate([0., 0., 2.], &objects);
.translate([0., 0., 2.], &objects)?;

assert_eq!((&ray, &face).intersect(), None);
Ok(())
}

#[test]
fn ray_hits_edge() {
fn ray_hits_edge() -> anyhow::Result<()> {
let objects = Objects::new();

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);
Expand All @@ -238,7 +241,7 @@ mod tests {
[-1., 1.],
])
.build()
.translate([1., 1., 0.], &objects);
.translate([1., 1., 0.], &objects)?;

let edge = face
.half_edge_iter()
Expand All @@ -252,10 +255,11 @@ mod tests {
(&ray, &face).intersect(),
Some(RayFaceIntersection::RayHitsEdge(edge.clone()))
);
Ok(())
}

#[test]
fn ray_hits_vertex() {
fn ray_hits_vertex() -> anyhow::Result<()> {
let objects = Objects::new();

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);
Expand All @@ -270,7 +274,7 @@ mod tests {
[-1., 1.],
])
.build()
.translate([1., 1., 1.], &objects);
.translate([1., 1., 1.], &objects)?;

let vertex = face
.vertex_iter()
Expand All @@ -282,6 +286,7 @@ mod tests {
(&ray, &face).intersect(),
Some(RayFaceIntersection::RayHitsVertex(vertex.clone()))
);
Ok(())
}

#[test]
Expand All @@ -308,7 +313,7 @@ mod tests {
}

#[test]
fn ray_is_parallel_to_surface_and_misses() {
fn ray_is_parallel_to_surface_and_misses() -> anyhow::Result<()> {
let objects = Objects::new();

let ray = HorizontalRayToTheRight::from([0., 0., 0.]);
Expand All @@ -323,8 +328,9 @@ mod tests {
[-1., 1.],
])
.build()
.translate([0., 0., 1.], &objects);
.translate([0., 0., 1.], &objects)?;

assert_eq!((&ray, &face).intersect(), None)
assert_eq!((&ray, &face).intersect(), None);
Ok(())
}
}
Loading