Skip to content

Commit

Permalink
Merge pull request #1404 from hannobraun/validation
Browse files Browse the repository at this point in the history
Move validation to separate service
  • Loading branch information
hannobraun authored Nov 29, 2022
2 parents 6e4a582 + 7e4c0af commit 005503c
Show file tree
Hide file tree
Showing 27 changed files with 600 additions and 735 deletions.
43 changes: 25 additions & 18 deletions crates/fj-kernel/src/algorithms/approx/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,28 @@ mod tests {
builder::{CurveBuilder, SurfaceBuilder},
geometry::path::GlobalPath,
insert::Insert,
objects::Objects,
partial::{PartialCurve, PartialSurface},
services::State,
services::Services,
};

use super::CurveApprox;

#[test]
fn approx_line_on_flat_surface() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface =
PartialSurface::from_axes(GlobalPath::x_axis(), [0., 0., 1.])
.build(&objects)
.insert(&mut objects);
.build(&services.objects)
.insert(&mut services.objects);
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_line_from_points([[1., 1.], [2., 1.]]);
let curve = curve.build(&mut objects).insert(&mut objects);
let curve = curve
.build(&mut services.objects)
.insert(&mut services.objects);
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);
Expand All @@ -233,20 +234,22 @@ mod tests {

#[test]
fn approx_line_on_curved_surface_but_not_along_curve() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface = PartialSurface::from_axes(
GlobalPath::circle_from_radius(1.),
[0., 0., 1.],
)
.build(&objects)
.insert(&mut objects);
.build(&services.objects)
.insert(&mut services.objects);
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_line_from_points([[1., 1.], [1., 2.]]);
let curve = curve.build(&mut objects).insert(&mut objects);
let curve = curve
.build(&mut services.objects)
.insert(&mut services.objects);
let range = RangeOnPath::from([[0.], [1.]]);

let approx = (&curve, range).approx(1.);
Expand All @@ -256,18 +259,20 @@ mod tests {

#[test]
fn approx_line_on_curved_surface_along_curve() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let path = GlobalPath::circle_from_radius(1.);
let surface = PartialSurface::from_axes(path, [0., 0., 1.])
.build(&objects)
.insert(&mut objects);
.build(&services.objects)
.insert(&mut services.objects);
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_line_from_points([[0., 1.], [1., 1.]]);
let curve = curve.build(&mut objects).insert(&mut objects);
let curve = curve
.build(&mut services.objects)
.insert(&mut services.objects);

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand All @@ -290,18 +295,20 @@ mod tests {

#[test]
fn approx_circle_on_flat_surface() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface =
PartialSurface::from_axes(GlobalPath::x_axis(), [0., 0., 1.])
.build(&objects)
.insert(&mut objects);
.build(&services.objects)
.insert(&mut services.objects);
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_circle_from_radius(1.);
let curve = curve.build(&mut objects).insert(&mut objects);
let curve = curve
.build(&mut services.objects)
.insert(&mut services.objects);

let range = RangeOnPath::from([[0.], [TAU]]);
let tolerance = 1.;
Expand Down
36 changes: 18 additions & 18 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ mod tests {

use crate::{
builder::{CurveBuilder, HalfEdgeBuilder},
objects::{HalfEdge, Objects},
objects::HalfEdge,
partial::{HasPartial, PartialCurve},
services::State,
services::Services,
};

use super::CurveEdgeIntersection;

#[test]
fn compute_edge_in_front_of_curve_origin() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface = objects.surfaces.xy_plane();
let surface = services.objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&mut objects);
let curve = curve.build(&mut services.objects);
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(surface, [[1., -1.], [1., 1.]])
.build(&mut objects);
.build(&mut services.objects);

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

Expand All @@ -110,21 +110,21 @@ mod tests {

#[test]
fn compute_edge_behind_curve_origin() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface = objects.surfaces.xy_plane();
let surface = services.objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&mut objects);
let curve = curve.build(&mut services.objects);
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(
surface,
[[-1., -1.], [-1., 1.]],
)
.build(&mut objects);
.build(&mut services.objects);

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

Expand All @@ -138,21 +138,21 @@ mod tests {

#[test]
fn compute_edge_parallel_to_curve() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface = objects.surfaces.xy_plane();
let surface = services.objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&mut objects);
let curve = curve.build(&mut services.objects);
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(
surface,
[[-1., -1.], [1., -1.]],
)
.build(&mut objects);
.build(&mut services.objects);

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

Expand All @@ -161,18 +161,18 @@ mod tests {

#[test]
fn compute_edge_on_curve() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface = objects.surfaces.xy_plane();
let surface = services.objects.surfaces.xy_plane();
let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_u_axis();
let curve = curve.build(&mut objects);
let curve = curve.build(&mut services.objects);
let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(surface, [[-1., 0.], [1., 0.]])
.build(&mut objects);
.build(&mut services.objects);

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

Expand Down
12 changes: 6 additions & 6 deletions crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,25 @@ where
mod tests {
use crate::{
builder::{CurveBuilder, FaceBuilder},
objects::{Face, Objects},
objects::Face,
partial::{HasPartial, PartialCurve},
services::State,
services::Services,
};

use super::CurveFaceIntersection;

#[test]
fn compute() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

let surface = objects.surfaces.xy_plane();
let surface = services.objects.surfaces.xy_plane();

let mut curve = PartialCurve {
surface: Some(surface.clone()),
..Default::default()
};
curve.update_as_line_from_points([[-3., 0.], [-2., 0.]]);
let curve = curve.build(&mut objects);
let curve = curve.build(&mut services.objects);

#[rustfmt::skip]
let exterior = [
Expand All @@ -190,7 +190,7 @@ mod tests {
.with_surface(surface)
.with_exterior_polygon_from_points(exterior)
.with_interior_polygon_from_points(interior)
.build(&mut objects);
.build(&mut services.objects);

let expected =
CurveFaceIntersection::from_intervals([[[1.], [2.]], [[4.], [5.]]]);
Expand Down
41 changes: 24 additions & 17 deletions crates/fj-kernel/src/algorithms/intersect/face_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ mod tests {
algorithms::intersect::CurveFaceIntersection,
builder::{CurveBuilder, FaceBuilder},
insert::Insert,
objects::{Face, Objects},
objects::Face,
partial::{HasPartial, PartialCurve},
services::State,
services::Services,
};

use super::FaceFaceIntersection;

#[test]
fn compute_no_intersection() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

#[rustfmt::skip]
let points = [
Expand All @@ -89,23 +89,26 @@ mod tests {
[2., 2.],
[1., 2.],
];
let [a, b] = [objects.surfaces.xy_plane(), objects.surfaces.xz_plane()]
.map(|surface| {
Face::partial()
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build(&mut objects)
});
let [a, b] = [
services.objects.surfaces.xy_plane(),
services.objects.surfaces.xz_plane(),
]
.map(|surface| {
Face::partial()
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build(&mut services.objects)
});

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

assert!(intersection.is_none());
}

#[test]
fn compute_one_intersection() {
let mut objects = Objects::new().into_service();
let mut services = Services::new();

#[rustfmt::skip]
let points = [
Expand All @@ -114,25 +117,29 @@ mod tests {
[ 1., 1.],
[-1., 1.],
];
let surfaces =
[objects.surfaces.xy_plane(), objects.surfaces.xz_plane()];
let surfaces = [
services.objects.surfaces.xy_plane(),
services.objects.surfaces.xz_plane(),
];
let [a, b] = surfaces.clone().map(|surface| {
Face::partial()
.with_surface(surface)
.with_exterior_polygon_from_points(points)
.build(&mut objects)
.build(&mut services.objects)
});

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

let expected_curves = surfaces.map(|surface| {
let mut curve = PartialCurve {
surface: Some(surface),
..Default::default()
};
curve.update_as_line_from_points([[0., 0.], [1., 0.]]);
curve.build(&mut objects).insert(&mut objects)
curve
.build(&mut services.objects)
.insert(&mut services.objects)
});
let expected_intervals =
CurveFaceIntersection::from_intervals([[[-1.], [1.]]]);
Expand Down
Loading

0 comments on commit 005503c

Please sign in to comment.